A dynamic leaflet layers control that pulls from multiple mapservers and manages basemaps and overlays plus order
A dynamic leaflet layers control that pulls from multiple mapservers and manages basemaps and overlays plus their order.
See this demo page for a full example or this barebones demonstration of the simpliest way to configure the plugin.
New! WMS support! Huzzah! Splits the WMS layers up for you so that you can turn them off/on and declare basemaps, automatically pulls layers. See this demo for an example.
The configuration is an object that is passed in as the first signature on the method call (L.control.autolayers()). The second is the standard Layers options object which is optional.
List of possible configuration keys:
That's it! It has its own built in ajax and comes bundled with x2js, you can drop both of these for your own with some slight modifications.
Sample Configuration that pulls from the public ArcGIS and Navy Research Labs tileservers:
var config = {
overlays: overlays, //custom overlays group that are static
baseLayers: baseLayers, //custom baselayers group that are static
selectedBasemap: 'Streets', //selected basemap when it loads
selectedOverlays: ["ASTER Digital Elevation Model 30M", "ASTER Digital Elevation Model Color 30M", "Cities"], //which overlays should be on by default
mapServers: [{
"url": "http://services.arcgisonline.com/arcgis/rest/services",
"dictionary": "http://services.arcgisonline.com/arcgis/rest/services?f=pjson",
"tileUrl": "/MapServer/tile/{z}/{y}/{x}",
"name": "ArcGIS Online",
"type": "esri",
"baseLayers": ["ESRI_Imagery_World_2D", "ESRI_StreetMap_World_2D", "NGS_Topo_US_2D"],
"whitelist": ["ESRI_Imagery_World_2D", "ESRI_StreetMap_World_2D", "NGS_Topo_US_2D"]
}, {
"url": "http://geoint.nrlssc.navy.mil/nrltileserver",
"dictionary": "http://geoint.nrlssc.navy.mil/nrltileserver/wms?REQUEST=GetCapabilities&VERSION=1.1.1&SERVICE=WMS",
"tileUrl": "/{z}/{x}/{y}.png",
"name": "Navy NRL",
"type": "nrltileserver",
"baseLayers": ["bluemarble", "Landsat7", "DTED0_GRID_COLOR1", "ETOPO1_COLOR1", "NAIP", "DRG_AUTO"],
"blacklist": ["BlackMarble"]
}]
};
Make sure all your layers you include are of the same projection. Currently map projection redrawing based on baselayer is not implemented, so if you don't have matching layer projections, things will not line up properly.
Contributions, especially for other map servers or enhancements welcome.
For now it's going to remain in beta until the Leaflet 1.0.0 release. After that time a standard version 1.x will begin.
This project is licensed under the MIT License - see the LICENSE.md file for details