Last active
March 12, 2018 04:18
-
-
Save rclark/5952912 to your computer and use it in GitHub Desktop.
Access dynamic ESRI service layers via "export"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* When creating a layer pass the ESRI Service's Export URL. e.g.: | |
* https://eia-ms.esri.com/arcgis/rest/services/20130301StateEnergyProfilesMap/MapServer/export | |
*/ | |
L.TileLayer.EsriImageExports = L.TileLayer.WMS.extend({ | |
getTileUrl: function (tilePoint) { | |
// Get the URL if this was just a WMS | |
var wmsUrl = L.TileLayer.WMS.prototype.call(this, tilePoint), | |
base = wmsUrl.split("?")[0], | |
params = wmsUrl.split("?")[1].split("&"); | |
// Look through the params and pick on the ones we need | |
var bbox = "", height = 0, width = 0; | |
for (var i = 0; i < params.length; i++) { | |
var param = params[i], | |
key = param.split("=")[0], | |
val = param.split("=")[1]; | |
switch (key.toLowerCase()) { | |
case "bbox": | |
bbox = val; | |
break; | |
case "height": | |
height = val; | |
break; | |
case "width": | |
width = val; | |
break; | |
} | |
} | |
// Rebuild the ESRI export URL | |
var esriUrl = base + "?" + "f=image&format=png32&transparent=true&bboxSR=3857&bbox=" + bbox + "&size=" + width + "," + height; | |
return esriUrl; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment