Add a WMS layer to GeoJSON.io
Note: This is a pretty roundabout way to do this. After some discussion on Twitter, it seems you can just add these sorts of layers directly in GeoJSON.io
httP://.../MapServer/tile/{z}/{y}/{x} (Add the bold part to the service URI
GeoJSON.io allows you to use its console API to access Leaflet/Mapbox.js methods. This means you can add layers from external sources. This works great with your tile map service from the likes of Stamen, CartoDB, or Mapbox, but adding layers from a WMS is a little different. Apparently you can work with WMS layers using Leaflet with L.tileLayer.wms()
, but I've not ever successfully done this with straigh-up Leaflet. I have been able to access WMS layers using esri-leaflet. In this little note, I want to address two things:
GeoJSON.io loads natively with access to mapbox.js and, as a result, Leaflet. We need to be add esri-leaflet so it is also available for us to use.
F12
F12
Enter
to run them<script>
tag to the <head>
of our open GeoJSON.io page (Source). In the console create a variable to create and hold our new <script>
tag:var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://cdn.jsdelivr.net/leaflet.esri/1.0.0/esri-leaflet.js';
<script>
tag that can give us access to esri-leaflet (You can check out what the final tag looks like by running console.log(script)
). Now we need to add or append the contents of our script
variable to the <head>
of GeoJSON.io:document.head.appendChild(script)
Hooray! Hopefully this all worked and you've added esri-leaflet to GeoJSON.io. Now we'll moving on to accessing esri-leaflet through GeoJSON.io's console API so we can add a WMS from and ArcGIS REST Service.
For this example, we're going to be adding a WMS of the Veteran's Wildlife Management Area north of Georgetown, KY that is accessed from the Georgetown-Scott County Planning Commission's ArcGIS REST Service: http://gis.gscplanning.com/arcgis/rest/services/wma_aerial2012_hs/MapServer
L.esri.tiledMapLayer()
to access that WMS:var aerial = L.esri.tiledMapLayer({url:'http://gis.gscplanning.com/arcgis/rest/services/wma_aerial2012_hs/MapServer'});
window.api.map.addLayer(aerial);
window.api.map.setView([38.328393, -84.544945], 14)
Well...hopefully it all worked! If it did, you can now use the WMS layer to help with whatever feature creation you want to do in GeoJSON.io. These are truly amazing times!