Layer refactoring

A work in progress. This PR contains major refactoring of Leaflet layers architecture, creating a base Layer class for all layers to inherit from, and putting all shared layers logic there (as well as layers-related logic in `Map.js`), DRYing up and simplifying the code significantly, removing ugly hacks, as well as addressing #496 #1249 #1742 and other issues. A part of the major refactoring for Leaflet 1.0 #2210.