Exploring Leaflet Geographic Classes

leaflet

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.

Leaflet Geographic Classes

Leaflet Geographic Classes

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.

leaflet_crs_classes

Leaflet CRS Classes

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.

Advertisements

2 thoughts on “Exploring Leaflet Geographic Classes

  1. Pingback: Exploring Leaflet Vector Classes | Exploring Spatial

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s