In my previous post, Exploring Leaflet Base Classes, I covered the core classes upon which the Leaflet API is built. In this post, I cover the geographic classes.
If you have ever used the APIs for Google, Bing, OSM, or Open Layers then you are already familiar with the model objects for the spherical reference system: latitude and longitude, as well as for the 2-D projection, point, expressed as x/y coordinates. The corresponding classes for Google are LatLng, LatLngBounds, and Point. For Bing Maps the classes are Location, LocationRect, and Point. OSM uses LatLng, RectLL, and Point. Leaflet has LatLng, LatLngBounds, Point, and Bounds, as illustrated below.
The diagram above also includes the L.Map class showing its functions that either accepts or return the other classes shown on the diagram. You’ll note that many map features, such as responding to events, are available in both Lat/Lon or x/y point versions. Also, note the many projection functions on L.Map that depend on the projection system specified for a given map instance.
Every web mapping API must project coordinates from a spherical reference system, latitude, and longitude, to the 2-D, x/y pixel coordinates on your computer monitor. In most online maps, like Google Maps, the projection system is fixed because the vendor controls both the base map and vector layer. Leaflet and OpenLayers, on the other hand, are open, so the user is free to pick base maps generated with a different coordinate reference system. Matching the projection system ensures that features on the vector layer align with the base map tiles. The Leaflet CRS classes are shown below.
I found a good post about spherical Mercator projections on the Open Layers web site. Lucky for me, at Garmin Connect all of our base maps, Google, Bing, and OSM, use Spherical Mercator so I won’t have to mess with the projection system.
In my next post, I’ll delve into vector layer classes.