1.1.0 • Published 7 years ago
prebaked-geojson-map v1.1.0
prebaked-geojson-map
This package makes it very easy to add GeoJSON data to a to a preconfigured Leaflet map.
Installation
npm install --save-dev prebaked-geojson-map
Usage
This module exports a UMD object named PrebakedGeoJSONMap; you can see the
exported members in src/index.ts.
Here are the basic steps to use this module in a webpage:
- Load this module's
index.cssandindex.jsinto your page. var map = window.PrebakedGeoJSONMap.add();..addtakes the same options as Leaflet'sL.map. It includes some default options (seesrc/map.ts) and automatically adds some base layers (seesrc/layers.ts).- Add data to the map with
window.PrebakedGeoJSONMap.renderPaths(data, map);andwindow.PrebakedGeoJSONMap.renderPoints(data, map);.datamust be valid GeoJSON data, either as a JavaScript object literal or viaJSON.parse.
You can see these steps demonstrated by example/index.html. The
instant-map project is slightly more complex; the user drags a
GeoJSON file into the browser window and the GeoJSON data is projected on the
map.
The Map instance returned by .add has some custom event listeners that
work around limitations in Leaflet’s API:
"addBaseLayer"allows you to add a new baseLayerto the existing layers control. Leaflet’s API only allows you to add new layers by callingL.control.layers, which will always add a new control. Use it likemap.fire("addBaseLayer", { baseLayer: layer, key: 'foo' });."addOverlayLayer"allows you to add a newLayerorLayerGroupoverlay to the existing layers control. Use it likemap.fire("addOverlayLayer", { overlayLayer: layer, key: 'foo' });."resetOverlayLayers"allows you to remove all the overlay layers from the layers control. Use it likemap.fire("resetOverlayLayers"). Note that this will not removeMarkers added by.renderPoints: to remove those, runmap.eachLayer(layer => { if (!layer._url) map.removeLayer(layer) });.