{"version":3,"file":"esri-leaflet.js","sources":["../src/EsriLeaflet.js","../src/Util.js","../src/Request.js","../src/Services/Service.js","../src/Services/FeatureLayer.js","../src/Services/MapService.js","../src/Services/ImageService.js","../src/Tasks/Task.js","../src/Tasks/Query.js","../src/Tasks/Find.js","../src/Tasks/Identify.js","../src/Tasks/IdentifyImage.js","../src/Tasks/IdentifyFeatures.js","../src/Layers/BasemapLayer.js","../src/Layers/RasterLayer.js","../src/Layers/DynamicMapLayer.js","../src/Layers/ImageMapLayer.js","../src/Layers/TiledMapLayer.js","../src/Layers/FeatureLayer/FeatureGrid.js","../src/Layers/FeatureLayer/FeatureManager.js","../src/Layers/FeatureLayer/FeatureLayer.js","../src/Controls/Logo.js"],"names":["EsriLeaflet","VERSION","Layers","Services","Controls","Tasks","Util","Support","CORS","window","XMLHttpRequest","pointerEvents","document","documentElement","style","L","esri","clone","obj","target","i","hasOwnProperty","pointsEqual","a","b","length","closeRing","coordinates","push","ringIsClockwise","ringToTest","pt2","total","rLength","pt1","vertexIntersectsVertex","a1","a2","b1","b2","uaT","ubT","uB","ua","ub","arrayIntersectsArray","j","coordinatesContainPoint","point","contains","l","coordinatesContainCoordinates","outer","inner","intersects","convertRingsToGeoJSON","rings","x","outerRing","hole","outerRings","holes","r","ring","slice","polygon","uncontainedHoles","pop","contained","reverse","type","orientRings","poly","output","shift","flattenMultiPolygonRings","raf","requestAnimationFrame","webkitRequestAnimationFrame","mozRequestAnimationFrame","msRequestAnimationFrame","cb","setTimeout","extentToBounds","extent","sw","LatLng","ymin","xmin","ne","ymax","xmax","LatLngBounds","boundsToExtent","bounds","latLngBounds","getSouthWest","lng","lat","getNorthEast","spatialReference","wkid","arcgisToGeojson","arcgis","idAttribute","geojson","y","points","paths","geometry","attributes","properties","id","OBJECTID","FID","geojsonToArcGIS","result","features","geometries","responseToFeatureCollection","response","objectIdField","objectIdFieldName","fields","name","featureCollection","results","cleanUrl","url","replace","isArcgisOnline","test","geojsonTypeToArcGIS","geoJsonType","arcgisGeometryType","bind","serialize","params","data","f","key","value","param","Object","prototype","toString","call","JSON","stringify","join","valueOf","encodeURIComponent","createRequest","callback","context","httpRequest","onerror","onreadystatechange","falseFn","error","code","message","readyState","parse","responseText","e","callbacks","_EsriLeafletCallbacks","Request","request","paramString","requestLength","open","send","setRequestHeader","get","JSONP","console","warn","post","XMLHTTP","callbackId","script","DomUtil","create","body","src","responseType","abort","_callback","Service","Class","extend","includes","Mixin","Events","options","proxy","useCors","initialize","this","_requestQueue","_authenticating","setOptions","path","_request","metadata","authenticate","token","_runQueue","method","fire","wrappedCallback","_createServiceCallback","apply","service","FeatureLayer","query","Query","addFeature","feature","addResults","undefined","updateFeature","updateResults","deleteFeature","objectIds","deleteResults","deleteFeatures","ids","featureLayer","MapService","identify","identifyFeatures","find","Find","mapService","ImageService","IdentifyImage","imageService","Task","generateSetter","endpoint","_service","setters","setter","offset","limit","precision","featureIds","returnGeometry","where","outSr","outFields","within","_setGeometry","spatialRel","overlaps","nearby","latlng","radius","latLng","geometryType","units","distance","inSr","string","between","start","end","time","simplify","map","factor","mapWidth","Math","abs","getBounds","getWest","getEast","maxAllowableOffset","getSize","orderBy","fieldName","order","orderByFields","run","_cleanParams","count","returnCountOnly","returnIdsOnly","returnExtentOnly","pixelSize","layer","getLatLng","GeoJSON","getLayers","toGeoJSON","text","sr","layers","dynamicLayers","returnZ","returnM","gdbVersion","layerDefs","Identify","setMosaicRule","setRenderingRule","setPixelSize","returnCatalogItems","at","getMosaicRule","mosaicRule","getRenderingRule","renderingRule","getPixelSize","_responseToGeoJSON","location","catalogItems","catalogItemVisibilities","geoJSON","pixel","crs","objectId","Values","values","catalogItemVisibility","identifyImage","IdentifyFeatures","tolerance","on","size","imageDisplay","mapExtent","layerDef","layerId","tileProtocol","protocol","BasemapLayer","TileLayer","statics","TILES","Streets","urlTemplate","attributionUrl","hideLogo","logoPosition","minZoom","maxZoom","subdomains","attribution","Topographic","Oceans","OceansLabels","NationalGeographic","DarkGray","DarkGrayLabels","Gray","GrayLabels","Imagery","ImageryLabels","ImageryTransportation","ShadedRelief","ShadedReliefLabels","Terrain","TerrainLabels","config","Error","tileOptions","_getAttributionData","_logo","Logo","position","onAdd","_hasEsriLogo","addTo","_updateMapAttribution","onRemove","_container","removeControl","off","getAttribution","attributions","_attributions","c","contributors","contributor","coverageAreas","coverageArea","southWest","bbox","northEast","score","zoomMin","zoomMax","sort","_map","attributionControl","newAttributions","zoom","getZoom","match","substr","attributionElement","querySelector","innerHTML","maxWidth","basemapLayer","RasterLayer","opacity","_update","limitExecByInterval","updateInterval","split","bboxSR","imageSR","_currentImage","_bounds","equals","addLayer","removeLayer","_popup","_getPopupData","_resetPopupState","bindPopup","fn","popupOptions","_shouldRenderPopup","_lastClick","popup","_popupFunction","unbindPopup","closePopup","removeFrom","bringToFront","bringToBack","getOpacity","setOpacity","getTimeRange","from","to","setTimeRange","_renderImage","image","ImageOverlay","once","newImage","oldImage","_animatingZoom","_panTransition","_inProgress","_buildExportParams","_requestExport","_renderPopup","content","setLatLng","setContent","openOn","_propagateEvent","DynamicMapLayer","timeOptions","format","transparent","setLayers","getLayerDefs","setLayerDefs","getTimeOptions","setTimeOptions","identifyRequest","project","_northEast","_southWest","top","latLngToLayerPoint","bottom","dpi","href","getParamString","dynamicMapLayer","ImageMapLayer","setPixelType","pixelType","getPixelType","setBandIds","bandIds","isArray","getBandIds","setNoData","noData","noDataInterpretation","getNoData","getNoDataInterpretation","interpolation","compressionQuality","imageMapLayer","TiledMapLayer","tileUrl","tokenQs","tiledMapLayer","FeatureGrid","cellSize","addEventListener","getEvents","_reset","removeEventListener","_removeCells","events","viewreset","moveend","zoomend","_onZoom","hasLayer","_cells","_activeCells","_cellsToLoad","_cellsTotal","_resetWrap","infinite","_getCellSize","wrapLng","_wrapLng","floor","ceil","wrapLat","_wrapLat","getPixelBounds","cellPadding","topLeft","min","subtract","divideBy","max","cellBounds","add","_removeOtherCells","_addCells","coords","queue","center","getCenter","Point","z","cellsToLoad","distanceTo","_addCell","_cellCoordsToBounds","nwPoint","multiplyBy","sePoint","nw","unproject","wrap","se","_cellCoordsToKey","_keyToCellCoords","kArr","parseInt","_removeCell","cell","cellLeave","_wrapCoords","cellEnter","createCell","wrapNum","BinarySearchIndex","FeatureManager","timeField","timeFilterMode","simplifyFactor","oidCheck","_startTimeIndex","_endTimeIndex","_timeIndex","_cache","_currentSnapshot","_activeRequests","_pendingRequests","_requestFeatures","_buildQuery","exceededTransferLimit","_addFeatures","_cacheKey","_buildTimeIndexes","createLayers","setWhere","oldSnapshot","newShapshot","pendingRequests","requestError","requestCallback","removeLayers","addLayers","getWhere","oldFrom","oldTo","_filterExistingFeatures","refresh","newFrom","newTo","layersToRemove","_getFeaturesInTimeRange","layersToAdd","indexOf","shouldRemoveLayer","splice","search","startTimes","endTimes","concat","startTimeEntries","endTimeEntries","Date","bulkAdd","timeEntries","_featureWithinTimeRange","date","startDate","endDate","_getMetadata","_metadata","_query","currentIndex","currentElement","resultIndex","minIndex","maxIndex","round","dirty","startIndex","endIndex","items","EVENTS","cacheLayers","_layers","_leafletIds","_key","random","_zooming","createNewLayer","geometryToLayer","pointToLayer","coordsToLatLng","_updateLayerGeometry","latlngs","coordsToLatLngs","setLatLngs","newLayer","_originalStyle","_leaflet_id","_popupOptions","onEachFeature","resetStyle","permanent","cacheKey","cellKey","mapBounds","removable","setFeatureStyle","setStyle","eachFeature","defaultOptions","Path","fill","popupContent","groupLayers","gLayer","getFeature","Control","marginTop","marginLeft","marginBottom","marginRight","div","_adjustLogo","_size","newSize","mapSize","logo"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,GAAIA,cACFC,QAAS,aACTC,UACAC,YACAC,YACAC,SACAC,QACAC,SACEC,QAASC,OAAOC,gBAAkB,mBAAqB,IAAIA,iBAC3DC,cAAgE,KAAjDC,SAASC,gBAAgBC,MAAMH,eAI7B,oBAAXF,SAA0BA,OAAOM,IACzCN,OAAOM,EAAEC,KAAOhB,aCdlB,SAAUA,GAWR,QA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YE,OAAOoO,aAAe,SAAStG,EAAKoE,GAC9C,MAAO,IAAIpM,aAAYE,OAAOsN,aAAaxF,EAAKoE,IAGlDpM,YAAYsO,aAAe,SAAStG,EAAKoE,GACvC,MAAO,IAAIpM,aAAYE,OAAOsN,aAAaxF,EAAKoE,IC3TlDpM,YAAYI,SAASgX,KAAOrW,EAAE6oB,QAAQ5d,QACpCI,SACEiL,SAAU,cACVwS,UAAW,EACXC,WAAY,EACZC,aAAc,EACdC,YAAa,GAGf1S,MAAO,WACL,GAAI2S,GAAMlpB,EAAEwK,QAAQC,OAAO,MAAO,oBAWlC,OAVAye,GAAInpB,MAAM+oB,UAAYrd,KAAKJ,QAAQyd,UACnCI,EAAInpB,MAAMgpB,WAAatd,KAAKJ,QAAQ0d,WACpCG,EAAInpB,MAAMipB,aAAevd,KAAKJ,QAAQ2d,aACtCE,EAAInpB,MAAMkpB,YAAcxd,KAAKJ,QAAQ4d,YACrCC,EAAI3Q,UAAY9M,KAAK0d,YAAY1d,KAAKqM,KAAKsR,OAE3C3d,KAAKqM,KAAKlE,GAAG,SAAU,SAAStK,GAC9B4f,EAAI3Q,UAAY9M,KAAK0d,YAAY7f,EAAE+f,UAClC5d,MAEIyd,GAGTC,YAAa,SAAUG,GACrB,MAAIA,GAAQ5mB,GAAK,KAAO4mB,EAAQ3jB,GAAK,IAC5B,mLAGA,uLAMb1G,YAAYI,SAASkqB,KAAO,SAASle,GACnC,MAAO,IAAIrL,GAAEC,KAAKZ,SAASgX,KAAKhL","sourcesContent":["var EsriLeaflet = { //jshint ignore:line\n VERSION: '1.0.0-rc.7',\n Layers: {},\n Services: {},\n Controls: {},\n Tasks: {},\n Util: {},\n Support: {\n CORS: !!(window.XMLHttpRequest && 'withCredentials' in new XMLHttpRequest()),\n pointerEvents: document.documentElement.style.pointerEvents === ''\n }\n};\n\nif(typeof window !== 'undefined' && window.L){\n window.L.esri = EsriLeaflet;\n}\n","(function(EsriLeaflet){\n\n // normalize request animation frame\n var raf = window.requestAnimationFrame ||\n window.webkitRequestAnimationFrame ||\n window.mozRequestAnimationFrame ||\n window.msRequestAnimationFrame ||\n function(cb) { return window.setTimeout(cb, 1000 / 60); };\n\n // shallow object clone for feature properties and attributes\n // from http://jsperf.com/cloning-an-object/2\n function clone(obj) {\n var target = {};\n for (var i in obj) {\n if (obj.hasOwnProperty(i)) {\n target[i] = obj[i];\n }\n }\n return target;\n }\n\n // checks if 2 x,y points are equal\n function pointsEqual(a, b) {\n for (var i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) {\n return false;\n }\n }\n return true;\n }\n\n // checks if the first and last points of a ring are equal and closes the ring\n function closeRing(coordinates) {\n if (!pointsEqual(coordinates[0], coordinates[coordinates.length - 1])) {\n coordinates.push(coordinates[0]);\n }\n return coordinates;\n }\n\n // determine if polygon ring coordinates are clockwise. clockwise signifies outer ring, counter-clockwise an inner ring\n // or hole. this logic was found at http://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-\n // points-are-in-clockwise-order\n function ringIsClockwise(ringToTest) {\n var total = 0,i = 0;\n var rLength = ringToTest.length;\n var pt1 = ringToTest[i];\n var pt2;\n for (i; i < rLength - 1; i++) {\n pt2 = ringToTest[i + 1];\n total += (pt2[0] - pt1[0]) * (pt2[1] + pt1[1]);\n pt1 = pt2;\n }\n return (total >= 0);\n }\n\n // ported from terraformer.js https://github.com/Esri/Terraformer/blob/master/terraformer.js#L504-L519\n function vertexIntersectsVertex(a1, a2, b1, b2) {\n var uaT = (b2[0] - b1[0]) * (a1[1] - b1[1]) - (b2[1] - b1[1]) * (a1[0] - b1[0]);\n var ubT = (a2[0] - a1[0]) * (a1[1] - b1[1]) - (a2[1] - a1[1]) * (a1[0] - b1[0]);\n var uB = (b2[1] - b1[1]) * (a2[0] - a1[0]) - (b2[0] - b1[0]) * (a2[1] - a1[1]);\n\n if ( uB !== 0 ) {\n var ua = uaT / uB;\n var ub = ubT / uB;\n\n if ( 0 <= ua && ua <= 1 && 0 <= ub && ub <= 1 ) {\n return true;\n }\n }\n\n return false;\n }\n\n // ported from terraformer.js https://github.com/Esri/Terraformer/blob/master/terraformer.js#L521-L531\n function arrayIntersectsArray(a, b) {\n for (var i = 0; i < a.length - 1; i++) {\n for (var j = 0; j < b.length - 1; j++) {\n if (vertexIntersectsVertex(a[i], a[i + 1], b[j], b[j + 1])) {\n return true;\n }\n }\n }\n\n return false;\n }\n\n // ported from terraformer.js https://github.com/Esri/Terraformer/blob/master/terraformer.js#L470-L480\n function coordinatesContainPoint(coordinates, point) {\n var contains = false;\n for(var i = -1, l = coordinates.length, j = l - 1; ++i < l; j = i) {\n if (((coordinates[i][1] <= point[1] && point[1] < coordinates[j][1]) ||\n (coordinates[j][1] <= point[1] && point[1] < coordinates[i][1])) &&\n (point[0] < (coordinates[j][0] - coordinates[i][0]) * (point[1] - coordinates[i][1]) / (coordinates[j][1] - coordinates[i][1]) + coordinates[i][0])) {\n contains = !contains;\n }\n }\n return contains;\n }\n\n // ported from terraformer-arcgis-parser.js https://github.com/Esri/terraformer-arcgis-parser/blob/master/terraformer-arcgis-parser.js#L106-L113\n function coordinatesContainCoordinates(outer, inner){\n var intersects = arrayIntersectsArray(outer, inner);\n var contains = coordinatesContainPoint(outer, inner[0]);\n if(!intersects && contains){\n return true;\n }\n return false;\n }\n\n // do any polygons in this array contain any other polygons in this array?\n // used for checking for holes in arcgis rings\n // ported from terraformer-arcgis-parser.js https://github.com/Esri/terraformer-arcgis-parser/blob/master/terraformer-arcgis-parser.js#L117-L172\n function convertRingsToGeoJSON(rings){\n var outerRings = [];\n var holes = [];\n var x; // iterator\n var outerRing; // current outer ring being evaluated\n var hole; // current hole being evaluated\n\n // for each ring\n for (var r = 0; r < rings.length; r++) {\n var ring = closeRing(rings[r].slice(0));\n if(ring.length < 4){\n continue;\n }\n // is this ring an outer ring? is it clockwise?\n if(ringIsClockwise(ring)){\n var polygon = [ ring ];\n outerRings.push(polygon); // push to outer rings\n } else {\n holes.push(ring); // counterclockwise push to holes\n }\n }\n\n var uncontainedHoles = [];\n\n // while there are holes left...\n while(holes.length){\n // pop a hole off out stack\n hole = holes.pop();\n\n // loop over all outer rings and see if they contain our hole.\n var contained = false;\n for (x = outerRings.length - 1; x >= 0; x--) {\n outerRing = outerRings[x][0];\n if(coordinatesContainCoordinates(outerRing, hole)){\n // the hole is contained push it into our polygon\n outerRings[x].push(hole);\n contained = true;\n break;\n }\n }\n\n // ring is not contained in any outer ring\n // sometimes this happens https://github.com/Esri/esri-leaflet/issues/320\n if(!contained){\n uncontainedHoles.push(hole);\n }\n }\n\n // if we couldn't match any holes using contains we can try intersects...\n while(uncontainedHoles.length){\n // pop a hole off out stack\n hole = uncontainedHoles.pop();\n\n // loop over all outer rings and see if any intersect our hole.\n var intersects = false;\n for (x = outerRings.length - 1; x >= 0; x--) {\n outerRing = outerRings[x][0];\n if(arrayIntersectsArray(outerRing, hole)){\n // the hole is contained push it into our polygon\n outerRings[x].push(hole);\n intersects = true;\n break;\n }\n }\n\n if(!intersects) {\n outerRings.push([hole.reverse()]);\n }\n }\n\n if(outerRings.length === 1){\n return {\n type: 'Polygon',\n coordinates: outerRings[0]\n };\n } else {\n return {\n type: 'MultiPolygon',\n coordinates: outerRings\n };\n }\n }\n\n // This function ensures that rings are oriented in the right directions\n // outer rings are clockwise, holes are counterclockwise\n // used for converting GeoJSON Polygons to ArcGIS Polygons\n function orientRings(poly){\n var output = [];\n var polygon = poly.slice(0);\n var outerRing = closeRing(polygon.shift().slice(0));\n if(outerRing.length >= 4){\n if(!ringIsClockwise(outerRing)){\n outerRing.reverse();\n }\n\n output.push(outerRing);\n\n for (var i = 0; i < polygon.length; i++) {\n var hole = closeRing(polygon[i].slice(0));\n if(hole.length >= 4){\n if(ringIsClockwise(hole)){\n hole.reverse();\n }\n output.push(hole);\n }\n }\n }\n\n return output;\n }\n\n // This function flattens holes in multipolygons to one array of polygons\n // used for converting GeoJSON Polygons to ArcGIS Polygons\n function flattenMultiPolygonRings(rings){\n var output = [];\n for (var i = 0; i < rings.length; i++) {\n var polygon = orientRings(rings[i]);\n for (var x = polygon.length - 1; x >= 0; x--) {\n var ring = polygon[x].slice(0);\n output.push(ring);\n }\n }\n return output;\n }\n\n // convert an extent (ArcGIS) to LatLngBounds (Leaflet)\n EsriLeaflet.Util.extentToBounds = function(extent){\n var sw = new L.LatLng(extent.ymin, extent.xmin);\n var ne = new L.LatLng(extent.ymax, extent.xmax);\n return new L.LatLngBounds(sw, ne);\n };\n\n // convert an LatLngBounds (Leaflet) to extent (ArcGIS)\n EsriLeaflet.Util.boundsToExtent = function(bounds) {\n bounds = L.latLngBounds(bounds);\n return {\n 'xmin': bounds.getSouthWest().lng,\n 'ymin': bounds.getSouthWest().lat,\n 'xmax': bounds.getNorthEast().lng,\n 'ymax': bounds.getNorthEast().lat,\n 'spatialReference': {\n 'wkid' : 4326\n }\n };\n };\n\n EsriLeaflet.Util.arcgisToGeojson = function (arcgis, idAttribute){\n var geojson = {};\n\n if(typeof arcgis.x === 'number' && typeof arcgis.y === 'number'){\n geojson.type = 'Point';\n geojson.coordinates = [arcgis.x, arcgis.y];\n }\n\n if(arcgis.points){\n geojson.type = 'MultiPoint';\n geojson.coordinates = arcgis.points.slice(0);\n }\n\n if(arcgis.paths) {\n if(arcgis.paths.length === 1){\n geojson.type = 'LineString';\n geojson.coordinates = arcgis.paths[0].slice(0);\n } else {\n geojson.type = 'MultiLineString';\n geojson.coordinates = arcgis.paths.slice(0);\n }\n }\n\n if(arcgis.rings) {\n geojson = convertRingsToGeoJSON(arcgis.rings.slice(0));\n }\n\n if(arcgis.geometry || arcgis.attributes) {\n geojson.type = 'Feature';\n geojson.geometry = (arcgis.geometry) ? EsriLeaflet.Util.arcgisToGeojson(arcgis.geometry) : null;\n geojson.properties = (arcgis.attributes) ? clone(arcgis.attributes) : null;\n if(arcgis.attributes) {\n geojson.id = arcgis.attributes[idAttribute] || arcgis.attributes.OBJECTID || arcgis.attributes.FID;\n }\n }\n\n return geojson;\n };\n\n // GeoJSON -> ArcGIS\n EsriLeaflet.Util.geojsonToArcGIS = function(geojson, idAttribute){\n idAttribute = idAttribute || 'OBJECTID';\n var spatialReference = { wkid: 4326 };\n var result = {};\n var i;\n\n switch(geojson.type){\n case 'Point':\n result.x = geojson.coordinates[0];\n result.y = geojson.coordinates[1];\n result.spatialReference = spatialReference;\n break;\n case 'MultiPoint':\n result.points = geojson.coordinates.slice(0);\n result.spatialReference = spatialReference;\n break;\n case 'LineString':\n result.paths = [geojson.coordinates.slice(0)];\n result.spatialReference = spatialReference;\n break;\n case 'MultiLineString':\n result.paths = geojson.coordinates.slice(0);\n result.spatialReference = spatialReference;\n break;\n case 'Polygon':\n result.rings = orientRings(geojson.coordinates.slice(0));\n result.spatialReference = spatialReference;\n break;\n case 'MultiPolygon':\n result.rings = flattenMultiPolygonRings(geojson.coordinates.slice(0));\n result.spatialReference = spatialReference;\n break;\n case 'Feature':\n if(geojson.geometry) {\n result.geometry = EsriLeaflet.Util.geojsonToArcGIS(geojson.geometry, idAttribute);\n }\n result.attributes = (geojson.properties) ? clone(geojson.properties) : {};\n if(geojson.id){\n result.attributes[idAttribute] = geojson.id;\n }\n break;\n case 'FeatureCollection':\n result = [];\n for (i = 0; i < geojson.features.length; i++){\n result.push(EsriLeaflet.Util.geojsonToArcGIS(geojson.features[i], idAttribute));\n }\n break;\n case 'GeometryCollection':\n result = [];\n for (i = 0; i < geojson.geometries.length; i++){\n result.push(EsriLeaflet.Util.geojsonToArcGIS(geojson.geometries[i], idAttribute));\n }\n break;\n }\n\n return result;\n };\n\n EsriLeaflet.Util.responseToFeatureCollection = function(response, idAttribute){\n var objectIdField;\n\n if(idAttribute){\n objectIdField = idAttribute;\n } else if(response.objectIdFieldName){\n objectIdField = response.objectIdFieldName;\n } else if(response.fields) {\n for (var j = 0; j <= response.fields.length - 1; j++) {\n if(response.fields[j].type === 'esriFieldTypeOID') {\n objectIdField = response.fields[j].name;\n break;\n }\n }\n } else {\n objectIdField = 'OBJECTID';\n }\n\n var featureCollection = {\n type: 'FeatureCollection',\n features: []\n };\n var features = response.features || response.results;\n if(features.length){\n for (var i = features.length - 1; i >= 0; i--) {\n featureCollection.features.push(EsriLeaflet.Util.arcgisToGeojson(features[i], objectIdField));\n }\n }\n\n return featureCollection;\n };\n\n // trim url whitespace and add a trailing slash if needed\n EsriLeaflet.Util.cleanUrl = function(url){\n //trim leading and trailing spaces, but not spaces inside the url\n url = url.replace(/^\\s+|\\s+$|\\A\\s+|\\s+\\z/g, '');\n\n //add a trailing slash to the url if the user omitted it\n if(url[url.length-1] !== '/'){\n url += '/';\n }\n\n return url;\n };\n\n EsriLeaflet.Util.isArcgisOnline = function(url){\n /* hosted feature services can emit geojson natively.\n our check for 'geojson' support will need to be revisted\n once the functionality makes its way to ArcGIS Server*/\n return (/\\.arcgis\\.com.*?FeatureServer/g).test(url);\n };\n\n EsriLeaflet.Util.geojsonTypeToArcGIS = function (geoJsonType) {\n var arcgisGeometryType;\n switch (geoJsonType) {\n case 'Point':\n arcgisGeometryType = 'esriGeometryPoint';\n break;\n case 'MultiPoint':\n arcgisGeometryType = 'esriGeometryMultipoint';\n break;\n case 'LineString':\n arcgisGeometryType = 'esriGeometryPolyline';\n break;\n case 'MultiLineString':\n arcgisGeometryType = 'esriGeometryPolyline';\n break;\n case 'Polygon':\n arcgisGeometryType = 'esriGeometryPolygon';\n break;\n case 'MultiPolygon':\n arcgisGeometryType = 'esriGeometryPolygon';\n break;\n }\n return arcgisGeometryType;\n };\n\n EsriLeaflet.Util.requestAnimationFrame = L.Util.bind(raf, window);\n\n})(EsriLeaflet);","(function(EsriLeaflet){\n\n var callbacks = 0;\n\n window._EsriLeafletCallbacks = {};\n\n function serialize(params){\n var data = '';\n\n params.f = params.f || 'json';\n\n for (var key in params){\n if(params.hasOwnProperty(key)){\n var param = params[key];\n var type = Object.prototype.toString.call(param);\n var value;\n\n if(data.length){\n data += '&';\n }\n\n if (type === '[object Array]'){\n value = (Object.prototype.toString.call(param[0]) === '[object Object]') ? JSON.stringify(param) : param.join(',');\n } else if (type === '[object Object]') {\n value = JSON.stringify(param);\n } else if (type === '[object Date]'){\n value = param.valueOf();\n } else {\n value = param;\n }\n\n data += encodeURIComponent(key) + '=' + encodeURIComponent(value);\n }\n }\n\n return data;\n }\n\n function createRequest(callback, context){\n var httpRequest = new XMLHttpRequest();\n\n httpRequest.onerror = function(e) {\n httpRequest.onreadystatechange = L.Util.falseFn;\n\n callback.call(context, {\n error: {\n code: 500,\n message: 'XMLHttpRequest error'\n }\n }, null);\n };\n\n httpRequest.onreadystatechange = function(){\n var response;\n var error;\n\n if (httpRequest.readyState === 4) {\n try {\n response = JSON.parse(httpRequest.responseText);\n } catch(e) {\n response = null;\n error = {\n code: 500,\n message: 'Could not parse response as JSON. This could also be caused by a CORS or XMLHttpRequest error.'\n };\n }\n\n if (!error && response.error) {\n error = response.error;\n response = null;\n }\n\n httpRequest.onerror = L.Util.falseFn;\n\n callback.call(context, error, response);\n }\n };\n\n return httpRequest;\n }\n\n // AJAX handlers for CORS (modern browsers) or JSONP (older browsers)\n EsriLeaflet.Request = {\n request: function(url, params, callback, context){\n var paramString = serialize(params);\n var httpRequest = createRequest(callback, context);\n var requestLength = (url + '?' + paramString).length;\n\n // request is less then 2000 characters and the browser supports CORS, make GET request with XMLHttpRequest\n if(requestLength <= 2000 && L.esri.Support.CORS){\n httpRequest.open('GET', url + '?' + paramString);\n httpRequest.send(null);\n\n // request is less more then 2000 characters and the browser supports CORS, make POST request with XMLHttpRequest\n } else if (requestLength > 2000 && L.esri.Support.CORS){\n httpRequest.open('POST', url);\n httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');\n httpRequest.send(paramString);\n\n // request is less more then 2000 characters and the browser does not support CORS, make a JSONP request\n } else if(requestLength <= 2000 && !L.esri.Support.CORS){\n return L.esri.Request.get.JSONP(url, params, callback, context);\n\n // request is longer then 2000 characters and the browser does not support CORS, log a warning\n } else {\n if(console && console.warn){\n console.warn('a request to ' + url + ' was longer then 2000 characters and this browser cannot make a cross-domain post request. Please use a proxy http://esri.github.io/esri-leaflet/api-reference/request.html');\n return;\n }\n }\n\n return httpRequest;\n },\n post: {\n XMLHTTP: function (url, params, callback, context) {\n var httpRequest = createRequest(callback, context);\n httpRequest.open('POST', url);\n httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');\n httpRequest.send(serialize(params));\n\n return httpRequest;\n }\n },\n\n get: {\n CORS: function (url, params, callback, context) {\n var httpRequest = createRequest(callback, context);\n\n httpRequest.open('GET', url + '?' + serialize(params), true);\n httpRequest.send(null);\n\n return httpRequest;\n },\n JSONP: function(url, params, callback, context){\n var callbackId = 'c' + callbacks;\n\n params.callback = 'window._EsriLeafletCallbacks.' + callbackId;\n\n var script = L.DomUtil.create('script', null, document.body);\n script.type = 'text/javascript';\n script.src = url + '?' + serialize(params);\n script.id = callbackId;\n\n window._EsriLeafletCallbacks[callbackId] = function(response){\n if(window._EsriLeafletCallbacks[callbackId] !== true){\n var error;\n var responseType = Object.prototype.toString.call(response);\n\n if(!(responseType === '[object Object]' || responseType === '[object Array]')){\n error = {\n error: {\n code: 500,\n message: 'Expected array or object as JSONP response'\n }\n };\n response = null;\n }\n\n if (!error && response.error) {\n error = response;\n response = null;\n }\n\n callback.call(context, error, response);\n window._EsriLeafletCallbacks[callbackId] = true;\n }\n };\n\n callbacks++;\n\n return {\n id: callbackId,\n url: script.src,\n abort: function(){\n window._EsriLeafletCallbacks._callback[callbackId]({\n code: 0,\n message: 'Request aborted.'\n });\n }\n };\n }\n }\n };\n\n // choose the correct AJAX handler depending on CORS support\n EsriLeaflet.get = (EsriLeaflet.Support.CORS) ? EsriLeaflet.Request.get.CORS : EsriLeaflet.Request.get.JSONP;\n\n // always use XMLHttpRequest for posts\n EsriLeaflet.post = EsriLeaflet.Request.post.XMLHTTP;\n\n // expose a common request method the uses GET\\POST based on request length\n EsriLeaflet.request = EsriLeaflet.Request.request;\n\n})(EsriLeaflet);","EsriLeaflet.Services.Service = L.Class.extend({\n\n includes: L.Mixin.Events,\n\n options: {\n proxy: false,\n useCors: EsriLeaflet.Support.CORS\n },\n\n initialize: function (options) {\n options = options || {};\n this._requestQueue = [];\n this._authenticating = false;\n L.Util.setOptions(this, options);\n this.options.url = EsriLeaflet.Util.cleanUrl(this.options.url);\n },\n\n get: function (path, params, callback, context) {\n return this._request('get', path, params, callback, context);\n },\n\n post: function (path, params, callback, context) {\n return this._request('post', path, params, callback, context);\n },\n\n request: function (path, params, callback, context) {\n return this._request('request', path, params, callback, context);\n },\n\n metadata: function (callback, context) {\n return this._request('get', '', {}, callback, context);\n },\n\n authenticate: function(token){\n this._authenticating = false;\n this.options.token = token;\n this._runQueue();\n return this;\n },\n\n _request: function(method, path, params, callback, context){\n this.fire('requeststart', {\n url: this.options.url + path,\n params: params,\n method: method\n });\n\n var wrappedCallback = this._createServiceCallback(method, path, params, callback, context);\n\n if (this.options.token) {\n params.token = this.options.token;\n }\n\n if (this._authenticating) {\n this._requestQueue.push([method, path, params, callback, context]);\n return;\n } else {\n var url = (this.options.proxy) ? this.options.proxy + '?' + this.options.url + path : this.options.url + path;\n\n if((method === 'get' || method === 'request') && !this.options.useCors){\n return EsriLeaflet.Request.get.JSONP(url, params, wrappedCallback);\n } else {\n return EsriLeaflet[method](url, params, wrappedCallback);\n }\n }\n },\n\n _createServiceCallback: function(method, path, params, callback, context){\n var request = [method, path, params, callback, context];\n\n return L.Util.bind(function(error, response){\n\n if (error && (error.code === 499 || error.code === 498)) {\n this._authenticating = true;\n\n this._requestQueue.push(request);\n\n this.fire('authenticationrequired', {\n authenticate: L.Util.bind(this.authenticate, this)\n });\n } else {\n callback.call(context, error, response);\n\n if(error) {\n this.fire('requesterror', {\n url: this.options.url + path,\n params: params,\n message: error.message,\n code: error.code,\n method: method\n });\n } else {\n this.fire('requestsuccess', {\n url: this.options.url + path,\n params: params,\n response: response,\n method: method\n });\n }\n\n this.fire('requestend', {\n url: this.options.url + path,\n params: params,\n method: method\n });\n }\n }, this);\n },\n\n _runQueue: function(){\n for (var i = this._requestQueue.length - 1; i >= 0; i--) {\n var request = this._requestQueue[i];\n var method = request.shift();\n this[method].apply(this, request);\n }\n this._requestQueue = [];\n }\n\n});\n\nEsriLeaflet.Services.service = function(params){\n return new EsriLeaflet.Services.Service(params);\n};","EsriLeaflet.Services.FeatureLayer = EsriLeaflet.Services.Service.extend({\n\n options: {\n idAttribute: 'OBJECTID'\n },\n\n query: function(){\n return new EsriLeaflet.Tasks.Query(this);\n },\n\n addFeature: function(feature, callback, context) {\n delete feature.id;\n\n feature = EsriLeaflet.Util.geojsonToArcGIS(feature);\n\n return this.post('addFeatures', {\n features: [feature]\n }, function(error, response){\n var result = (response && response.addResults) ? response.addResults[0] : undefined;\n if(callback){\n callback.call(context, error || response.addResults[0].error, result);\n }\n }, context);\n },\n\n updateFeature: function(feature, callback, context) {\n feature = EsriLeaflet.Util.geojsonToArcGIS(feature, this.options.idAttribute);\n\n return this.post('updateFeatures', {\n features: [feature]\n }, function(error, response){\n var result = (response && response.updateResults) ? response.updateResults[0] : undefined;\n if(callback){\n callback.call(context, error || response.updateResults[0].error, result);\n }\n }, context);\n },\n\n deleteFeature: function(id, callback, context) {\n return this.post('deleteFeatures', {\n objectIds: id\n }, function(error, response){\n var result = (response && response.deleteResults) ? response.deleteResults[0] : undefined;\n if(callback){\n callback.call(context, error || response.deleteResults[0].error, result);\n }\n }, context);\n },\n\n deleteFeatures: function(ids, callback, context) {\n return this.post('deleteFeatures', {\n objectIds: ids\n }, function(error, response){\n // pass back the entire array\n var result = (response && response.deleteResults) ? response.deleteResults : undefined;\n if(callback){\n callback.call(context, error || response.deleteResults[0].error, result);\n }\n }, context);\n }\n});\n\nEsriLeaflet.Services.featureLayer = function(options) {\n return new EsriLeaflet.Services.FeatureLayer(options);\n};","EsriLeaflet.Services.MapService = EsriLeaflet.Services.Service.extend({\n\n identify: function () {\n return new EsriLeaflet.Tasks.identifyFeatures(this);\n },\n\n find: function () {\n return new EsriLeaflet.Tasks.Find(this);\n },\n\n query: function () {\n return new EsriLeaflet.Tasks.Query(this);\n }\n\n});\n\nEsriLeaflet.Services.mapService = function(params){\n return new EsriLeaflet.Services.MapService(params);\n};","EsriLeaflet.Services.ImageService = EsriLeaflet.Services.Service.extend({\n\n query: function () {\n return new EsriLeaflet.Tasks.Query(this);\n },\n\n identify: function() {\n return new EsriLeaflet.Tasks.IdentifyImage(this);\n }\n});\n\nEsriLeaflet.Services.imageService = function(params){\n return new EsriLeaflet.Services.ImageService(params);\n};","EsriLeaflet.Tasks.Task = L.Class.extend({\n\n options: {\n proxy: false,\n useCors: EsriLeaflet.Support.CORS\n },\n\n //Generate a method for each methodName:paramName in the setters for this task.\n generateSetter: function(param, context){\n return L.Util.bind(function(value){\n this.params[param] = value;\n return this;\n }, context);\n },\n\n initialize: function(endpoint){\n // endpoint can be either a url (and options) for an ArcGIS Rest Service or an instance of EsriLeaflet.Service\n if(endpoint.request && endpoint.options){\n this._service = endpoint;\n L.Util.setOptions(this, endpoint.options);\n } else {\n L.Util.setOptions(this, endpoint);\n this.options.url = L.esri.Util.cleanUrl(endpoint.url);\n }\n\n // clone default params into this object\n this.params = L.Util.extend({}, this.params || {});\n\n // generate setter methods based on the setters object implimented a child class\n if(this.setters){\n for (var setter in this.setters){\n var param = this.setters[setter];\n this[setter] = this.generateSetter(param, this);\n }\n }\n },\n\n token: function(token){\n if(this._service){\n this._service.authenticate(token);\n } else {\n this.params.token = token;\n }\n return this;\n },\n\n request: function(callback, context){\n if(this._service){\n return this._service.request(this.path, this.params, callback, context);\n } else {\n return this._request('request', this.path, this.params, callback, context);\n }\n },\n\n _request: function(method, path, params, callback, context){\n var url = (this.options.proxy) ? this.options.proxy + '?' + this.options.url + path : this.options.url + path;\n if((method === 'get' || method === 'request') && !this.options.useCors){\n return EsriLeaflet.Request.get.JSONP(url, params, callback, context);\n } else{\n return EsriLeaflet[method](url, params, callback, context);\n }\n }\n});","EsriLeaflet.Tasks.Query = EsriLeaflet.Tasks.Task.extend({\n setters: {\n 'offset': 'offset',\n 'limit': 'limit',\n 'fields': 'outFields',\n 'precision': 'geometryPrecision',\n 'featureIds': 'objectIds',\n 'returnGeometry': 'returnGeometry',\n 'token': 'token'\n },\n\n path: 'query',\n\n params: {\n returnGeometry: true,\n where: '1=1',\n outSr: 4326,\n outFields: '*'\n },\n\n within: function(geometry){\n this._setGeometry(geometry);\n this.params.spatialRel = 'esriSpatialRelContains'; // will make code read layer within geometry, to the api this will reads geometry contains layer\n return this;\n },\n\n intersects: function(geometry){\n this._setGeometry(geometry);\n this.params.spatialRel = 'esriSpatialRelIntersects';\n return this;\n },\n\n contains: function(geometry){\n this._setGeometry(geometry);\n this.params.spatialRel = 'esriSpatialRelWithin'; // will make code read layer contains geometry, to the api this will reads geometry within layer\n return this;\n },\n\n // crosses: function(geometry){\n // this._setGeometry(geometry);\n // this.params.spatialRel = 'esriSpatialRelCrosses';\n // return this;\n // },\n\n // touches: function(geometry){\n // this._setGeometry(geometry);\n // this.params.spatialRel = 'esriSpatialRelTouches';\n // return this;\n // },\n\n overlaps: function(geometry){\n this._setGeometry(geometry);\n this.params.spatialRel = 'esriSpatialRelOverlaps';\n return this;\n },\n\n // only valid for Feature Services running on ArcGIS Server 10.3 or ArcGIS Online\n nearby: function(latlng, radius){\n latlng = L.latLng(latlng);\n this.params.geometry = [latlng.lng, latlng.lat];\n this.params.geometryType = 'esriGeometryPoint';\n this.params.spatialRel = 'esriSpatialRelIntersects';\n this.params.units = 'esriSRUnit_Meter';\n this.params.distance = radius;\n this.params.inSr = 4326;\n return this;\n },\n\n where: function(string){\n this.params.where = string.replace(/\"/g, \"\\'\"); // jshint ignore:line\n return this;\n },\n\n between: function(start, end){\n this.params.time = [start.valueOf(), end.valueOf()];\n return this;\n },\n\n simplify: function(map, factor){\n var mapWidth = Math.abs(map.getBounds().getWest() - map.getBounds().getEast());\n this.params.maxAllowableOffset = (mapWidth / map.getSize().y) * factor;\n return this;\n },\n\n orderBy: function(fieldName, order){\n order = order || 'ASC';\n this.params.orderByFields = (this.params.orderByFields) ? this.params.orderByFields + ',' : '';\n this.params.orderByFields += ([fieldName, order]).join(' ');\n return this;\n },\n\n run: function(callback, context){\n this._cleanParams();\n\n // if the service is hosted on arcgis online request geojson directly\n if(EsriLeaflet.Util.isArcgisOnline(this.options.url)){\n this.params.f = 'geojson';\n\n return this.request(function(error, response){\n callback.call(context, error, response, response);\n }, context);\n\n // otherwise convert it in the callback then pass it on\n } else {\n return this.request(function(error, response){\n callback.call(context, error, (response && EsriLeaflet.Util.responseToFeatureCollection(response)), response);\n }, context);\n }\n },\n\n count: function(callback, context){\n this._cleanParams();\n this.params.returnCountOnly = true;\n return this.request(function(error, response){\n callback.call(this, error, (response && response.count), response);\n }, context);\n },\n\n ids: function(callback, context){\n this._cleanParams();\n this.params.returnIdsOnly = true;\n return this.request(function(error, response){\n callback.call(this, error, (response && response.objectIds), response);\n }, context);\n },\n\n // only valid for Feature Services running on ArcGIS Server 10.3 or ArcGIS Online\n bounds: function(callback, context){\n this._cleanParams();\n this.params.returnExtentOnly = true;\n return this.request(function(error, response){\n callback.call(context, error, (response && response.extent && EsriLeaflet.Util.extentToBounds(response.extent)), response);\n }, context);\n },\n\n // only valid for image services\n pixelSize: function(point){\n point = L.point(point);\n this.params.pixelSize = [point.x,point.y];\n return this;\n },\n\n // only valid for map services\n layer: function(layer){\n this.path = layer + '/query';\n return this;\n },\n\n _cleanParams: function(){\n delete this.params.returnIdsOnly;\n delete this.params.returnExtentOnly;\n delete this.params.returnCountOnly;\n },\n\n _setGeometry: function(geometry) {\n this.params.inSr = 4326;\n\n // convert bounds to extent and finish\n if ( geometry instanceof L.LatLngBounds ) {\n // set geometry + geometryType\n this.params.geometry = EsriLeaflet.Util.boundsToExtent(geometry);\n this.params.geometryType = 'esriGeometryEnvelope';\n return;\n }\n\n // convert L.Marker > L.LatLng\n if(geometry.getLatLng){\n geometry = geometry.getLatLng();\n }\n\n // convert L.LatLng to a geojson point and continue;\n if (geometry instanceof L.LatLng) {\n geometry = {\n type: 'Point',\n coordinates: [geometry.lng, geometry.lat]\n };\n }\n\n // handle L.GeoJSON, pull out the first geometry\n if ( geometry instanceof L.GeoJSON ) {\n //reassign geometry to the GeoJSON value (we are assuming that only one feature is present)\n geometry = geometry.getLayers()[0].feature.geometry;\n this.params.geometry = EsriLeaflet.Util.geojsonToArcGIS(geometry);\n this.params.geometryType = EsriLeaflet.Util.geojsonTypeToArcGIS(geometry.type);\n }\n\n // Handle L.Polyline and L.Polygon\n if (geometry.toGeoJSON) {\n geometry = geometry.toGeoJSON();\n }\n\n // handle GeoJSON feature by pulling out the geometry\n if ( geometry.type === 'Feature' ) {\n // get the geometry of the geojson feature\n geometry = geometry.geometry;\n }\n\n // confirm that our GeoJSON is a point, line or polygon\n if ( geometry.type === 'Point' || geometry.type === 'LineString' || geometry.type === 'Polygon') {\n this.params.geometry = EsriLeaflet.Util.geojsonToArcGIS(geometry);\n this.params.geometryType = EsriLeaflet.Util.geojsonTypeToArcGIS(geometry.type);\n return;\n }\n\n // warn the user if we havn't found a\n /* global console */\n if(console && console.warn) {\n console.warn('invalid geometry passed to spatial query. Should be an L.LatLng, L.LatLngBounds or L.Marker or a GeoJSON Point Line or Polygon object');\n }\n\n return;\n }\n});\n\nEsriLeaflet.Tasks.query = function(params){\n return new EsriLeaflet.Tasks.Query(params);\n};","EsriLeaflet.Tasks.Find = EsriLeaflet.Tasks.Task.extend({\n setters: {\n // method name > param name\n 'contains': 'contains',\n 'text': 'searchText',\n 'fields': 'searchFields', // denote an array or single string\n 'spatialReference': 'sr',\n 'sr': 'sr',\n 'layers': 'layers',\n 'returnGeometry': 'returnGeometry',\n 'maxAllowableOffset': 'maxAllowableOffset',\n 'precision': 'geometryPrecision',\n 'dynamicLayers': 'dynamicLayers',\n 'returnZ' : 'returnZ',\n 'returnM' : 'returnM',\n 'gdbVersion' : 'gdbVersion',\n 'token' : 'token'\n },\n\n path: 'find',\n\n params: {\n sr: 4326,\n contains: true,\n returnGeometry: true,\n returnZ: true,\n returnM: false\n },\n\n layerDefs: function (id, where) {\n this.params.layerDefs = (this.params.layerDefs) ? this.params.layerDefs + ';' : '';\n this.params.layerDefs += ([id, where]).join(':');\n return this;\n },\n\n simplify: function(map, factor){\n var mapWidth = Math.abs(map.getBounds().getWest() - map.getBounds().getEast());\n this.params.maxAllowableOffset = (mapWidth / map.getSize().y) * factor;\n return this;\n },\n\n run: function (callback, context) {\n return this.request(function(error, response){\n callback.call(context, error, (response && EsriLeaflet.Util.responseToFeatureCollection(response)), response);\n }, context);\n }\n});\n\nEsriLeaflet.Tasks.find = function (params) {\n return new EsriLeaflet.Tasks.Find(params);\n};","EsriLeaflet.Tasks.Identify = EsriLeaflet.Tasks.Task.extend({\n path: 'identify',\n\n between: function(start, end){\n this.params.time = [start.valueOf(), end.valueOf()];\n return this;\n }\n});\n","EsriLeaflet.Tasks.IdentifyImage = EsriLeaflet.Tasks.Identify.extend({\n setters: {\n 'setMosaicRule': 'mosaicRule',\n 'setRenderingRule': 'renderingRule',\n 'setPixelSize': 'pixelSize',\n 'returnCatalogItems': 'returnCatalogItems',\n 'returnGeometry': 'returnGeometry'\n },\n\n params: {\n returnGeometry: false\n },\n\n at: function(latlng){\n latlng = L.latLng(latlng);\n this.params.geometry = JSON.stringify({\n x: latlng.lng,\n y: latlng.lat,\n spatialReference:{\n wkid: 4326\n }\n });\n this.params.geometryType = 'esriGeometryPoint';\n return this;\n },\n\n getMosaicRule: function() {\n return this.params.mosaicRule;\n },\n\n getRenderingRule: function() {\n return this.params.renderingRule;\n },\n\n getPixelSize: function() {\n return this.params.pixelSize;\n },\n\n run: function (callback, context){\n return this.request(function(error, response){\n callback.call(context, error, (response && this._responseToGeoJSON(response)), response);\n }, this);\n },\n\n // get pixel data and return as geoJSON point\n // populate catalog items (if any)\n // merging in any catalogItemVisibilities as a propery of each feature\n _responseToGeoJSON: function(response) {\n var location = response.location;\n var catalogItems = response.catalogItems;\n var catalogItemVisibilities = response.catalogItemVisibilities;\n var geoJSON = {\n 'pixel': {\n 'type': 'Feature',\n 'geometry': {\n 'type': 'Point',\n 'coordinates': [location.x, location.y]\n },\n 'crs': {\n 'type': 'EPSG',\n 'properties': {\n 'code': location.spatialReference.wkid\n }\n },\n 'properties': {\n 'OBJECTID': response.objectId,\n 'name': response.name,\n 'value': response.value\n },\n 'id': response.objectId\n }\n };\n if (response.properties && response.properties.Values) {\n geoJSON.pixel.properties.values = response.properties.Values;\n }\n if (catalogItems && catalogItems.features) {\n geoJSON.catalogItems = EsriLeaflet.Util.responseToFeatureCollection(catalogItems);\n if (catalogItemVisibilities && catalogItemVisibilities.length === geoJSON.catalogItems.features.length) {\n for (var i = catalogItemVisibilities.length - 1; i >= 0; i--) {\n geoJSON.catalogItems.features[i].properties.catalogItemVisibility = catalogItemVisibilities[i];\n }\n }\n }\n return geoJSON;\n }\n\n});\n\nEsriLeaflet.Tasks.identifyImage = function(params){\n return new EsriLeaflet.Tasks.IdentifyImage(params);\n};","EsriLeaflet.Tasks.IdentifyFeatures = EsriLeaflet.Tasks.Identify.extend({\n setters: {\n 'layers': 'layers',\n 'precision': 'geometryPrecision',\n 'tolerance': 'tolerance',\n 'returnGeometry': 'returnGeometry'\n },\n\n params: {\n sr: 4326,\n layers: 'all',\n tolerance: 3,\n returnGeometry: true\n },\n\n on: function(map){\n var extent = EsriLeaflet.Util.boundsToExtent(map.getBounds());\n var size = map.getSize();\n this.params.imageDisplay = [size.x, size.y, 96];\n this.params.mapExtent = [extent.xmin, extent.ymin, extent.xmax, extent.ymax];\n return this;\n },\n\n at: function(latlng){\n latlng = L.latLng(latlng);\n this.params.geometry = [latlng.lng, latlng.lat];\n this.params.geometryType = 'esriGeometryPoint';\n return this;\n },\n\n layerDef: function (id, where){\n this.params.layerDefs = (this.params.layerDefs) ? this.params.layerDefs + ';' : '';\n this.params.layerDefs += ([id, where]).join(':');\n return this;\n },\n\n simplify: function(map, factor){\n var mapWidth = Math.abs(map.getBounds().getWest() - map.getBounds().getEast());\n this.params.maxAllowableOffset = (mapWidth / map.getSize().y) * (1 - factor);\n return this;\n },\n\n run: function (callback, context){\n return this.request(function(error, response){\n // immediately invoke with an error\n if(error) {\n callback.call(context, error, undefined, response);\n return;\n\n // ok no error lets just assume we have features...\n } else {\n var featureCollection = EsriLeaflet.Util.responseToFeatureCollection(response);\n response.results = response.results.reverse();\n for (var i = 0; i < featureCollection.features.length; i++) {\n var feature = featureCollection.features[i];\n feature.layerId = response.results[i].layerId;\n }\n callback.call(context, undefined, featureCollection, response);\n }\n });\n }\n});\n\nEsriLeaflet.Tasks.identifyFeatures = function(params){\n return new EsriLeaflet.Tasks.IdentifyFeatures(params);\n};","(function(EsriLeaflet){\n\n var tileProtocol = (window.location.protocol !== 'https:') ? 'http:' : 'https:';\n\n EsriLeaflet.Layers.BasemapLayer = L.TileLayer.extend({\n statics: {\n TILES: {\n Streets: {\n urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}',\n attributionUrl: 'https://static.arcgis.com/attribution/World_Street_Map',\n options: {\n hideLogo: false,\n logoPosition: 'bottomright',\n minZoom: 1,\n maxZoom: 19,\n subdomains: ['server', 'services'],\n attribution: 'Esri'\n }\n },\n Topographic: {\n urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}',\n attributionUrl: 'https://static.arcgis.com/attribution/World_Topo_Map',\n options: {\n hideLogo: false,\n logoPosition: 'bottomright',\n minZoom: 1,\n maxZoom: 19,\n subdomains: ['server', 'services'],\n attribution: 'Esri'\n }\n },\n Oceans: {\n urlTemplate: tileProtocol + '//{s}.arcgisonline.com/arcgis/rest/services/Ocean/World_Ocean_Base/MapServer/tile/{z}/{y}/{x}',\n attributionUrl: 'https://static.arcgis.com/attribution/Ocean_Basemap',\n options: {\n hideLogo: false,\n logoPosition: 'bottomright',\n minZoom: 1,\n maxZoom: 16,\n subdomains: ['server', 'services'],\n attribution: 'Esri'\n }\n },\n OceansLabels: {\n urlTemplate: tileProtocol + '//{s}.arcgisonline.com/arcgis/rest/services/Ocean/World_Ocean_Reference/MapServer/tile/{z}/{y}/{x}',\n options: {\n hideLogo: true,\n logoPosition: 'bottomright',\n //pane: 'esri-label',\n minZoom: 1,\n maxZoom: 16,\n subdomains: ['server', 'services']\n }\n },\n NationalGeographic: {\n urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{z}/{y}/{x}',\n options: {\n hideLogo: false,\n logoPosition: 'bottomright',\n minZoom: 1,\n maxZoom: 16,\n subdomains: ['server', 'services'],\n attribution: 'Esri'\n }\n },\n DarkGray: {\n urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Dark_Gray_Base/MapServer/tile/{z}/{y}/{x}',\n options: {\n hideLogo: false,\n logoPosition: 'bottomright',\n minZoom: 1,\n maxZoom: 16,\n subdomains: ['server', 'services'],\n attribution: 'Esri, DeLorme, HERE'\n }\n },\n DarkGrayLabels: {\n urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Dark_Gray_Reference/MapServer/tile/{z}/{y}/{x}',\n options: {\n hideLogo: true,\n logoPosition: 'bottomright',\n //pane: 'esri-label',\n minZoom: 1,\n maxZoom: 16,\n subdomains: ['server', 'services']\n }\n },\n Gray: {\n urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer/tile/{z}/{y}/{x}',\n options: {\n hideLogo: false,\n logoPosition: 'bottomright',\n minZoom: 1,\n maxZoom: 16,\n subdomains: ['server', 'services'],\n attribution: 'Esri, NAVTEQ, DeLorme'\n }\n },\n GrayLabels: {\n urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Reference/MapServer/tile/{z}/{y}/{x}',\n options: {\n hideLogo: true,\n logoPosition: 'bottomright',\n //pane: 'esri-label',\n minZoom: 1,\n maxZoom: 16,\n subdomains: ['server', 'services']\n }\n },\n Imagery: {\n urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',\n options: {\n hideLogo: false,\n logoPosition: 'bottomright',\n minZoom: 1,\n maxZoom: 19,\n subdomains: ['server', 'services'],\n attribution: 'Esri, DigitalGlobe, GeoEye, i-cubed, USDA, USGS, AEX, Getmapping, Aerogrid, IGN, IGP, swisstopo, and the GIS User Community'\n }\n },\n ImageryLabels: {\n urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places/MapServer/tile/{z}/{y}/{x}',\n options: {\n hideLogo: true,\n logoPosition: 'bottomright',\n //pane: 'esri-label',\n minZoom: 1,\n maxZoom: 19,\n subdomains: ['server', 'services']\n }\n },\n ImageryTransportation: {\n urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Reference/World_Transportation/MapServer/tile/{z}/{y}/{x}',\n //pane: 'esri-label',\n options: {\n hideLogo: true,\n logoPosition: 'bottomright',\n minZoom: 1,\n maxZoom: 19,\n subdomains: ['server', 'services']\n }\n },\n ShadedRelief: {\n urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/World_Shaded_Relief/MapServer/tile/{z}/{y}/{x}',\n options: {\n hideLogo: false,\n logoPosition: 'bottomright',\n minZoom: 1,\n maxZoom: 13,\n subdomains: ['server', 'services'],\n attribution: 'Esri, NAVTEQ, DeLorme'\n }\n },\n ShadedReliefLabels: {\n urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places_Alternate/MapServer/tile/{z}/{y}/{x}',\n options: {\n hideLogo: true,\n logoPosition: 'bottomright',\n //pane: 'esri-label',\n minZoom: 1,\n maxZoom: 12,\n subdomains: ['server', 'services']\n }\n },\n Terrain: {\n urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/World_Terrain_Base/MapServer/tile/{z}/{y}/{x}',\n options: {\n hideLogo: false,\n logoPosition: 'bottomright',\n minZoom: 1,\n maxZoom: 13,\n subdomains: ['server', 'services'],\n attribution: 'Esri, USGS, NOAA'\n }\n },\n TerrainLabels: {\n urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Reference/World_Reference_Overlay/MapServer/tile/{z}/{y}/{x}',\n options: {\n hideLogo: true,\n logoPosition: 'bottomright',\n //pane: 'esri-label',\n minZoom: 1,\n maxZoom: 13,\n subdomains: ['server', 'services']\n }\n }\n }\n },\n initialize: function(key, options){\n var config;\n\n // set the config variable with the appropriate config object\n if (typeof key === 'object' && key.urlTemplate && key.options){\n config = key;\n } else if(typeof key === 'string' && EsriLeaflet.BasemapLayer.TILES[key]){\n config = EsriLeaflet.BasemapLayer.TILES[key];\n } else {\n throw new Error('L.esri.BasemapLayer: Invalid parameter. Use one of \"Streets\", \"Topographic\", \"Oceans\", \"OceansLabels\", \"NationalGeographic\", \"Gray\", \"GrayLabels\", \"DarkGray\", \"DarkGrayLabels\", \"Imagery\", \"ImageryLabels\", \"ImageryTransportation\", \"ShadedRelief\", \"ShadedReliefLabels\", \"Terrain\" or \"TerrainLabels\"');\n }\n\n // merge passed options into the config options\n var tileOptions = L.Util.extend(config.options, options);\n\n // call the initialize method on L.TileLayer to set everything up\n L.TileLayer.prototype.initialize.call(this, config.urlTemplate, L.Util.setOptions(this, tileOptions));\n\n // if this basemap requires dynamic attribution set it up\n if(config.attributionUrl){\n this._getAttributionData(config.attributionUrl);\n }\n this._logo = new EsriLeaflet.Controls.Logo({\n position: this.options.logoPosition\n });\n },\n onAdd: function(map){\n if(!this.options.hideLogo && !map._hasEsriLogo){\n this._logo.addTo(map);\n map._hasEsriLogo = true;\n }\n\n // if(this.options.pane && EsriLeaflet.Support.pointerEvents){\n // this._initPane();\n // }\n\n L.TileLayer.prototype.onAdd.call(this, map);\n\n map.on('moveend', this._updateMapAttribution, this);\n },\n onRemove: function(map){\n // check to make sure the logo hasn't already been removed\n if(this._logo && this._logo._container){\n map.removeControl(this._logo);\n map._hasEsriLogo = false;\n }\n\n L.TileLayer.prototype.onRemove.call(this, map);\n\n map.off('moveend', this._updateMapAttribution, this);\n },\n getAttribution:function(){\n var attribution = '<span class=\"esri-attributions\" style=\"line-height:14px; vertical-align: -3px; text-overflow:ellipsis; white-space:nowrap; overflow:hidden; display:inline-block;\">' + this.options.attribution + '</span>'/* + logo*/;\n return attribution;\n },\n // _initPane: function(){\n // if(!this._map.getPane(this.options.pane)){\n // var pane = this._map.createPane(this.options.pane);\n // pane.style.pointerEvents = 'none';\n // pane.style.zIndex = 5;\n // }\n // },\n _getAttributionData: function(url){\n L.esri.Request.get.JSONP(url, {}, L.Util.bind(function(error, attributions){\n this._attributions = [];\n\n for (var c = 0; c < attributions.contributors.length; c++) {\n var contributor = attributions.contributors[c];\n for (var i = 0; i < contributor.coverageAreas.length; i++) {\n var coverageArea = contributor.coverageAreas[i];\n var southWest = new L.LatLng(coverageArea.bbox[0], coverageArea.bbox[1]);\n var northEast = new L.LatLng(coverageArea.bbox[2], coverageArea.bbox[3]);\n this._attributions.push({\n attribution: contributor.attribution,\n score: coverageArea.score,\n bounds: new L.LatLngBounds(southWest, northEast),\n minZoom: coverageArea.zoomMin,\n maxZoom: coverageArea.zoomMax\n });\n }\n }\n\n this._attributions.sort(function(a, b){\n return b.score - a.score;\n });\n\n this._updateMapAttribution();\n }, this));\n },\n _updateMapAttribution: function(){\n if(this._map && this._map.attributionControl && this._attributions){\n var newAttributions = '';\n var bounds = this._map.getBounds();\n var zoom = this._map.getZoom();\n\n for (var i = 0; i < this._attributions.length; i++) {\n var attribution = this._attributions[i];\n var text = attribution.attribution;\n if(!newAttributions.match(text) && bounds.intersects(attribution.bounds) && zoom >= attribution.minZoom && zoom <= attribution.maxZoom) {\n newAttributions += (', ' + text);\n }\n }\n newAttributions = newAttributions.substr(2);\n var attributionElement = this._map.attributionControl._container.querySelector('.esri-attributions');\n attributionElement.innerHTML = newAttributions;\n attributionElement.style.maxWidth = (this._map.getSize().x * 0.65) + 'px';\n this.fire('attributionupdated', {\n attribution: newAttributions\n });\n }\n }\n });\n\n EsriLeaflet.BasemapLayer = EsriLeaflet.Layers.BasemapLayer;\n\n EsriLeaflet.Layers.basemapLayer = function(key, options){\n return new EsriLeaflet.Layers.BasemapLayer(key, options);\n };\n\n EsriLeaflet.basemapLayer = function(key, options){\n return new EsriLeaflet.Layers.BasemapLayer(key, options);\n };\n\n})(EsriLeaflet);","EsriLeaflet.Layers.RasterLayer = L.Class.extend({\n includes: L.Mixin.Events,\n\n options: {\n opacity: 1,\n position: 'front',\n f: 'image'\n },\n\n onAdd: function (map) {\n this._map = map;\n\n this._update = L.Util.limitExecByInterval(this._update, this.options.updateInterval, this);\n\n if (map.options.crs && map.options.crs.code) {\n var sr = map.options.crs.code.split(':')[1];\n this.options.bboxSR = sr;\n this.options.imageSR = sr;\n }\n\n map.on('moveend', this._update, this);\n\n // if we had an image loaded and it matches the\n // current bounds show the image otherwise remove it\n if(this._currentImage && this._currentImage._bounds.equals(this._map.getBounds())){\n map.addLayer(this._currentImage);\n } else if(this._currentImage) {\n this._map.removeLayer(this._currentImage);\n this._currentImage = null;\n }\n\n this._update();\n\n if(this._popup){\n this._map.on('click', this._getPopupData, this);\n this._map.on('dblclick', this._resetPopupState, this);\n }\n },\n\n bindPopup: function(fn, popupOptions){\n this._shouldRenderPopup = false;\n this._lastClick = false;\n this._popup = L.popup(popupOptions);\n this._popupFunction = fn;\n if(this._map){\n this._map.on('click', this._getPopupData, this);\n this._map.on('dblclick', this._resetPopupState, this);\n }\n return this;\n },\n\n unbindPopup: function(){\n if(this._map){\n this._map.closePopup(this._popup);\n this._map.off('click', this._getPopupData, this);\n this._map.off('dblclick', this._resetPopupState, this);\n }\n this._popup = false;\n return this;\n },\n\n onRemove: function (map) {\n if (this._currentImage) {\n this._map.removeLayer(this._currentImage);\n }\n\n if(this._popup){\n this._map.off('click', this._getPopupData, this);\n this._map.off('dblclick', this._resetPopupState, this);\n }\n\n this._map.off('moveend', this._update, this);\n this._map = null;\n },\n\n addTo: function(map){\n map.addLayer(this);\n return this;\n },\n\n removeFrom: function(map){\n map.removeLayer(this);\n return this;\n },\n\n bringToFront: function(){\n this.options.position = 'front';\n if(this._currentImage){\n this._currentImage.bringToFront();\n }\n return this;\n },\n\n bringToBack: function(){\n this.options.position = 'back';\n if(this._currentImage){\n this._currentImage.bringToBack();\n }\n return this;\n },\n\n getAttribution: function () {\n return this.options.attribution;\n },\n\n getOpacity: function(){\n return this.options.opacity;\n },\n\n setOpacity: function(opacity){\n this.options.opacity = opacity;\n this._currentImage.setOpacity(opacity);\n return this;\n },\n\n getTimeRange: function(){\n return [this.options.from, this.options.to];\n },\n\n setTimeRange: function(from, to){\n this.options.from = from;\n this.options.to = to;\n this._update();\n return this;\n },\n\n metadata: function(callback, context){\n this._service.metadata(callback, context);\n return this;\n },\n\n authenticate: function(token){\n this._service.authenticate(token);\n return this;\n },\n\n _renderImage: function(url, bounds){\n if(this._map){\n // create a new image overlay and add it to the map\n // to start loading the image\n // opacity is 0 while the image is loading\n var image = new L.ImageOverlay(url, bounds, {\n opacity: 0\n }).addTo(this._map);\n\n // once the image loads\n image.once('load', function(e){\n var newImage = e.target;\n var oldImage = this._currentImage;\n\n // if the bounds of this image matches the bounds that\n // _renderImage was called with and we have a map with the same bounds\n // hide the old image if there is one and set the opacity\n // of the new image otherwise remove the new image\n if(newImage._bounds.equals(bounds) && newImage._bounds.equals(this._map.getBounds())){\n this._currentImage = newImage;\n\n if(this.options.position === 'front'){\n this.bringToFront();\n } else {\n this.bringToBack();\n }\n\n if(this._map && this._currentImage._map){\n this._currentImage.setOpacity(this.options.opacity);\n } else {\n this._currentImage._map.removeLayer(this._currentImage);\n }\n\n if(oldImage && this._map) {\n this._map.removeLayer(oldImage);\n }\n\n if(oldImage && oldImage._map){\n oldImage._map.removeLayer(oldImage);\n }\n } else {\n this._map.removeLayer(newImage);\n }\n\n this.fire('load', {\n bounds: bounds\n });\n\n }, this);\n\n this.fire('loading', {\n bounds: bounds\n });\n }\n },\n\n _update: function () {\n if(!this._map){\n return;\n }\n\n var zoom = this._map.getZoom();\n var bounds = this._map.getBounds();\n\n if(this._animatingZoom){\n return;\n }\n\n if (this._map._panTransition && this._map._panTransition._inProgress) {\n return;\n }\n\n if (zoom > this.options.maxZoom || zoom < this.options.minZoom) {\n return;\n }\n var params = this._buildExportParams();\n\n this._requestExport(params, bounds);\n },\n\n // TODO: refactor these into raster layer\n _renderPopup: function(latlng, error, results, response){\n latlng = L.latLng(latlng);\n if(this._shouldRenderPopup && this._lastClick.equals(latlng)){\n //add the popup to the map where the mouse was clicked at\n var content = this._popupFunction(error, results, response);\n if (content) {\n this._popup.setLatLng(latlng).setContent(content).openOn(this._map);\n }\n }\n },\n\n _resetPopupState: function(e){\n this._shouldRenderPopup = false;\n this._lastClick = e.latlng;\n },\n\n // from https://github.com/Leaflet/Leaflet/blob/v0.7.2/src/layer/FeatureGroup.js\n // @TODO remove at Leaflet 0.8\n _propagateEvent: function (e) {\n e = L.extend({\n layer: e.target,\n target: this\n }, e);\n this.fire(e.type, e);\n }\n});","EsriLeaflet.Layers.DynamicMapLayer = EsriLeaflet.Layers.RasterLayer.extend({\n\n options: {\n updateInterval: 150,\n layers: false,\n layerDefs: false,\n timeOptions: false,\n format: 'png24',\n transparent: true,\n f: 'json'\n },\n\n initialize: function (url, options) {\n options = options || {};\n options.url = EsriLeaflet.Util.cleanUrl(url);\n this._service = new EsriLeaflet.Services.MapService(options);\n this._service.on('authenticationrequired requeststart requestend requesterror requestsuccess', this._propagateEvent, this);\n if ((options.proxy || options.token) && options.f !== 'json'){\n options.f = 'json';\n }\n L.Util.setOptions(this, options);\n },\n\n getLayers: function(){\n return this.options.layers;\n },\n\n setLayers: function(layers){\n this.options.layers = layers;\n this._update();\n return this;\n },\n\n getLayerDefs: function(){\n return this.options.layerDefs;\n },\n\n setLayerDefs: function(layerDefs){\n this.options.layerDefs = layerDefs;\n this._update();\n return this;\n },\n\n getTimeOptions: function(){\n return this.options.timeOptions;\n },\n\n setTimeOptions: function(timeOptions){\n this.options.timeOptions = timeOptions;\n this._update();\n return this;\n },\n\n query: function(){\n return this._service.query();\n },\n\n identify: function(){\n return this._service.identify();\n },\n\n find: function(){\n return this._service.find();\n },\n\n _getPopupData: function(e){\n var callback = L.Util.bind(function(error, featureCollection, response) {\n setTimeout(L.Util.bind(function(){\n this._renderPopup(e.latlng, error, featureCollection, response);\n }, this), 300);\n }, this);\n\n var identifyRequest = this.identify().on(this._map).at(e.latlng);\n\n if(this.options.layers){\n identifyRequest.layers('visible:' + this.options.layers.join(','));\n } else {\n identifyRequest.layers('visible');\n }\n\n identifyRequest.run(callback);\n\n // set the flags to show the popup\n this._shouldRenderPopup = true;\n this._lastClick = e.latlng;\n },\n\n _buildExportParams: function () {\n var bounds = this._map.getBounds();\n var size = this._map.getSize();\n var ne = this._map.options.crs.project(bounds._northEast);\n var sw = this._map.options.crs.project(bounds._southWest);\n\n //ensure that we don't ask ArcGIS Server for a taller image than we have actual map displaying\n var top = this._map.latLngToLayerPoint(bounds._northEast);\n var bottom = this._map.latLngToLayerPoint(bounds._southWest);\n\n if (top.y > 0 || bottom.y < size.y){\n size.y = bottom.y - top.y;\n }\n\n var params = {\n bbox: [sw.x, sw.y, ne.x, ne.y].join(','),\n size: size.x + ',' + size.y,\n dpi: 96,\n format: this.options.format,\n transparent: this.options.transparent,\n bboxSR: this.options.bboxSR,\n imageSR: this.options.imageSR\n };\n\n if(this.options.layers){\n params.layers = 'show:' + this.options.layers.join(',');\n }\n\n if(this.options.layerDefs){\n params.layerDefs = JSON.stringify(this.options.layerDefs);\n }\n\n if(this.options.timeOptions){\n params.timeOptions = JSON.stringify(this.options.timeOptions);\n }\n\n if(this.options.from && this.options.to){\n params.time = this.options.from.valueOf() + ',' + this.options.to.valueOf();\n }\n\n if(this._service.options.token) {\n params.token = this._service.options.token;\n }\n\n return params;\n },\n\n _requestExport: function (params, bounds) {\n if(this.options.f === 'json'){\n this._service.get('export', params, function(error, response){\n this._renderImage(response.href, bounds);\n }, this);\n } else {\n params.f = 'image';\n this._renderImage(this.options.url + 'export' + L.Util.getParamString(params), bounds);\n }\n }\n});\n\nEsriLeaflet.DynamicMapLayer = EsriLeaflet.Layers.DynamicMapLayer;\n\nEsriLeaflet.Layers.dynamicMapLayer = function(url, options){\n return new EsriLeaflet.Layers.DynamicMapLayer(url, options);\n};\n\nEsriLeaflet.dynamicMapLayer = function(url, options){\n return new EsriLeaflet.Layers.DynamicMapLayer(url, options);\n};","EsriLeaflet.Layers.ImageMapLayer = EsriLeaflet.Layers.RasterLayer.extend({\n\n options: {\n updateInterval: 150,\n format: 'jpgpng',\n transparent: true\n },\n\n query: function(){\n return this._service.query();\n },\n\n identify: function(){\n return this._service.identify();\n },\n\n initialize: function (url, options) {\n options = options || {};\n options.url = EsriLeaflet.Util.cleanUrl(url);\n this._service = new EsriLeaflet.Services.ImageService(options);\n this._service.on('authenticationrequired requeststart requestend requesterror requestsuccess', this._propagateEvent, this);\n L.Util.setOptions(this, options);\n },\n\n setPixelType: function (pixelType) {\n this.options.pixelType = pixelType;\n this._update();\n return this;\n },\n\n getPixelType: function () {\n return this.options.pixelType;\n },\n\n setBandIds: function (bandIds) {\n if (L.Util.isArray(bandIds)) {\n this.options.bandIds = bandIds.join(',');\n } else {\n this.options.bandIds = bandIds.toString();\n }\n this._update();\n return this;\n },\n\n getBandIds: function () {\n return this.options.bandIds;\n },\n\n setNoData: function (noData, noDataInterpretation) {\n if (L.Util.isArray(noData)) {\n this.options.noData = noData.join(',');\n } else {\n this.options.noData = noData.toString();\n }\n if (noDataInterpretation) {\n this.options.noDataInterpretation = noDataInterpretation;\n }\n this._update();\n return this;\n },\n\n getNoData: function () {\n return this.options.noData;\n },\n\n getNoDataInterpretation: function () {\n return this.options.noDataInterpretation;\n },\n\n setRenderingRule: function(renderingRule) {\n this.options.renderingRule = renderingRule;\n this._update();\n },\n\n getRenderingRule: function() {\n return this.options.renderingRule;\n },\n\n setMosaicRule: function(mosaicRule) {\n this.options.mosaicRule = mosaicRule;\n this._update();\n },\n\n getMosaicRule: function() {\n return this.options.mosaicRule;\n },\n\n _getPopupData: function(e){\n var callback = L.Util.bind(function(error, results, response) {\n setTimeout(L.Util.bind(function(){\n this._renderPopup(e.latlng, error, results, response);\n }, this), 300);\n }, this);\n\n var identifyRequest = this.identify().at(e.latlng);\n\n // set mosaic rule for identify task if it is set for layer\n if (this.options.mosaicRule) {\n identifyRequest.setMosaicRule(this.options.mosaicRule);\n // @TODO: force return catalog items too?\n }\n\n // @TODO: set rendering rule? Not sure,\n // sometimes you want raw pixel values\n // if (this.options.renderingRule) {\n // identifyRequest.setRenderingRule(this.options.renderingRule);\n // }\n\n identifyRequest.run(callback);\n\n // set the flags to show the popup\n this._shouldRenderPopup = true;\n this._lastClick = e.latlng;\n },\n\n _buildExportParams: function () {\n var bounds = this._map.getBounds();\n var size = this._map.getSize();\n var ne = this._map.options.crs.project(bounds._northEast);\n var sw = this._map.options.crs.project(bounds._southWest);\n\n var params = {\n bbox: [sw.x, sw.y, ne.x, ne.y].join(','),\n size: size.x + ',' + size.y,\n format: this.options.format,\n transparent: this.options.transparent,\n bboxSR: this.options.bboxSR,\n imageSR: this.options.imageSR\n };\n\n if (this.options.from && this.options.to) {\n params.time = this.options.from.valueOf() + ',' + this.options.to.valueOf();\n }\n\n if (this.options.pixelType) {\n params.pixelType = this.options.pixelType;\n }\n\n if (this.options.interpolation) {\n params.interpolation = this.options.interpolation;\n }\n\n if (this.options.compressionQuality) {\n params.compressionQuality = this.options.compressionQuality;\n }\n\n if (this.options.bandIds) {\n params.bandIds = this.options.bandIds;\n }\n\n if (this.options.noData) {\n params.noData = this.options.noData;\n }\n\n if (this.options.noDataInterpretation) {\n params.noDataInterpretation = this.options.noDataInterpretation;\n }\n\n if (this._service.options.token) {\n params.token = this._service.options.token;\n }\n\n if(this.options.renderingRule) {\n params.renderingRule = JSON.stringify(this.options.renderingRule);\n }\n\n if(this.options.mosaicRule) {\n params.mosaicRule = JSON.stringify(this.options.mosaicRule);\n }\n\n return params;\n },\n\n _requestExport: function (params, bounds) {\n if (this.options.f === 'json') {\n this._service.get('exportImage', params, function(error, response){\n this._renderImage(response.href, bounds);\n }, this);\n } else {\n params.f = 'image';\n this._renderImage(this.options.url + 'exportImage' + L.Util.getParamString(params), bounds);\n }\n }\n});\n\nEsriLeaflet.ImageMapLayer = EsriLeaflet.Layers.ImageMapLayer;\n\nEsriLeaflet.Layers.imageMapLayer = function (url, options) {\n return new EsriLeaflet.Layers.ImageMapLayer(url, options);\n};\n\nEsriLeaflet.imageMapLayer = function (url, options) {\n return new EsriLeaflet.Layers.ImageMapLayer(url, options);\n};\n","EsriLeaflet.Layers.TiledMapLayer = L.TileLayer.extend({\n initialize: function(url, options){\n options = options || {};\n options.url = EsriLeaflet.Util.cleanUrl(url);\n options = L.Util.setOptions(this, options);\n\n // set the urls\n //this.url = L.esri.Util.cleanUrl(url);\n this.tileUrl = L.esri.Util.cleanUrl(url) + 'tile/{z}/{y}/{x}';\n this._service = new L.esri.Services.MapService(options);\n this._service.on('authenticationrequired requeststart requestend requesterror requestsuccess', this._propagateEvent, this);\n\n //if this is looking at the AGO tiles subdomain insert the subdomain placeholder\n if(this.tileUrl.match('://tiles.arcgisonline.com')){\n this.tileUrl = this.tileUrl.replace('://tiles.arcgisonline.com', '://tiles{s}.arcgisonline.com');\n options.subdomains = ['1', '2', '3', '4'];\n }\n\n if(this.options.token) {\n this.tileUrl += ('?token=' + this.options.token);\n }\n\n // init layer by calling TileLayers initialize method\n L.TileLayer.prototype.initialize.call(this, this.tileUrl, options);\n },\n\n metadata: function(callback, context){\n this._service.metadata(callback, context);\n return this;\n },\n\n identify: function(){\n return this._service.identify();\n },\n\n authenticate: function(token){\n var tokenQs = '?token=' + token;\n this.tileUrl = (this.options.token) ? this.tileUrl.replace(/\\?token=(.+)/g, tokenQs) : this.tileUrl + tokenQs;\n this.options.token = token;\n this._service.authenticate(token);\n return this;\n },\n\n // from https://github.com/Leaflet/Leaflet/blob/v0.7.2/src/layer/FeatureGroup.js\n // @TODO remove at Leaflet 0.8\n _propagateEvent: function (e) {\n e = L.extend({\n layer: e.target,\n target: this\n }, e);\n this.fire(e.type, e);\n }\n});\n\nL.esri.TiledMapLayer = L.esri.Layers.tiledMapLayer;\n\nL.esri.Layers.tiledMapLayer = function(url, options){\n return new L.esri.Layers.TiledMapLayer(url, options);\n};\n\nL.esri.tiledMapLayer = function(url, options){\n return new L.esri.Layers.TiledMapLayer(url, options);\n};","EsriLeaflet.Layers.FeatureGrid = L.Class.extend({\n\n includes: L.Mixin.Events,\n\n options: {\n cellSize: 512,\n updateInterval: 150\n },\n\n initialize: function (options) {\n options = L.setOptions(this, options);\n },\n\n onAdd: function (map) {\n this._map = map;\n this._update = L.Util.limitExecByInterval(this._update, this.options.updateInterval, this);\n\n // @TODO remove for leaflet 0.8\n this._map.addEventListener(this.getEvents(), this);\n\n this._reset();\n this._update();\n },\n\n onRemove: function(){\n this._map.removeEventListener(this.getEvents(), this);\n this._removeCells();\n },\n\n getEvents: function () {\n var events = {\n viewreset: this._reset,\n moveend: this._update,\n zoomend : this._onZoom\n };\n\n return events;\n },\n\n addTo: function(map){\n map.addLayer(this);\n return this;\n },\n\n removeFrom: function(map){\n map.removeLayer(this);\n return this;\n },\n\n _onZoom : function () {\n var zoom = this._map.getZoom();\n\n if (zoom > this.options.maxZoom ||\n zoom < this.options.minZoom) {\n this.removeFrom(this._map);\n this._map.addEventListener('zoomend', this.getEvents().zoomend, this);\n } else if (!this._map.hasLayer(this)) {\n this._map.removeEventListener('zoomend', this.getEvents().zoomend, this);\n this.addTo(this._map);\n }\n\n },\n\n _reset: function () {\n this._removeCells();\n\n this._cells = {};\n this._activeCells = {};\n this._cellsToLoad = 0;\n this._cellsTotal = 0;\n\n // @TODO enable at Leaflet 0.8\n // this._cellNumBounds = this._getCellNumBounds();\n\n this._resetWrap();\n },\n\n _resetWrap: function () {\n var map = this._map,\n crs = map.options.crs;\n\n if (crs.infinite) { return; }\n\n var cellSize = this._getCellSize();\n\n if (crs.wrapLng) {\n this._wrapLng = [\n Math.floor(map.project([0, crs.wrapLng[0]]).x / cellSize),\n Math.ceil(map.project([0, crs.wrapLng[1]]).x / cellSize)\n ];\n }\n\n if (crs.wrapLat) {\n this._wrapLat = [\n Math.floor(map.project([crs.wrapLat[0], 0]).y / cellSize),\n Math.ceil(map.project([crs.wrapLat[1], 0]).y / cellSize)\n ];\n }\n },\n\n _getCellSize: function () {\n return this.options.cellSize;\n },\n\n _update: function () {\n if (!this._map) { return; }\n\n var bounds = this._map.getPixelBounds(),\n zoom = this._map.getZoom(),\n cellSize = this._getCellSize(),\n cellPadding = [cellSize/2,cellSize/2];\n // cellPadding = [0,0]\n\n if (zoom > this.options.maxZoom ||\n zoom < this.options.minZoom) { return; }\n\n // cell coordinates range for the current view\n var topLeft = bounds.min.subtract(cellPadding).divideBy(cellSize).floor();\n topLeft.x = Math.max(topLeft.x, 0);\n topLeft.y = Math.max(topLeft.y, 0);\n\n var cellBounds = L.bounds(topLeft, bounds.max.add(cellPadding).divideBy(cellSize).floor());\n\n // remove any present cells that are off the specified bounds\n this._removeOtherCells(cellBounds);\n this._addCells(cellBounds);\n },\n\n _addCells: function (bounds) {\n var queue = [],\n center = bounds.getCenter(),\n zoom = this._map.getZoom();\n\n var j, i, coords;\n // create a queue of coordinates to load cells from\n for (j = bounds.min.y; j <= bounds.max.y; j++) {\n for (i = bounds.min.x; i <= bounds.max.x; i++) {\n coords = new L.Point(i, j);\n coords.z = zoom;\n\n // @TODO enable at Leaflet 0.8\n // if (this._isValidCell(coords)) {\n // queue.push(coords);\n // }\n\n queue.push(coords);\n }\n }\n var cellsToLoad = queue.length;\n\n if (cellsToLoad === 0) { return; }\n\n this._cellsToLoad += cellsToLoad;\n this._cellsTotal += cellsToLoad;\n\n // sort cell queue to load cells in order of their distance to center\n queue.sort(function (a, b) {\n return a.distanceTo(center) - b.distanceTo(center);\n });\n\n for (i = 0; i < cellsToLoad; i++) {\n this._addCell(queue[i]);\n }\n },\n\n // @TODO enable at Leaflet 0.8\n // _isValidCell: function (coords) {\n // var crs = this._map.options.crs;\n\n // if (!crs.infinite) {\n // // don't load cell if it's out of bounds and not wrapped\n // var bounds = this._cellNumBounds;\n // if (\n // (!crs.wrapLng && (coords.x < bounds.min.x || coords.x > bounds.max.x)) ||\n // (!crs.wrapLat && (coords.y < bounds.min.y || coords.y > bounds.max.y))\n // ) {\n // return false;\n // }\n // }\n\n // if (!this.options.bounds) {\n // return true;\n // }\n\n // // don't load cell if it doesn't intersect the bounds in options\n // var cellBounds = this._cellCoordsToBounds(coords);\n // return L.latLngBounds(this.options.bounds).intersects(cellBounds);\n // },\n\n // converts cell coordinates to its geographical bounds\n _cellCoordsToBounds: function (coords) {\n var map = this._map,\n cellSize = this.options.cellSize,\n\n nwPoint = coords.multiplyBy(cellSize),\n sePoint = nwPoint.add([cellSize, cellSize]),\n\n // @TODO for Leaflet 0.8\n // nw = map.wrapLatLng(map.unproject(nwPoint, coords.z)),\n // se = map.wrapLatLng(map.unproject(sePoint, coords.z));\n\n nw = map.unproject(nwPoint, coords.z).wrap(),\n se = map.unproject(sePoint, coords.z).wrap();\n\n return new L.LatLngBounds(nw, se);\n },\n\n // converts cell coordinates to key for the cell cache\n _cellCoordsToKey: function (coords) {\n return coords.x + ':' + coords.y;\n },\n\n // converts cell cache key to coordiantes\n _keyToCellCoords: function (key) {\n var kArr = key.split(':'),\n x = parseInt(kArr[0], 10),\n y = parseInt(kArr[1], 10);\n\n return new L.Point(x, y);\n },\n\n // remove any present cells that are off the specified bounds\n _removeOtherCells: function (bounds) {\n for (var key in this._cells) {\n if (!bounds.contains(this._keyToCellCoords(key))) {\n this._removeCell(key);\n }\n }\n },\n\n _removeCell: function (key) {\n var cell = this._activeCells[key];\n if(cell){\n delete this._activeCells[key];\n\n if (this.cellLeave) {\n this.cellLeave(cell.bounds, cell.coords);\n }\n\n this.fire('cellleave', {\n bounds: cell.bounds,\n coords: cell.coords\n });\n }\n },\n\n _removeCells: function(){\n for (var key in this._cells) {\n var bounds = this._cells[key].bounds;\n var coords = this._cells[key].coords;\n\n if (this.cellLeave) {\n this.cellLeave(bounds, coords);\n }\n\n this.fire('cellleave', {\n bounds: bounds,\n coords: coords\n });\n }\n },\n\n _addCell: function (coords) {\n\n // wrap cell coords if necessary (depending on CRS)\n this._wrapCoords(coords);\n\n // generate the cell key\n var key = this._cellCoordsToKey(coords);\n\n // get the cell from the cache\n var cell = this._cells[key];\n // if this cell should be shown as isnt active yet (enter)\n\n if (cell && !this._activeCells[key]) {\n if (this.cellEnter) {\n this.cellEnter(cell.bounds, coords);\n }\n\n this.fire('cellenter', {\n bounds: cell.bounds,\n coords: coords\n });\n\n this._activeCells[key] = cell;\n }\n\n // if we dont have this cell in the cache yet (create)\n if (!cell) {\n cell = {\n coords: coords,\n bounds: this._cellCoordsToBounds(coords)\n };\n\n this._cells[key] = cell;\n this._activeCells[key] = cell;\n\n if(this.createCell){\n this.createCell(cell.bounds, coords);\n }\n\n this.fire('cellcreate', {\n bounds: cell.bounds,\n coords: coords\n });\n }\n },\n\n _wrapCoords: function (coords) {\n coords.x = this._wrapLng ? L.Util.wrapNum(coords.x, this._wrapLng) : coords.x;\n coords.y = this._wrapLat ? L.Util.wrapNum(coords.y, this._wrapLat) : coords.y;\n }\n\n // get the global cell coordinates range for the current zoom\n // @TODO enable at Leaflet 0.8\n // _getCellNumBounds: function () {\n // // @TODO for Leaflet 0.8\n // // var bounds = this._map.getPixelWorldBounds(),\n // // size = this._getCellSize();\n // //\n // // return bounds ? L.bounds(\n // // bounds.min.divideBy(size).floor(),\n // // bounds.max.divideBy(size).ceil().subtract([1, 1])) : null;\n // }\n\n});","(function(EsriLeaflet){\n\n EsriLeaflet.Layers.FeatureManager = EsriLeaflet.Layers.FeatureGrid.extend({\n\n /**\n * Options\n */\n\n options: {\n where: '1=1',\n fields: ['*'],\n from: false,\n to: false,\n timeField: false,\n timeFilterMode: 'server',\n simplifyFactor: 0,\n precision: 6\n },\n\n /**\n * Constructor\n */\n\n initialize: function (url, options) {\n EsriLeaflet.Layers.FeatureGrid.prototype.initialize.call(this, options);\n\n options = options || {};\n options.url = EsriLeaflet.Util.cleanUrl(url);\n options = L.setOptions(this, options);\n\n this._service = new EsriLeaflet.Services.FeatureLayer(options);\n\n //use case insensitive regex to look for common fieldnames used for indexing\n /*global console */\n if (this.options.fields[0] !== '*'){\n var oidCheck = false;\n for (var i = 0; i < this.options.fields.length; i++){\n if (this.options.fields[i].match(/^(OBJECTID|FID|OID|ID)$/i)){\n oidCheck = true;\n }\n }\n if (oidCheck === false && console && console.warn){\n console.warn('no known esriFieldTypeOID field detected in fields Array. Please add an attribute field containing unique IDs to ensure the layer can be drawn correctly.');\n }\n }\n\n // Leaflet 0.8 change to new propagation\n this._service.on('authenticationrequired requeststart requestend requesterror requestsuccess', function (e) {\n e = L.extend({\n target: this\n }, e);\n this.fire(e.type, e);\n }, this);\n\n if(this.options.timeField.start && this.options.timeField.end){\n this._startTimeIndex = new BinarySearchIndex();\n this._endTimeIndex = new BinarySearchIndex();\n } else if(this.options.timeField){\n this._timeIndex = new BinarySearchIndex();\n }\n\n this._cache = {};\n this._currentSnapshot = []; // cache of what layers should be active\n this._activeRequests = 0;\n this._pendingRequests = [];\n },\n\n /**\n * Layer Interface\n */\n\n onAdd: function(map){\n return EsriLeaflet.Layers.FeatureGrid.prototype.onAdd.call(this, map);\n },\n\n onRemove: function(map){\n return EsriLeaflet.Layers.FeatureGrid.prototype.onRemove.call(this, map);\n },\n\n getAttribution: function () {\n return this.options.attribution;\n },\n\n /**\n * Feature Managment\n */\n\n createCell: function(bounds, coords){\n this._requestFeatures(bounds, coords);\n },\n\n _requestFeatures: function(bounds, coords, callback){\n this._activeRequests++;\n\n // our first active request fires loading\n if(this._activeRequests === 1){\n this.fire('loading', {\n bounds: bounds\n });\n }\n\n return this._buildQuery(bounds).run(function(error, featureCollection, response){\n if(response && response.exceededTransferLimit){\n this.fire('drawlimitexceeded');\n }\n\n //deincriment the request counter\n this._activeRequests--;\n\n if(!error && featureCollection.features.length){\n // schedule adding features until the next animation frame\n EsriLeaflet.Util.requestAnimationFrame(L.Util.bind(function(){\n this._addFeatures(featureCollection.features, coords);\n }, this));\n }\n\n if(callback){\n callback.call(this, error, featureCollection);\n }\n\n // if there are no more active requests fire a load event for this view\n if(this._activeRequests <= 0){\n this.fire('load', {\n bounds: bounds\n });\n }\n }, this);\n },\n\n _cacheKey: function (coords){\n return coords.z + ':' + coords.x + ':' +coords.y;\n },\n\n _addFeatures: function(features, coords){\n var key = this._cacheKey(coords);\n this._cache[key] = this._cache[key] || [];\n\n for (var i = features.length - 1; i >= 0; i--) {\n var id = features[i].id;\n this._currentSnapshot.push(id);\n this._cache[key].push(id);\n }\n\n if(this.options.timeField){\n this._buildTimeIndexes(features);\n }\n\n var zoom = this._map.getZoom();\n\n if (zoom > this.options.maxZoom ||\n zoom < this.options.minZoom) { return; }\n\n this.createLayers(features);\n },\n\n _buildQuery: function(bounds){\n var query = this._service.query().intersects(bounds).where(this.options.where).fields(this.options.fields).precision(this.options.precision);\n\n if(this.options.simplifyFactor){\n query.simplify(this._map, this.options.simplifyFactor);\n }\n\n if(this.options.timeFilterMode === 'server' && this.options.from && this.options.to){\n query.between(this.options.from, this.options.to);\n }\n\n return query;\n },\n\n /**\n * Where Methods\n */\n\n setWhere: function(where, callback, context){\n\n this.options.where = (where && where.length) ? where : '1=1';\n\n var oldSnapshot = [];\n var newShapshot = [];\n var pendingRequests = 0;\n var requestError = null;\n var requestCallback = L.Util.bind(function(error, featureCollection){\n if(error){\n requestError = error;\n }\n\n if(featureCollection){\n for (var i = featureCollection.features.length - 1; i >= 0; i--) {\n newShapshot.push(featureCollection.features[i].id);\n }\n }\n\n pendingRequests--;\n\n if(pendingRequests <= 0){\n this._currentSnapshot = newShapshot;\n // schedule adding features until the next animation frame\n EsriLeaflet.Util.requestAnimationFrame(L.Util.bind(function(){\n this.removeLayers(oldSnapshot);\n this.addLayers(newShapshot);\n if(callback) {\n callback.call(context, requestError);\n }\n }, this));\n\n }\n }, this);\n\n for (var i = this._currentSnapshot.length - 1; i >= 0; i--) {\n oldSnapshot.push(this._currentSnapshot[i]);\n }\n\n for(var key in this._activeCells){\n pendingRequests++;\n var coords = this._keyToCellCoords(key);\n var bounds = this._cellCoordsToBounds(coords);\n this._requestFeatures(bounds, key, requestCallback);\n }\n\n return this;\n },\n\n getWhere: function(){\n return this.options.where;\n },\n\n /**\n * Time Range Methods\n */\n\n getTimeRange: function(){\n return [this.options.from, this.options.to];\n },\n\n setTimeRange: function(from, to, callback, context){\n var oldFrom = this.options.from;\n var oldTo = this.options.to;\n var pendingRequests = 0;\n var requestError = null;\n var requestCallback = L.Util.bind(function(error){\n if(error){\n requestError = error;\n }\n this._filterExistingFeatures(oldFrom, oldTo, from, to);\n\n pendingRequests--;\n\n if(callback && pendingRequests <= 0){\n callback.call(context, requestError);\n }\n }, this);\n\n this.options.from = from;\n this.options.to = to;\n\n this._filterExistingFeatures(oldFrom, oldTo, from, to);\n\n if(this.options.timeFilterMode === 'server') {\n for(var key in this._activeCells){\n pendingRequests++;\n var coords = this._keyToCellCoords(key);\n var bounds = this._cellCoordsToBounds(coords);\n this._requestFeatures(bounds, key, requestCallback);\n }\n }\n },\n\n refresh: function(){\n for(var key in this._activeCells){\n var coords = this._keyToCellCoords(key);\n var bounds = this._cellCoordsToBounds(coords);\n this._requestFeatures(bounds, key);\n }\n },\n\n _filterExistingFeatures: function (oldFrom, oldTo, newFrom, newTo) {\n var layersToRemove = (oldFrom && oldTo) ? this._getFeaturesInTimeRange(oldFrom, oldTo) : this._currentSnapshot;\n var layersToAdd = this._getFeaturesInTimeRange(newFrom, newTo);\n\n if(layersToAdd.indexOf){\n for (var i = 0; i < layersToAdd.length; i++) {\n var shouldRemoveLayer = layersToRemove.indexOf(layersToAdd[i]);\n if(shouldRemoveLayer >= 0){\n layersToRemove.splice(shouldRemoveLayer, 1);\n }\n }\n }\n\n // schedule adding features until the next animation frame\n EsriLeaflet.Util.requestAnimationFrame(L.Util.bind(function(){\n this.removeLayers(layersToRemove);\n this.addLayers(layersToAdd);\n }, this));\n },\n\n _getFeaturesInTimeRange: function(start, end){\n var ids = [];\n var search;\n\n if(this.options.timeField.start && this.options.timeField.end){\n var startTimes = this._startTimeIndex.between(start, end);\n var endTimes = this._endTimeIndex.between(start, end);\n search = startTimes.concat(endTimes);\n } else {\n search = this._timeIndex.between(start, end);\n }\n\n for (var i = search.length - 1; i >= 0; i--) {\n ids.push(search[i].id);\n }\n\n return ids;\n },\n\n _buildTimeIndexes: function(geojson){\n var i;\n var feature;\n if(this.options.timeField.start && this.options.timeField.end){\n var startTimeEntries = [];\n var endTimeEntries = [];\n for (i = geojson.length - 1; i >= 0; i--) {\n feature = geojson[i];\n startTimeEntries.push( {\n id: feature.id,\n value: new Date(feature.properties[this.options.timeField.start])\n });\n endTimeEntries.push( {\n id: feature.id,\n value: new Date(feature.properties[this.options.timeField.end])\n });\n }\n this._startTimeIndex.bulkAdd(startTimeEntries);\n this._endTimeIndex.bulkAdd(endTimeEntries);\n } else {\n var timeEntries = [];\n for (i = geojson.length - 1; i >= 0; i--) {\n feature = geojson[i];\n timeEntries.push( {\n id: feature.id,\n value: new Date(feature.properties[this.options.timeField])\n });\n }\n\n this._timeIndex.bulkAdd(timeEntries);\n }\n },\n\n _featureWithinTimeRange: function(feature){\n if(!this.options.from || !this.options.to){\n return true;\n }\n\n var from = +this.options.from.valueOf();\n var to = +this.options.to.valueOf();\n\n if(typeof this.options.timeField === 'string'){\n var date = +feature.properties[this.options.timeField];\n return (date >= from) && (date <= to);\n }\n\n if(this.options.timeField.start && this.options.timeField.end){\n var startDate = +feature.properties[this.options.timeField.start];\n var endDate = +feature.properties[this.options.timeField.end];\n return ((startDate >= from) && (startDate <= to)) || ((endDate >= from) && (endDate <= to));\n }\n },\n\n /**\n * Service Methods\n */\n\n authenticate: function(token){\n this._service.authenticate(token);\n return this;\n },\n\n metadata: function(callback, context){\n this._service.metadata(callback, context);\n return this;\n },\n\n query: function(){\n return this._service.query();\n },\n\n _getMetadata: function(callback, context){\n if(this._metadata){\n var error;\n callback(context, error, this._metadata);\n } else {\n this.metadata(L.Util.bind(function(error, response) {\n this._metadata = response;\n callback(context, error, this._metadata);\n }, this));\n }\n },\n\n addFeature: function(feature, callback, context){\n //still need to pass 'undefined' as a placeholder, not sure how to fix\n this._getMetadata(L.Util.bind(function(undefined, error, metadata){\n this._service.addFeature(feature, L.Util.bind(function(error, response){\n if(!error){\n // assign ID from result to appropriate objectid field from service metadata\n feature.properties[metadata.objectIdField] = response.objectId;\n\n // we also need to update the geojson id for createLayers() to function\n feature.id = response.objectId;\n this.createLayers([feature]);\n }\n\n if(callback){\n callback.call(context, error, response);\n }\n }, this));\n }, this));\n },\n\n updateFeature: function(feature, callback, context){\n this._service.updateFeature(feature, function(error, response){\n if(!error){\n this.removeLayers([feature.id], true);\n this.createLayers([feature]);\n }\n if(callback){\n callback.call(context, error, response);\n }\n }, this);\n },\n\n deleteFeature: function(id, callback, context){\n this._service.deleteFeature(id, function(error, response){\n if(!error && response.objectId){\n this.removeLayers([response.objectId], true);\n }\n if(callback){\n callback.call(context, error, response);\n }\n }, this);\n },\n\n deleteFeatures: function(ids, callback, context){\n return this._service.deleteFeatures(ids, function(error, response){\n if(!error && response.length > 0){\n for (var i=0; i<response.length; i++){\n this.removeLayers([response[i].objectId], true);\n }\n }\n if(callback){\n callback.call(context, error, response);\n }\n }, this);\n }\n\n });\n\n /**\n * Temporal Binary Search Index\n */\n\n function BinarySearchIndex(values) {\n this.values = values || [];\n }\n\n BinarySearchIndex.prototype._query = function(query){\n var minIndex = 0;\n var maxIndex = this.values.length - 1;\n var currentIndex;\n var currentElement;\n var resultIndex;\n\n while (minIndex <= maxIndex) {\n resultIndex = currentIndex = (minIndex + maxIndex) / 2 | 0;\n currentElement = this.values[Math.round(currentIndex)];\n if (+currentElement.value < +query) {\n minIndex = currentIndex + 1;\n } else if (+currentElement.value > +query) {\n maxIndex = currentIndex - 1;\n } else {\n return currentIndex;\n }\n }\n\n return ~maxIndex;\n };\n\n BinarySearchIndex.prototype.sort = function(){\n this.values.sort(function(a, b) {\n return +b.value - +a.value;\n }).reverse();\n this.dirty = false;\n };\n\n BinarySearchIndex.prototype.between = function(start, end){\n if(this.dirty){\n this.sort();\n }\n\n var startIndex = this._query(start);\n var endIndex = this._query(end);\n\n if(startIndex === 0 && endIndex === 0){\n return [];\n }\n\n startIndex = Math.abs(startIndex);\n endIndex = (endIndex < 0) ? Math.abs(endIndex): endIndex + 1;\n\n return this.values.slice(startIndex, endIndex);\n };\n\n BinarySearchIndex.prototype.bulkAdd = function(items){\n this.dirty = true;\n this.values = this.values.concat(items);\n };\n\n})(EsriLeaflet);","EsriLeaflet.Layers.FeatureLayer = EsriLeaflet.Layers.FeatureManager.extend({\n\n statics: {\n EVENTS: 'click dblclick mouseover mouseout mousemove contextmenu popupopen popupclose'\n },\n\n options: {\n cacheLayers: true\n },\n\n /**\n * Constructor\n */\n\n initialize: function (url, options) {\n EsriLeaflet.Layers.FeatureManager.prototype.initialize.call(this, url, options);\n\n options = L.setOptions(this, options);\n\n this._layers = {};\n this._leafletIds = {};\n this._key = 'c'+(Math.random() * 1e9).toString(36).replace('.', '_');\n },\n\n /**\n * Layer Interface\n */\n\n onAdd: function(map){\n map.on('zoomstart zoomend', function(e){\n this._zooming = (e.type === 'zoomstart');\n }, this);\n return EsriLeaflet.Layers.FeatureManager.prototype.onAdd.call(this, map);\n },\n\n onRemove: function(map){\n for (var i in this._layers) {\n map.removeLayer(this._layers[i]);\n }\n\n return EsriLeaflet.Layers.FeatureManager.prototype.onRemove.call(this, map);\n },\n\n createNewLayer: function(geojson){\n // @TODO Leaflet 0.8\n //newLayer = L.GeoJSON.geometryToLayer(geojson, this.options);\n return L.GeoJSON.geometryToLayer(geojson, this.options.pointToLayer, L.GeoJSON.coordsToLatLng, this.options);\n },\n\n _updateLayerGeometry: function(layer, geojson){\n // convert the geojson coordinates into a Leaflet LatLng array/nested arrays\n // pass it to setLatLngs to update layer geometries\n var latlngs = [];\n var coordsToLatLng = this.options.coordsToLatLng || L.GeoJSON.coordsToLatLng;\n\n switch(geojson.geometry.type){\n case 'LineString':\n latlngs = L.GeoJSON.coordsToLatLngs(geojson.geometry.coordinates, 0, coordsToLatLng);\n layer.setLatLngs(latlngs);\n break;\n case 'MultiLineString':\n latlngs = L.GeoJSON.coordsToLatLngs(geojson.geometry.coordinates, 1, coordsToLatLng);\n layer.setLatLngs(latlngs);\n break;\n case 'Polygon':\n latlngs = L.GeoJSON.coordsToLatLngs(geojson.geometry.coordinates, 1, coordsToLatLng);\n layer.setLatLngs(latlngs);\n break;\n case 'MultiPolygon':\n latlngs = L.GeoJSON.coordsToLatLngs(geojson.geometry.coordinates, 2, coordsToLatLng);\n layer.setLatLngs(latlngs);\n break;\n }\n },\n\n /**\n * Feature Managment Methods\n */\n\n createLayers: function(features){\n for (var i = features.length - 1; i >= 0; i--) {\n\n var geojson = features[i];\n\n var layer = this._layers[geojson.id];\n var newLayer;\n\n if(layer && !this._map.hasLayer(layer)){\n this._map.addLayer(layer);\n return;\n }\n\n if (layer && layer.setLatLngs) {\n this._updateLayerGeometry(layer, geojson);\n return;\n }\n\n if(!layer){\n newLayer = this.createNewLayer(geojson);\n newLayer.feature = geojson;\n newLayer._originalStyle = this.options.style;\n newLayer._leaflet_id = this._key + '_' + geojson.id;\n\n this._leafletIds[newLayer._leaflet_id] = geojson.id;\n\n // bubble events from layers to this\n // @TODO Leaflet 0.8\n // newLayer.addEventParent(this);\n\n newLayer.on(EsriLeaflet.Layers.FeatureLayer.EVENTS, this._propagateEvent, this);\n\n // bind a popup if we have one\n if(this._popup && newLayer.bindPopup){\n newLayer.bindPopup(this._popup(newLayer.feature, newLayer), this._popupOptions);\n }\n\n if(this.options.onEachFeature){\n this.options.onEachFeature(newLayer.feature, newLayer);\n }\n\n // cache the layer\n this._layers[newLayer.feature.id] = newLayer;\n\n // style the layer\n this.resetStyle(newLayer.feature.id);\n\n this.fire('createfeature', {\n feature: newLayer.feature\n });\n\n // add the layer if it is within the time bounds or our layer is not time enabled\n if(!this.options.timeField || (this.options.timeField && this._featureWithinTimeRange(geojson)) ){\n this._map.addLayer(newLayer);\n }\n }\n }\n },\n\n addLayers: function(ids){\n for (var i = ids.length - 1; i >= 0; i--) {\n var layer = this._layers[ids[i]];\n if(layer){\n this.fire('addfeature', {\n feature: layer.feature\n });\n this._map.addLayer(layer);\n }\n }\n },\n\n removeLayers: function(ids, permanent){\n for (var i = ids.length - 1; i >= 0; i--) {\n var id = ids[i];\n var layer = this._layers[id];\n if(layer){\n this.fire('removefeature', {\n feature: layer.feature,\n permanent: permanent\n });\n this._map.removeLayer(layer);\n }\n if(layer && permanent){\n delete this._layers[id];\n }\n }\n },\n\n cellEnter: function(bounds, coords){\n if(!this._zooming){\n EsriLeaflet.Util.requestAnimationFrame(L.Util.bind(function(){\n var cacheKey = this._cacheKey(coords);\n var cellKey = this._cellCoordsToKey(coords);\n var layers = this._cache[cacheKey];\n if(this._activeCells[cellKey] && layers){\n this.addLayers(layers);\n }\n }, this));\n }\n },\n\n cellLeave: function(bounds, coords){\n if(!this._zooming){\n EsriLeaflet.Util.requestAnimationFrame(L.Util.bind(function(){\n var cacheKey = this._cacheKey(coords);\n var cellKey = this._cellCoordsToKey(coords);\n var layers = this._cache[cacheKey];\n var mapBounds = this._map.getBounds();\n if(!this._activeCells[cellKey] && layers){\n var removable = true;\n\n for (var i = 0; i < layers.length; i++) {\n var layer = this._layers[layers[i]];\n if(layer && layer.getBounds && mapBounds.intersects(layer.getBounds())){\n removable = false;\n }\n }\n\n if(removable){\n this.removeLayers(layers, !this.options.cacheLayers);\n }\n\n if(!this.options.cacheLayers && removable){\n delete this._cache[cacheKey];\n delete this._cells[cellKey];\n delete this._activeCells[cellKey];\n }\n }\n }, this));\n }\n },\n\n /**\n * Styling Methods\n */\n\n resetStyle: function (id) {\n var layer = this._layers[id];\n\n if(layer){\n this.setFeatureStyle(layer.feature.id, layer._originalStyle);\n }\n\n return this;\n },\n\n setStyle: function (style) {\n this.options.style = style;\n this.eachFeature(function (layer) {\n this.setFeatureStyle(layer.feature.id, style);\n }, this);\n return this;\n },\n\n setFeatureStyle: function (id, style) {\n var layer = this._layers[id];\n\n if (typeof style === 'function') {\n style = style(layer.feature);\n }\n\n if (!style && !layer.defaultOptions) {\n style = L.Path.prototype.options;\n style.fill = true; //not set by default\n }\n\n if (layer && layer.setStyle) {\n layer.setStyle(style);\n }\n\n return this;\n },\n\n /**\n * Popup Methods\n */\n\n bindPopup: function (fn, options) {\n this._popup = fn;\n this._popupOptions = options;\n for (var i in this._layers) {\n var layer = this._layers[i];\n var popupContent = this._popup(layer.feature, layer);\n layer.bindPopup(popupContent, options);\n }\n return this;\n },\n\n unbindPopup: function () {\n this._popup = false;\n for (var i in this._layers) {\n var layer = this._layers[i];\n if (layer.unbindPopup) {\n layer.unbindPopup();\n } else if (layer.getLayers) {\n var groupLayers = layer.getLayers();\n for (var j in groupLayers) {\n var gLayer = groupLayers[j];\n gLayer.unbindPopup();\n }\n }\n }\n return this;\n },\n\n /**\n * Utility Methods\n */\n\n eachFeature: function (fn, context) {\n for (var i in this._layers) {\n fn.call(context, this._layers[i]);\n }\n return this;\n },\n\n getFeature: function (id) {\n return this._layers[id];\n },\n\n // from https://github.com/Leaflet/Leaflet/blob/v0.7.2/src/layer/FeatureGroup.js\n // @TODO remove at Leaflet 0.8\n _propagateEvent: function (e) {\n e.layer = this._layers[this._leafletIds[e.target._leaflet_id]];\n e.target = this;\n this.fire(e.type, e);\n }\n});\n\nEsriLeaflet.FeatureLayer = EsriLeaflet.Layers.FeatureLayer;\n\nEsriLeaflet.Layers.featureLayer = function(url, options){\n return new EsriLeaflet.Layers.FeatureLayer(url, options);\n};\n\nEsriLeaflet.featureLayer = function(url, options){\n return new EsriLeaflet.Layers.FeatureLayer(url, options);\n};","EsriLeaflet.Controls.Logo = L.Control.extend({\n options: {\n position: 'bottomright',\n marginTop: 0,\n marginLeft: 0,\n marginBottom: 0,\n marginRight: 0\n },\n\n onAdd: function () {\n var div = L.DomUtil.create('div', 'esri-leaflet-logo');\n div.style.marginTop = this.options.marginTop;\n div.style.marginLeft = this.options.marginLeft;\n div.style.marginBottom = this.options.marginBottom;\n div.style.marginRight = this.options.marginRight;\n div.innerHTML = this._adjustLogo(this._map._size);\n\n this._map.on('resize', function(e){\n div.innerHTML = this._adjustLogo(e.newSize);\n }, this);\n\n return div;\n },\n\n _adjustLogo: function (mapSize) {\n if (mapSize.x <= 600 || mapSize.y <= 600){\n return '<a href=\"https://developers.arcgis.com\" style=\"border: none;\"><img src=\"https://js.arcgis.com/3.13/esri/images/map/logo-sm.png\" alt=\"Powered by Esri\" style=\"border: none;\"></a>';\n }\n else {\n return '<a href=\"https://developers.arcgis.com\" style=\"border: none;\"><img src=\"https://js.arcgis.com/3.13/esri/images/map/logo-med.png\" alt=\"Powered by Esri\" style=\"border: none;\"></a>';\n }\n }\n\n});\n\nEsriLeaflet.Controls.logo = function(options){\n return new L.esri.Controls.Logo(options);\n};\n"]}