New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

esri-leaflet-geocoder

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esri-leaflet-geocoder - npm Package Compare versions

Comparing version 2.0.0-beta.1 to 2.0.0-beta.2

dist/esri-leaflet-geocoder.js.map

4

dist/esri-leaflet-geocoder.js

@@ -1,5 +0,5 @@

/* esri-leaflet-geocoder - v2.0.0-beta.1 - Fri Jul 24 2015 12:30:02 GMT-0700 (PDT)
/* esri-leaflet-geocoder - v2.0.0-beta.2 - Fri Jul 24 2015 13:26:21 GMT-0700 (PDT)
* Copyright (c) 2015 Environmental Systems Research Institute, Inc.
* Apache 2.0 */
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?factory(exports,require("leaflet"),require("esri-leaflet")):typeof define==="function"&&define.amd?define(["exports","leaflet","esri-leaflet"],factory):factory(global.L.esri.Geocoding={},L,L.esri)})(this,function(exports,L,esri_leaflet){"use strict";exports.Geocode=esri_leaflet.Task.extend({path:"find",params:{outSr:4326,forStorage:false,outFields:"*",maxLocations:20},setters:{address:"address",neighborhood:"neighborhood",city:"city",subregion:"subregion",region:"region",postal:"postal",country:"country",text:"text",category:"category",token:"token",key:"magicKey",fields:"outFields",forStorage:"forStorage",maxLocations:"maxLocations"},initialize:function(options){options=options||{};options.url=options.url||exports.WorldGeocodingServiceUrl;esri_leaflet.Task.prototype.initialize.call(this,options)},within:function(bounds){bounds=L.latLngBounds(bounds);this.params.bbox=esri_leaflet.Util.boundsToExtent(bounds);return this},nearby:function(latlng,radius){latlng=L.latLng(latlng);this.params.location=latlng.lng+","+latlng.lat;this.params.distance=Math.min(Math.max(radius,2e3),5e4);return this},run:function(callback,context){this.path=this.params.text?"find":"findAddressCandidates";if(this.path==="findAddressCandidates"&&this.params.bbox){this.params.searchExtent=this.params.bbox;delete this.params.bbox}return this.request(function(error,response){var processor=this.path==="find"?this._processFindResponse:this._processFindAddressCandidatesResponse;var results=!error?processor(response):undefined;callback.call(context,error,{results:results},response)},this)},_processFindResponse:function(response){var results=[];for(var i=0;i<response.locations.length;i++){var location=response.locations[i];var bounds;if(location.extent){bounds=esri_leaflet.Util.extentToBounds(location.extent)}results.push({text:location.name,bounds:bounds,score:location.feature.attributes.Score,latlng:L.latLng(location.feature.geometry.y,location.feature.geometry.x),properties:location.feature.attributes})}return results},_processFindAddressCandidatesResponse:function(response){var results=[];for(var i=0;i<response.candidates.length;i++){var candidate=response.candidates[i];var bounds=esri_leaflet.Util.extentToBounds(candidate.extent);results.push({text:candidate.address,bounds:bounds,score:candidate.score,latlng:L.latLng(candidate.location.y,candidate.location.x),properties:candidate.attributes})}return results}});function geocode(options){return new exports.Geocode(options)}exports.ReverseGeocode=esri_leaflet.Task.extend({path:"reverseGeocode",params:{outSR:4326},setters:{distance:"distance",language:"language"},initialize:function(options){options=options||{};options.url=options.url||exports.WorldGeocodingServiceUrl;esri_leaflet.Task.prototype.initialize.call(this,options)},latlng:function(latlng){latlng=L.latLng(latlng);this.params.location=latlng.lng+","+latlng.lat;return this},run:function(callback,context){return this.request(function(error,response){var result;if(!error){result={latlng:L.latLng(response.location.y,response.location.x),address:response.address}}else{result=undefined}callback.call(context,error,result,response)},this)}});function reverseGeocode(options){return new exports.ReverseGeocode(options)}exports.Suggest=esri_leaflet.Task.extend({path:"suggest",params:{},setters:{text:"text",category:"category"},initialize:function(options){options=options||{};options.url=options.url||exports.WorldGeocodingServiceUrl;esri_leaflet.Task.prototype.initialize.call(this,options)},within:function(bounds){bounds=L.latLngBounds(bounds);bounds=bounds.pad(.5);var center=bounds.getCenter();var ne=bounds.getNorthWest();this.params.location=center.lng+","+center.lat;this.params.distance=Math.min(Math.max(center.distanceTo(ne),2e3),5e4);this.params.searchExtent=esri_leaflet.Util.boundsToExtent(bounds);return this},nearby:function(latlng,radius){latlng=L.latLng(latlng);this.params.location=latlng.lng+","+latlng.lat;this.params.distance=Math.min(Math.max(radius,2e3),5e4);return this},run:function(callback,context){return this.request(function(error,response){callback.call(context,error,response,response)},this)}});function suggest(options){return new exports.Suggest(options)}exports.GeocodeService=esri_leaflet.Service.extend({initialize:function(options){options=options||{};options.url=options.url||exports.WorldGeocodingServiceUrl;esri_leaflet.Service.prototype.initialize.call(this,options);this._confirmSuggestSupport()},geocode:function(){return geocode(this)},reverse:function(){return reverseGeocode(this)},suggest:function(){return suggest(this)},_confirmSuggestSupport:function(){this.metadata(function(error,response){if(error){return}if(response.capabilities.includes("Suggest")){this.options.supportsSuggest=true}else{this.options.supportsSuggest=false}},this)}});function geocodeService(options){return new exports.GeocodeService(options)}exports.Geosearch=L.Control.extend({includes:L.Mixin.Events,options:{position:"topleft",zoomToResult:true,useMapBounds:12,collapseAfterResult:true,expanded:false,forStorage:false,allowMultipleResults:true,placeholder:"Search for places or addresses",title:"Location Search"},initialize:function(options){if(!options||!options.providers||!options.providers.length){throw new Error("You must specificy at least one provider")}this._providers=options.providers;for(var i=0;i<this._providers.length;i++){this._providers[i].addEventParent(this)}this._pendingSuggestions=[];L.Control.prototype.initialize.call(options)},_geocode:function(text,key,provider){var activeRequests=0;var allResults=[];var bounds;var callback=L.Util.bind(function(error,results){activeRequests--;if(error){return}if(results){allResults=allResults.concat(results)}if(activeRequests<=0){bounds=this._boundsFromResults(allResults);this.fire("results",{results:allResults,bounds:bounds,latlng:bounds?bounds.getCenter():undefined,text:text});if(this.options.zoomToResult&&bounds){this._map.fitBounds(bounds)}L.DomUtil.removeClass(this._input,"geocoder-control-loading");this.fire("load");this.clear();this._input.blur()}},this);if(key){activeRequests++;provider.results(text,key,this._searchBounds(),callback)}else{for(var i=0;i<this._providers.length;i++){activeRequests++;this._providers[i].results(text,key,this._searchBounds(),callback)}}},_suggest:function(text){L.DomUtil.addClass(this._input,"geocoder-control-loading");var activeRequests=this._providers.length;var createCallback=L.Util.bind(function(text,provider){return L.Util.bind(function(error,suggestions){if(error){return}var i;activeRequests=activeRequests-1;if(this._input.value<2){this._suggestions.innerHTML="";this._suggestions.style.display="none";return}if(suggestions){for(i=0;i<suggestions.length;i++){suggestions[i].provider=provider}}if(provider._lastRender!==text&&provider.nodes){for(i=0;i<provider.nodes.length;i++){if(provider.nodes[i].parentElement){this._suggestions.removeChild(provider.nodes[i])}}provider.nodes=[]}if(suggestions.length&&this._input.value===text){if(provider.nodes){for(var k=0;k<provider.nodes.length;k++){if(provider.nodes[k].parentElement){this._suggestions.removeChild(provider.nodes[k])}}}provider._lastRender=text;provider.nodes=this._renderSuggestions(suggestions)}if(activeRequests===0){L.DomUtil.removeClass(this._input,"geocoder-control-loading")}},this)},this);this._pendingSuggestions=[];for(var i=0;i<this._providers.length;i++){var provider=this._providers[i];var request=provider.suggestions(text,this._searchBounds(),createCallback(text,provider));this._pendingSuggestions.push(request)}},_searchBounds:function(){if(this.options.useMapBounds===false){return null}if(this.options.useMapBounds===true){return this._map.getBounds()}if(this.options.useMapBounds<=this._map.getZoom()){return this._map.getBounds()}return null},_renderSuggestions:function(suggestions){var currentGroup;this._suggestions.style.display="block";this._suggestions.style.maxHeight=this._map.getSize().y-this._suggestions.offsetTop-this._wrapper.offsetTop-10+"px";var nodes=[];var list;var header;for(var i=0;i<suggestions.length;i++){var suggestion=suggestions[i];if(!header&&this._providers.length>1&&currentGroup!==suggestion.provider.options.label){header=L.DomUtil.create("span","geocoder-control-header",this._suggestions);header.textContent=suggestion.provider.options.label;header.innerText=suggestion.provider.options.label;currentGroup=suggestion.provider.options.label;nodes.push(header)}if(!list){list=L.DomUtil.create("ul","geocoder-control-list",this._suggestions)}var suggestionItem=L.DomUtil.create("li","geocoder-control-suggestion",list);suggestionItem.innerHTML=suggestion.text;suggestionItem.provider=suggestion.provider;suggestionItem["data-magic-key"]=suggestion.magicKey}nodes.push(list);return nodes},_boundsFromResults:function(results){if(!results.length){return}var nullIsland=L.latLngBounds([0,0],[0,0]);var bounds=L.latLngBounds();for(var i=results.length-1;i>=0;i--){var result=results[i];if(result.bounds&&result.bounds.isValid()&&!result.bounds.equals(nullIsland)){bounds.extend(result.bounds)}bounds.extend(result.latlng)}return bounds},clear:function(){this._suggestions.innerHTML="";this._suggestions.style.display="none";this._input.value="";if(this.options.collapseAfterResult){this._input.placeholder="";L.DomUtil.removeClass(this._wrapper,"geocoder-control-expanded")}if(!this._map.scrollWheelZoom.enabled()&&this._map.options.scrollWheelZoom){this._map.scrollWheelZoom.enable()}},getAttribution:function(){var attribution=this.options.attribution;for(var i=0;i<this._providers.length;i++){attribution+=" "+this._providers[i].options.attribution}return attribution},onAdd:function(map){this._map=map;this._wrapper=L.DomUtil.create("div","geocoder-control "+(this.options.expanded?" "+"geocoder-control-expanded":""));this._input=L.DomUtil.create("input","geocoder-control-input leaflet-bar",this._wrapper);this._input.title=this.options.title;this._suggestions=L.DomUtil.create("div","geocoder-control-suggestions leaflet-bar",this._wrapper);L.DomEvent.addListener(this._input,"focus",function(e){this._input.placeholder=this.options.placeholder;L.DomUtil.addClass(this._wrapper,"geocoder-control-expanded")},this);L.DomEvent.addListener(this._wrapper,"click",function(e){L.DomUtil.addClass(this._wrapper,"geocoder-control-expanded");this._input.focus()},this);L.DomEvent.addListener(this._suggestions,"mousedown",function(e){var suggestionItem=e.target||e.srcElement;this._geocode(suggestionItem.innerHTML,suggestionItem["data-magic-key"],suggestionItem.provider);this.clear()},this);L.DomEvent.addListener(this._input,"blur",function(e){this.clear()},this);L.DomEvent.addListener(this._input,"keydown",function(e){L.DomUtil.addClass(this._wrapper,"geocoder-control-expanded");var list=this._suggestions.querySelectorAll("."+"geocoder-control-suggestion");var selected=this._suggestions.querySelectorAll("."+"geocoder-control-selected")[0];var selectedPosition;for(var i=0;i<list.length;i++){if(list[i]===selected){selectedPosition=i;break}}switch(e.keyCode){case 13:if(selected){this._geocode(selected.innerHTML,selected["data-magic-key"],selected.provider);this.clear()}else if(this.options.allowMultipleResults){this._geocode(this._input.value,undefined);this.clear()}else{L.DomUtil.addClass(list[0],"geocoder-control-selected")}L.DomEvent.preventDefault(e);break;case 38:if(selected){L.DomUtil.removeClass(selected,"geocoder-control-selected")}var previousItem=list[selectedPosition-1];if(selected&&previousItem){L.DomUtil.addClass(previousItem,"geocoder-control-selected")}else{L.DomUtil.addClass(list[list.length-1],"geocoder-control-selected")}L.DomEvent.preventDefault(e);break;case 40:if(selected){L.DomUtil.removeClass(selected,"geocoder-control-selected")}var nextItem=list[selectedPosition+1];if(selected&&nextItem){L.DomUtil.addClass(nextItem,"geocoder-control-selected")}else{L.DomUtil.addClass(list[0],"geocoder-control-selected")}L.DomEvent.preventDefault(e);break;default:for(var x=0;x<this._pendingSuggestions.length;x++){var request=this._pendingSuggestions[x];if(request&&request.abort&&!request.id){request.abort()}}break}},this);L.DomEvent.addListener(this._input,"keyup",L.Util.throttle(function(e){var key=e.which||e.keyCode;var text=(e.target||e.srcElement).value;if(text.length<2){this._suggestions.innerHTML="";this._suggestions.style.display="none";L.DomUtil.removeClass(this._input,"geocoder-control-loading");return}if(key===27){this._suggestions.innerHTML="";this._suggestions.style.display="none";return}if(key!==13&&key!==38&&key!==40){if(this._input.value!==this._lastValue){this._lastValue=this._input.value;this._suggest(text)}}},50,this),this);L.DomEvent.disableClickPropagation(this._wrapper);L.DomEvent.addListener(this._suggestions,"mouseover",function(e){if(map.scrollWheelZoom.enabled()&&map.options.scrollWheelZoom){map.scrollWheelZoom.disable()}});L.DomEvent.addListener(this._suggestions,"mouseout",function(e){if(!map.scrollWheelZoom.enabled()&&map.options.scrollWheelZoom){map.scrollWheelZoom.enable()}});return this._wrapper},onRemove:function(map){map.attributionControl.removeAttribution("Geocoding by Esri")}});function geosearch(options){return new exports.Geosearch(options)}exports.ArcgisOnlineProvider=exports.GeocodeService.extend({options:{label:"Places and Addresses",maxResults:5,attribution:'<a href="https://developers.arcgis.com/en/features/geocoding/">Geocoding by Esri</a>'},suggestions:function(text,bounds,callback){var request=this.suggest().text(text);if(bounds){request.within(bounds)}return request.run(function(error,results,response){var suggestions=[];if(!error){while(response.suggestions.length&&suggestions.length<=this.options.maxResults-1){var suggestion=response.suggestions.shift();if(!suggestion.isCollection){suggestions.push({text:suggestion.text,magicKey:suggestion.magicKey})}}}callback(error,suggestions)},this)},results:function(text,key,bounds,callback){var request=this.geocode().text(text);if(key){request.key(key)}else{request.maxLocations(this.options.maxResults)}if(bounds){request.within(bounds)}if(this.options.forStorage){request.forStorage(true)}return request.run(function(error,response){callback(error,response.results)},this)}});function arcgisOnlineProvider(options){return new exports.ArcgisOnlineProvider(options)}exports.FeatureLayerProvider=esri_leaflet.FeatureLayerService.extend({options:{label:"Feature Layer",maxResults:5,bufferRadius:1e3,formatSuggestion:function(feature){return feature.properties[this.options.searchFields[0]]}},initialize:function(options){esri_leaflet.FeatureLayerService.prototype.initialize.call(this,options);if(typeof this.options.searchFields==="string"){this.options.searchFields=[this.options.searchFields]}},suggestions:function(text,bounds,callback){var query=this.query().where(this._buildQuery(text)).returnGeometry(false);if(bounds){query.intersects(bounds)}if(this.options.idField){query.fields([this.options.idField].concat(this.options.searchFields))}var request=query.run(function(error,results,raw){if(error){callback(error,[])}else{this.options.idField=raw.objectIdFieldName;var suggestions=[];var count=Math.min(results.features.length,this.options.maxResults);for(var i=0;i<count;i++){var feature=results.features[i];suggestions.push({text:this.options.formatSuggestion.call(this,feature),magicKey:feature.id})}callback(error,suggestions.slice(0,this.options.maxResults).reverse())}},this);return request},results:function(text,key,bounds,callback){var query=this.query();if(key){query.featureIds([key])}else{query.where(this._buildQuery(text))}if(bounds){query.within(bounds)}return query.run(L.Util.bind(function(error,features){var results=[];for(var i=0;i<features.features.length;i++){var feature=features.features[i];if(feature){var bounds=this._featureBounds(feature);var result={latlng:bounds.getCenter(),bounds:bounds,text:this.options.formatSuggestion.call(this,feature),properties:feature.properties};results.push(result)}}callback(error,results)},this))},_buildQuery:function(text){var queryString=[];for(var i=this.options.searchFields.length-1;i>=0;i--){var field=this.options.searchFields[i];queryString.push(field+" LIKE '%"+text+"%'")}return queryString.join(" OR ")},_featureBounds:function(feature){var geojson=L.geoJson(feature);if(feature.geometry.type==="Point"){var center=geojson.getBounds().getCenter();var lngRadius=this.options.bufferRadius/40075017*360/Math.cos(180/Math.PI*center.lat);var latRadius=this.options.bufferRadius/40075017*360;return L.latLngBounds([center.lat-latRadius,center.lng-lngRadius],[center.lat+latRadius,center.lng+lngRadius])}else{return geojson.getBounds()}}});function featureLayerProvider(options){return new exports.FeatureLayerProvider(options)}exports.MapServiceProvider=esri_leaflet.MapService.extend({options:{layers:[0],label:"Map Service",bufferRadius:1e3,maxResults:5,formatSuggestion:function(feature){return feature.properties[feature.displayFieldName]+" <small>"+feature.layerName+"</small>"}},initialize:function(options){esri_leaflet.MapService.prototype.initialize.call(this,options);this._getIdFields()},suggestions:function(text,bounds,callback){var request=this.find().text(text).fields(this.options.searchFields).returnGeometry(false).layers(this.options.layers);return request.run(function(error,results,raw){var suggestions=[];if(!error){var count=Math.min(this.options.maxResults,results.features.length);raw.results=raw.results.reverse();for(var i=0;i<count;i++){var feature=results.features[i];var result=raw.results[i];var layer=result.layerId;var idField=this._idFields[layer];feature.layerId=layer;feature.layerName=this._layerNames[layer];feature.displayFieldName=this._displayFields[layer];if(idField){suggestions.push({text:this.options.formatSuggestion.call(this,feature),magicKey:result.attributes[idField]+":"+layer})}}}callback(error,suggestions.reverse())},this)},results:function(text,key,bounds,callback){var results=[];var request;if(key){var featureId=key.split(":")[0];var layer=key.split(":")[1];request=this.query().layer(layer).featureIds(featureId)}else{request=this.find().text(text).fields(this.options.searchFields).contains(false).layers(this.options.layers)}return request.run(function(error,features,response){if(!error){if(response.results){response.results=response.results.reverse()}for(var i=0;i<features.features.length;i++){var feature=features.features[i];layer=layer?layer:response.results[i].layerId;if(feature&&layer!==undefined){var bounds=this._featureBounds(feature);feature.layerId=layer;feature.layerName=this._layerNames[layer];feature.displayFieldName=this._displayFields[layer];var result={latlng:bounds.getCenter(),bounds:bounds,text:this.options.formatSuggestion.call(this,feature),properties:feature.properties};results.push(result)}}}callback(error,results.reverse())},this)},_featureBounds:function(feature){var geojson=L.geoJson(feature);if(feature.geometry.type==="Point"){var center=geojson.getBounds().getCenter();var lngRadius=this.options.bufferRadius/40075017*360/Math.cos(180/Math.PI*center.lat);var latRadius=this.options.bufferRadius/40075017*360;return L.latLngBounds([center.lat-latRadius,center.lng-lngRadius],[center.lat+latRadius,center.lng+lngRadius])}else{return geojson.getBounds()}},_layerMetadataCallback:function(layerid){return L.Util.bind(function(error,metadata){if(error){return}this._displayFields[layerid]=metadata.displayField;this._layerNames[layerid]=metadata.name;for(var i=0;i<metadata.fields.length;i++){var field=metadata.fields[i];if(field.type==="esriFieldTypeOID"){this._idFields[layerid]=field.name;break}}},this)},_getIdFields:function(){this._idFields={};this._displayFields={};this._layerNames={};for(var i=0;i<this.options.layers.length;i++){var layer=this.options.layers[i];this.get(layer,{},this._layerMetadataCallback(layer))}}});function mapServiceProvider(options){return new exports.MapServiceProvider(options)}exports.GeocodeServiceProvider=exports.GeocodeService.extend({options:{label:"Geocode Server",maxResults:5},suggestions:function(text,bounds,callback){if(this.options.supportsSuggest){var request=this.suggest().text(text);if(bounds){request.within(bounds)}return request.run(function(error,results,response){var suggestions=[];if(!error){while(response.suggestions.length&&suggestions.length<=this.options.maxResults-1){var suggestion=response.suggestions.shift();if(!suggestion.isCollection){suggestions.push({text:suggestion.text,magicKey:suggestion.magicKey})}}}callback(error,suggestions)},this)}else{callback(undefined,[]);return false}},results:function(text,key,bounds,callback){var request=this.geocode().text(text);request.maxLocations(this.options.maxResults);if(bounds){request.within(bounds)}return request.run(function(error,response){callback(error,response.results)},this)}});function geocodeServiceProvider(options){return new exports.GeocodeServiceProvider(options)}exports.VERSION="2.0.0-beta.1";exports.WorldGeocodingServiceUrl=(window.location.protocol==="https:"?"https:":"http:")+"//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/";exports.geocode=geocode;exports.reverseGeocode=reverseGeocode;exports.suggest=suggest;exports.geocodeService=geocodeService;exports.geosearch=geosearch;exports.arcgisOnlineProvider=arcgisOnlineProvider;exports.featureLayerProvider=featureLayerProvider;exports.mapServiceProvider=mapServiceProvider;exports.geocodeServiceProvider=geocodeServiceProvider});
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?factory(exports,require("leaflet"),require("esri-leaflet")):typeof define==="function"&&define.amd?define(["exports","leaflet","esri-leaflet"],factory):factory(global.L.esri.Geocoding={},L,L.esri)})(this,function(exports,L,esri_leaflet){"use strict";exports.Geocode=esri_leaflet.Task.extend({path:"find",params:{outSr:4326,forStorage:false,outFields:"*",maxLocations:20},setters:{address:"address",neighborhood:"neighborhood",city:"city",subregion:"subregion",region:"region",postal:"postal",country:"country",text:"text",category:"category",token:"token",key:"magicKey",fields:"outFields",forStorage:"forStorage",maxLocations:"maxLocations"},initialize:function(options){options=options||{};options.url=options.url||exports.WorldGeocodingServiceUrl;esri_leaflet.Task.prototype.initialize.call(this,options)},within:function(bounds){bounds=L.latLngBounds(bounds);this.params.bbox=esri_leaflet.Util.boundsToExtent(bounds);return this},nearby:function(latlng,radius){latlng=L.latLng(latlng);this.params.location=latlng.lng+","+latlng.lat;this.params.distance=Math.min(Math.max(radius,2e3),5e4);return this},run:function(callback,context){this.path=this.params.text?"find":"findAddressCandidates";if(this.path==="findAddressCandidates"&&this.params.bbox){this.params.searchExtent=this.params.bbox;delete this.params.bbox}return this.request(function(error,response){var processor=this.path==="find"?this._processFindResponse:this._processFindAddressCandidatesResponse;var results=!error?processor(response):undefined;callback.call(context,error,{results:results},response)},this)},_processFindResponse:function(response){var results=[];for(var i=0;i<response.locations.length;i++){var location=response.locations[i];var bounds;if(location.extent){bounds=esri_leaflet.Util.extentToBounds(location.extent)}results.push({text:location.name,bounds:bounds,score:location.feature.attributes.Score,latlng:L.latLng(location.feature.geometry.y,location.feature.geometry.x),properties:location.feature.attributes})}return results},_processFindAddressCandidatesResponse:function(response){var results=[];for(var i=0;i<response.candidates.length;i++){var candidate=response.candidates[i];var bounds=esri_leaflet.Util.extentToBounds(candidate.extent);results.push({text:candidate.address,bounds:bounds,score:candidate.score,latlng:L.latLng(candidate.location.y,candidate.location.x),properties:candidate.attributes})}return results}});function geocode(options){return new exports.Geocode(options)}exports.ReverseGeocode=esri_leaflet.Task.extend({path:"reverseGeocode",params:{outSR:4326},setters:{distance:"distance",language:"language"},initialize:function(options){options=options||{};options.url=options.url||exports.WorldGeocodingServiceUrl;esri_leaflet.Task.prototype.initialize.call(this,options)},latlng:function(latlng){latlng=L.latLng(latlng);this.params.location=latlng.lng+","+latlng.lat;return this},run:function(callback,context){return this.request(function(error,response){var result;if(!error){result={latlng:L.latLng(response.location.y,response.location.x),address:response.address}}else{result=undefined}callback.call(context,error,result,response)},this)}});function reverseGeocode(options){return new exports.ReverseGeocode(options)}exports.Suggest=esri_leaflet.Task.extend({path:"suggest",params:{},setters:{text:"text",category:"category"},initialize:function(options){options=options||{};options.url=options.url||exports.WorldGeocodingServiceUrl;esri_leaflet.Task.prototype.initialize.call(this,options)},within:function(bounds){bounds=L.latLngBounds(bounds);bounds=bounds.pad(.5);var center=bounds.getCenter();var ne=bounds.getNorthWest();this.params.location=center.lng+","+center.lat;this.params.distance=Math.min(Math.max(center.distanceTo(ne),2e3),5e4);this.params.searchExtent=esri_leaflet.Util.boundsToExtent(bounds);return this},nearby:function(latlng,radius){latlng=L.latLng(latlng);this.params.location=latlng.lng+","+latlng.lat;this.params.distance=Math.min(Math.max(radius,2e3),5e4);return this},run:function(callback,context){return this.request(function(error,response){callback.call(context,error,response,response)},this)}});function suggest(options){return new exports.Suggest(options)}exports.GeocodeService=esri_leaflet.Service.extend({initialize:function(options){options=options||{};options.url=options.url||exports.WorldGeocodingServiceUrl;esri_leaflet.Service.prototype.initialize.call(this,options);this._confirmSuggestSupport()},geocode:function(){return geocode(this)},reverse:function(){return reverseGeocode(this)},suggest:function(){return suggest(this)},_confirmSuggestSupport:function(){this.metadata(function(error,response){if(error){return}if(response.capabilities.includes("Suggest")){this.options.supportsSuggest=true}else{this.options.supportsSuggest=false}},this)}});function geocodeService(options){return new exports.GeocodeService(options)}exports.Geosearch=L.Control.extend({includes:L.Mixin.Events,options:{position:"topleft",zoomToResult:true,useMapBounds:12,collapseAfterResult:true,expanded:false,forStorage:false,allowMultipleResults:true,placeholder:"Search for places or addresses",title:"Location Search"},initialize:function(options){if(!options||!options.providers||!options.providers.length){throw new Error("You must specificy at least one provider")}this._providers=options.providers;for(var i=0;i<this._providers.length;i++){this._providers[i].addEventParent(this)}this._pendingSuggestions=[];L.Control.prototype.initialize.call(options)},_geocode:function(text,key,provider){var activeRequests=0;var allResults=[];var bounds;var callback=L.Util.bind(function(error,results){activeRequests--;if(error){return}if(results){allResults=allResults.concat(results)}if(activeRequests<=0){bounds=this._boundsFromResults(allResults);this.fire("results",{results:allResults,bounds:bounds,latlng:bounds?bounds.getCenter():undefined,text:text});if(this.options.zoomToResult&&bounds){this._map.fitBounds(bounds)}L.DomUtil.removeClass(this._input,"geocoder-control-loading");this.fire("load");this.clear();this._input.blur()}},this);if(key){activeRequests++;provider.results(text,key,this._searchBounds(),callback)}else{for(var i=0;i<this._providers.length;i++){activeRequests++;this._providers[i].results(text,key,this._searchBounds(),callback)}}},_suggest:function(text){L.DomUtil.addClass(this._input,"geocoder-control-loading");var activeRequests=this._providers.length;var createCallback=L.Util.bind(function(text,provider){return L.Util.bind(function(error,suggestions){if(error){return}var i;activeRequests=activeRequests-1;if(this._input.value<2){this._suggestions.innerHTML="";this._suggestions.style.display="none";return}if(suggestions){for(i=0;i<suggestions.length;i++){suggestions[i].provider=provider}}if(provider._lastRender!==text&&provider.nodes){for(i=0;i<provider.nodes.length;i++){if(provider.nodes[i].parentElement){this._suggestions.removeChild(provider.nodes[i])}}provider.nodes=[]}if(suggestions.length&&this._input.value===text){if(provider.nodes){for(var k=0;k<provider.nodes.length;k++){if(provider.nodes[k].parentElement){this._suggestions.removeChild(provider.nodes[k])}}}provider._lastRender=text;provider.nodes=this._renderSuggestions(suggestions)}if(activeRequests===0){L.DomUtil.removeClass(this._input,"geocoder-control-loading")}},this)},this);this._pendingSuggestions=[];for(var i=0;i<this._providers.length;i++){var provider=this._providers[i];var request=provider.suggestions(text,this._searchBounds(),createCallback(text,provider));this._pendingSuggestions.push(request)}},_searchBounds:function(){if(this.options.useMapBounds===false){return null}if(this.options.useMapBounds===true){return this._map.getBounds()}if(this.options.useMapBounds<=this._map.getZoom()){return this._map.getBounds()}return null},_renderSuggestions:function(suggestions){var currentGroup;this._suggestions.style.display="block";this._suggestions.style.maxHeight=this._map.getSize().y-this._suggestions.offsetTop-this._wrapper.offsetTop-10+"px";var nodes=[];var list;var header;for(var i=0;i<suggestions.length;i++){var suggestion=suggestions[i];if(!header&&this._providers.length>1&&currentGroup!==suggestion.provider.options.label){header=L.DomUtil.create("span","geocoder-control-header",this._suggestions);header.textContent=suggestion.provider.options.label;header.innerText=suggestion.provider.options.label;currentGroup=suggestion.provider.options.label;nodes.push(header)}if(!list){list=L.DomUtil.create("ul","geocoder-control-list",this._suggestions)}var suggestionItem=L.DomUtil.create("li","geocoder-control-suggestion",list);suggestionItem.innerHTML=suggestion.text;suggestionItem.provider=suggestion.provider;suggestionItem["data-magic-key"]=suggestion.magicKey}nodes.push(list);return nodes},_boundsFromResults:function(results){if(!results.length){return}var nullIsland=L.latLngBounds([0,0],[0,0]);var bounds=L.latLngBounds();for(var i=results.length-1;i>=0;i--){var result=results[i];if(result.bounds&&result.bounds.isValid()&&!result.bounds.equals(nullIsland)){bounds.extend(result.bounds)}bounds.extend(result.latlng)}return bounds},clear:function(){this._suggestions.innerHTML="";this._suggestions.style.display="none";this._input.value="";if(this.options.collapseAfterResult){this._input.placeholder="";L.DomUtil.removeClass(this._wrapper,"geocoder-control-expanded")}if(!this._map.scrollWheelZoom.enabled()&&this._map.options.scrollWheelZoom){this._map.scrollWheelZoom.enable()}},getAttribution:function(){var attribution=this.options.attribution;for(var i=0;i<this._providers.length;i++){attribution+=" "+this._providers[i].options.attribution}return attribution},onAdd:function(map){this._map=map;this._wrapper=L.DomUtil.create("div","geocoder-control "+(this.options.expanded?" "+"geocoder-control-expanded":""));this._input=L.DomUtil.create("input","geocoder-control-input leaflet-bar",this._wrapper);this._input.title=this.options.title;this._suggestions=L.DomUtil.create("div","geocoder-control-suggestions leaflet-bar",this._wrapper);L.DomEvent.addListener(this._input,"focus",function(e){this._input.placeholder=this.options.placeholder;L.DomUtil.addClass(this._wrapper,"geocoder-control-expanded")},this);L.DomEvent.addListener(this._wrapper,"click",function(e){L.DomUtil.addClass(this._wrapper,"geocoder-control-expanded");this._input.focus()},this);L.DomEvent.addListener(this._suggestions,"mousedown",function(e){var suggestionItem=e.target||e.srcElement;this._geocode(suggestionItem.innerHTML,suggestionItem["data-magic-key"],suggestionItem.provider);this.clear()},this);L.DomEvent.addListener(this._input,"blur",function(e){this.clear()},this);L.DomEvent.addListener(this._input,"keydown",function(e){L.DomUtil.addClass(this._wrapper,"geocoder-control-expanded");var list=this._suggestions.querySelectorAll("."+"geocoder-control-suggestion");var selected=this._suggestions.querySelectorAll("."+"geocoder-control-selected")[0];var selectedPosition;for(var i=0;i<list.length;i++){if(list[i]===selected){selectedPosition=i;break}}switch(e.keyCode){case 13:if(selected){this._geocode(selected.innerHTML,selected["data-magic-key"],selected.provider);this.clear()}else if(this.options.allowMultipleResults){this._geocode(this._input.value,undefined);this.clear()}else{L.DomUtil.addClass(list[0],"geocoder-control-selected")}L.DomEvent.preventDefault(e);break;case 38:if(selected){L.DomUtil.removeClass(selected,"geocoder-control-selected")}var previousItem=list[selectedPosition-1];if(selected&&previousItem){L.DomUtil.addClass(previousItem,"geocoder-control-selected")}else{L.DomUtil.addClass(list[list.length-1],"geocoder-control-selected")}L.DomEvent.preventDefault(e);break;case 40:if(selected){L.DomUtil.removeClass(selected,"geocoder-control-selected")}var nextItem=list[selectedPosition+1];if(selected&&nextItem){L.DomUtil.addClass(nextItem,"geocoder-control-selected")}else{L.DomUtil.addClass(list[0],"geocoder-control-selected")}L.DomEvent.preventDefault(e);break;default:for(var x=0;x<this._pendingSuggestions.length;x++){var request=this._pendingSuggestions[x];if(request&&request.abort&&!request.id){request.abort()}}break}},this);L.DomEvent.addListener(this._input,"keyup",L.Util.throttle(function(e){var key=e.which||e.keyCode;var text=(e.target||e.srcElement).value;if(text.length<2){this._suggestions.innerHTML="";this._suggestions.style.display="none";L.DomUtil.removeClass(this._input,"geocoder-control-loading");return}if(key===27){this._suggestions.innerHTML="";this._suggestions.style.display="none";return}if(key!==13&&key!==38&&key!==40){if(this._input.value!==this._lastValue){this._lastValue=this._input.value;this._suggest(text)}}},50,this),this);L.DomEvent.disableClickPropagation(this._wrapper);L.DomEvent.addListener(this._suggestions,"mouseover",function(e){if(map.scrollWheelZoom.enabled()&&map.options.scrollWheelZoom){map.scrollWheelZoom.disable()}});L.DomEvent.addListener(this._suggestions,"mouseout",function(e){if(!map.scrollWheelZoom.enabled()&&map.options.scrollWheelZoom){map.scrollWheelZoom.enable()}});return this._wrapper},onRemove:function(map){map.attributionControl.removeAttribution("Geocoding by Esri")}});function geosearch(options){return new exports.Geosearch(options)}exports.ArcgisOnlineProvider=exports.GeocodeService.extend({options:{label:"Places and Addresses",maxResults:5,attribution:'<a href="https://developers.arcgis.com/en/features/geocoding/">Geocoding by Esri</a>'},suggestions:function(text,bounds,callback){var request=this.suggest().text(text);if(bounds){request.within(bounds)}return request.run(function(error,results,response){var suggestions=[];if(!error){while(response.suggestions.length&&suggestions.length<=this.options.maxResults-1){var suggestion=response.suggestions.shift();if(!suggestion.isCollection){suggestions.push({text:suggestion.text,magicKey:suggestion.magicKey})}}}callback(error,suggestions)},this)},results:function(text,key,bounds,callback){var request=this.geocode().text(text);if(key){request.key(key)}else{request.maxLocations(this.options.maxResults)}if(bounds){request.within(bounds)}if(this.options.forStorage){request.forStorage(true)}return request.run(function(error,response){callback(error,response.results)},this)}});function arcgisOnlineProvider(options){return new exports.ArcgisOnlineProvider(options)}exports.FeatureLayerProvider=esri_leaflet.FeatureLayerService.extend({options:{label:"Feature Layer",maxResults:5,bufferRadius:1e3,formatSuggestion:function(feature){return feature.properties[this.options.searchFields[0]]}},initialize:function(options){esri_leaflet.FeatureLayerService.prototype.initialize.call(this,options);if(typeof this.options.searchFields==="string"){this.options.searchFields=[this.options.searchFields]}},suggestions:function(text,bounds,callback){var query=this.query().where(this._buildQuery(text)).returnGeometry(false);if(bounds){query.intersects(bounds)}if(this.options.idField){query.fields([this.options.idField].concat(this.options.searchFields))}var request=query.run(function(error,results,raw){if(error){callback(error,[])}else{this.options.idField=raw.objectIdFieldName;var suggestions=[];var count=Math.min(results.features.length,this.options.maxResults);for(var i=0;i<count;i++){var feature=results.features[i];suggestions.push({text:this.options.formatSuggestion.call(this,feature),magicKey:feature.id})}callback(error,suggestions.slice(0,this.options.maxResults).reverse())}},this);return request},results:function(text,key,bounds,callback){var query=this.query();if(key){query.featureIds([key])}else{query.where(this._buildQuery(text))}if(bounds){query.within(bounds)}return query.run(L.Util.bind(function(error,features){var results=[];for(var i=0;i<features.features.length;i++){var feature=features.features[i];if(feature){var bounds=this._featureBounds(feature);var result={latlng:bounds.getCenter(),bounds:bounds,text:this.options.formatSuggestion.call(this,feature),properties:feature.properties};results.push(result)}}callback(error,results)},this))},_buildQuery:function(text){var queryString=[];for(var i=this.options.searchFields.length-1;i>=0;i--){var field=this.options.searchFields[i];queryString.push(field+" LIKE '%"+text+"%'")}return queryString.join(" OR ")},_featureBounds:function(feature){var geojson=L.geoJson(feature);if(feature.geometry.type==="Point"){var center=geojson.getBounds().getCenter();var lngRadius=this.options.bufferRadius/40075017*360/Math.cos(180/Math.PI*center.lat);var latRadius=this.options.bufferRadius/40075017*360;return L.latLngBounds([center.lat-latRadius,center.lng-lngRadius],[center.lat+latRadius,center.lng+lngRadius])}else{return geojson.getBounds()}}});function featureLayerProvider(options){return new exports.FeatureLayerProvider(options)}exports.MapServiceProvider=esri_leaflet.MapService.extend({options:{layers:[0],label:"Map Service",bufferRadius:1e3,maxResults:5,formatSuggestion:function(feature){return feature.properties[feature.displayFieldName]+" <small>"+feature.layerName+"</small>"}},initialize:function(options){esri_leaflet.MapService.prototype.initialize.call(this,options);this._getIdFields()},suggestions:function(text,bounds,callback){var request=this.find().text(text).fields(this.options.searchFields).returnGeometry(false).layers(this.options.layers);return request.run(function(error,results,raw){var suggestions=[];if(!error){var count=Math.min(this.options.maxResults,results.features.length);raw.results=raw.results.reverse();for(var i=0;i<count;i++){var feature=results.features[i];var result=raw.results[i];var layer=result.layerId;var idField=this._idFields[layer];feature.layerId=layer;feature.layerName=this._layerNames[layer];feature.displayFieldName=this._displayFields[layer];if(idField){suggestions.push({text:this.options.formatSuggestion.call(this,feature),magicKey:result.attributes[idField]+":"+layer})}}}callback(error,suggestions.reverse())},this)},results:function(text,key,bounds,callback){var results=[];var request;if(key){var featureId=key.split(":")[0];var layer=key.split(":")[1];request=this.query().layer(layer).featureIds(featureId)}else{request=this.find().text(text).fields(this.options.searchFields).contains(false).layers(this.options.layers)}return request.run(function(error,features,response){if(!error){if(response.results){response.results=response.results.reverse()}for(var i=0;i<features.features.length;i++){var feature=features.features[i];layer=layer?layer:response.results[i].layerId;if(feature&&layer!==undefined){var bounds=this._featureBounds(feature);feature.layerId=layer;feature.layerName=this._layerNames[layer];feature.displayFieldName=this._displayFields[layer];var result={latlng:bounds.getCenter(),bounds:bounds,text:this.options.formatSuggestion.call(this,feature),properties:feature.properties};results.push(result)}}}callback(error,results.reverse())},this)},_featureBounds:function(feature){var geojson=L.geoJson(feature);if(feature.geometry.type==="Point"){var center=geojson.getBounds().getCenter();var lngRadius=this.options.bufferRadius/40075017*360/Math.cos(180/Math.PI*center.lat);var latRadius=this.options.bufferRadius/40075017*360;return L.latLngBounds([center.lat-latRadius,center.lng-lngRadius],[center.lat+latRadius,center.lng+lngRadius])}else{return geojson.getBounds()}},_layerMetadataCallback:function(layerid){return L.Util.bind(function(error,metadata){if(error){return}this._displayFields[layerid]=metadata.displayField;this._layerNames[layerid]=metadata.name;for(var i=0;i<metadata.fields.length;i++){var field=metadata.fields[i];if(field.type==="esriFieldTypeOID"){this._idFields[layerid]=field.name;break}}},this)},_getIdFields:function(){this._idFields={};this._displayFields={};this._layerNames={};for(var i=0;i<this.options.layers.length;i++){var layer=this.options.layers[i];this.get(layer,{},this._layerMetadataCallback(layer))}}});function mapServiceProvider(options){return new exports.MapServiceProvider(options)}exports.GeocodeServiceProvider=exports.GeocodeService.extend({options:{label:"Geocode Server",maxResults:5},suggestions:function(text,bounds,callback){if(this.options.supportsSuggest){var request=this.suggest().text(text);if(bounds){request.within(bounds)}return request.run(function(error,results,response){var suggestions=[];if(!error){while(response.suggestions.length&&suggestions.length<=this.options.maxResults-1){var suggestion=response.suggestions.shift();if(!suggestion.isCollection){suggestions.push({text:suggestion.text,magicKey:suggestion.magicKey})}}}callback(error,suggestions)},this)}else{callback(undefined,[]);return false}},results:function(text,key,bounds,callback){var request=this.geocode().text(text);request.maxLocations(this.options.maxResults);if(bounds){request.within(bounds)}return request.run(function(error,response){callback(error,response.results)},this)}});function geocodeServiceProvider(options){return new exports.GeocodeServiceProvider(options)}exports.VERSION="2.0.0-beta.2";exports.WorldGeocodingServiceUrl=(window.location.protocol==="https:"?"https:":"http:")+"//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/";exports.geocode=geocode;exports.reverseGeocode=reverseGeocode;exports.suggest=suggest;exports.geocodeService=geocodeService;exports.geosearch=geosearch;exports.arcgisOnlineProvider=arcgisOnlineProvider;exports.featureLayerProvider=featureLayerProvider;exports.mapServiceProvider=mapServiceProvider;exports.geocodeServiceProvider=geocodeServiceProvider});
//# sourceMappingURL=./esri-leaflet-geocoder.js.map
{
"name": "esri-leaflet-geocoder",
"description": "Esri Geocoding utilities and search plguin for Leaflet.",
"version": "2.0.0-beta.1",
"version": "2.0.0-beta.2",
"author": "Patrick Arlt <parlt@esri.com> (http://patrickarlt.com)",

@@ -54,2 +54,3 @@ "browserify": {

"dist/esri-leaflet-geocoder.js",
"dist/esri-leaflet-geocoder.js.map",
"dist/esri-leaflet-geocoder.css",

@@ -56,0 +57,0 @@ "dist/img"

@@ -7,4 +7,2 @@ # Esri Leaflet Geocoder

Esri Leaflet Geocoder relies on the minimal Esri Leaflet Core which handles abstraction for requests and authentication when neccessary. You can find out more about the Esri Leaflet Core on the [Esri Leaflet downloads page](http://esri.github.com/esri-leaflet/downloads).
## Example

@@ -69,3 +67,3 @@

## L.esri.Geocoding.Controls.Geosearch
## L.esri.Geocoding.geosearch

@@ -78,3 +76,3 @@ ### Constructor

--- | --- | ---
`L.esri.Controls.geosearch(options)` | [`<GeosearchOptions>`](#options) | Creates a new Geosearch control.
`L.esri.Geocoding.geosearch(options)` | [`<GeosearchOptions>`](#options) | Creates a new Geosearch control.

@@ -92,7 +90,5 @@ ### Options

`allowMultipleResults` | `Boolean` | `true` | If set to `true` and the user submits the form without a suggestion selected geocodes the current text in the input and zooms the user to view all the results.
`useArcgisWorldGeocoder` | `Boolean` | `true` | Use the ArcGIS Online World Geocoder by default in the array of providers.
`providers` | `Array` | See Description | An array of `EsriLeafletGeocoding.Controls.Geosearch.Providers` objects. These additional providers will also be searched for possible results and added to the suggestion list.
`providers` | `Array` | See Description | An array of [providers](#providers) to search.
`placeholder` | `String` | `'Search for places or addresses'` | Placeholder text for the search input.
`title` | `String` | `Location Search` | Title text for the search input. Shows as tool tip on hover.
`mapAttribution` | `String` | `Geocoding by Esri` | Custom geocoding attribution to be added to map. This setting is ignored and the default attribution is used if `useArcgisworldgeocoder` is `true`.

@@ -113,2 +109,4 @@ ### Methods

Events from each [provider](#providers) and will match the events fired by [L.esri.service events](http://esri.github.io/esri-leaflet/api-reference/services/service.html).
### Styling

@@ -134,3 +132,4 @@ For reference here is the internal structure of the geocoder...

```js
var gisDay = new L.esri.Geocoding.Controls.Geosearch.Providers.FeatureLayer({
var arcgisOnline = L.esri.Geocoding.arcgisOnlineProvider();
var gisDay = L.esri.Geocoding.featureLayerProvider({
url: 'https://services.arcgis.com/uCXeTVveQzP4IIcx/arcgis/rest/services/GIS_Day_Final/FeatureServer/0',

@@ -145,3 +144,3 @@ searchFields: ['Name', 'Organization'], // Search these fields for text matches

L.esri.Geocoding.Controls.geosearch({
providers: [gisDay]
providers: [arcgisOnline, gisDay] // will geocode via ArcGIS Online and search the GIS Day feature service.
}).addTo(map);

@@ -152,6 +151,6 @@ ```

* `L.esri.Geocoding.Controls.Geosearch.Providers.ArcGISOnline` - Included by default unless the `useArcgisWorldGeocoder` option is set to false.
* `L.esri.Geocoding.Controls.Geosearch.Providers.FeatureLayer` - Gets results by querying the Feature Layer for text matches.
* `L.esri.Geocoding.Controls.Geosearch.Providers.MapService` - Uses the find and query methods on the Map Service to get text matches.
* `L.esri.Geocoding.Controls.Geosearch.Providers.GeocodeService` - Use a ArcGIS Server Geocode Service.
* `L.esri.Geocoding.arcgisOnlineProvider(options)` - Uses the ArcGIS Online World Geocoding service.
* `L.esri.Geocoding.featureLayerProvider(options)` - Gets results by querying the Feature Layer for text matches.
* `L.esri.Geocoding.mapServiceProvider(options)` - Uses the find and query methods on the Map Service to get text matches.
* `L.esri.Geocoding.geocodeServiceProvider` - Use an ArcGIS Server Geocode Service, supports suggestions if available with ARcGIS Server 10.3 and up.

@@ -162,9 +161,9 @@ #### Provider Options

--- | --- | --- | ---
`url` | `String` | Depends | The URL for the service that will be used to search. Varies by provider, usually a service or layer URL or a geocoding service URL.
`searchFields` | `Array[Strings]` | None | An array of fields to search for text. Not valid for the `ArcGISOnline` and `GeocodeService` providers.
`layer` | `Integer` | `0` | Only valid for `MapService` providers, the layer to find text matches on.
`url` | `String` | Depends | The URL for the service that will be used to search. Varies by provider, usually a service or layer URL or a geocoding service URL. Not needed with the `arcgisOnlineProvider`.
`searchFields` | `Array[Strings]` | None | An array of fields to search for text. Not valid for the `arcgisOnlineProvider` and `geocodeServiceProvider` providers.
`layer` | `Integer` | `0` | Only valid for `mapServiceProvider` providers, the layer to find text matches on.
`label` | `String` | Provider Type | Text that will be used to group suggestions under when more than one provider is being used.
`maxResults` | `Integer` | 5 | Maximum number of results to show for this provider.
`bufferRadius`, | `Integer` | If a service or layer contains points, buffer points by this radius to create bounds. Not valid for the `ArcGISOnline` and `GeocodeService` providers
`formatSuggestion`| `Function` | See Description | Formatting function for the suggestion text from `FeatureLayer` provider. Receives a feature and returns a string.
`bufferRadius`, | `Integer` | If a service or layer contains points, buffer points by this radius to create bounds. Not valid for the `arcgisOnlineProvider` and `geocodeServiceProvider`.
`formatSuggestion`| `Function` | See Description | Formatting function for the suggestion text. Receives feature information and returns a string.

@@ -191,4 +190,4 @@ #### Results Event

## L.esri.Geocoding.Services.Geocoding
A basic wrapper for ArcGIS Online geocoding services. Used internally by `L.esri.Controls.Geosearch`.
## L.esri.Geocoding.geocodeService
A basic wrapper for ArcGIS Online geocoding services. Used internally by `L.esri.Geocoding.geosearch`.

@@ -199,3 +198,3 @@ ### Constructor

--- | ---
`L.esri.Geocoding.Services.geocoding(options)` | Creates a new Geocoding service. You can pass the `url` in the options to reference a custom geocoding endpoint if you do not want to use the ArcGIS Online World Geocoding service.
`L.esri.Geocoding.geocodeService(options)` | Creates a new Geocoding service. You can pass the `url` in the options to reference a custom geocoding endpoint if you do not want to use the ArcGIS Online World Geocoding service.

@@ -210,11 +209,11 @@ ### Options

--- | --- | ---
`geocode()` | L.esri.Geocoding.Tasks.Geocode | Returns a new Geocode task bound to this server.
`suggest()` | L.esri.Geocoding.Tasks.Suggest | Returns a new Suggest task bound to this server.
`reverse()` | L.esri.Geocoding.Tasks.ReverseGeocode | Returns a new ReverseGeocode task bound to this server.
`geocode()` | L.esri.Geocoding.geocode | Returns a new Geocode task bound to this server.
`suggest()` | L.esri.Geocoding.suggest | Returns a new Suggest task bound to this server.
`reverse()` | L.esri.Geocoding.reverseGeocode | Returns a new ReverseGeocode task bound to this server.
### Events
L.esri.Services.FeatureLayer fires all L.esri.Services.service events.
L.esri.Geocoding.geocodeService fires all [L.esri.service events](http://esri.github.io/esri-leaflet/api-reference/services/service.html).
## L.esri.Geocoding.Tasks.Geocode
## L.esri.Geocoding.geocode

@@ -225,3 +224,3 @@ ### Constructor

--- | ---
`L.esri.Geocoding.Tasks.geocode(options)` | Creates a new Geocode task.
`L.esri.Geocoding.geocode(options)` | Creates a new Geocode task.

@@ -252,3 +251,3 @@ ### Options

```js
L.esri.Geocoding.Tasks.geocode().text('380 New York St, Redlands, California, 92373').run(function(err, results, response){
L.esri.Geocoding.geocode().text('380 New York St, Redlands, California, 92373').run(function(err, results, response){
console.log(results);

@@ -259,3 +258,3 @@ });

```js
L.esri.Geocoding.Tasks.geocode().address('380 New York St').city('Redlands').region('California').postal(92373).run(function(err, results, response){
L.esri.Geocoding.geocode().address('380 New York St').city('Redlands').region('California').postal(92373).run(function(err, results, response){
console.log(results);

@@ -271,3 +270,3 @@ });

L.esri.Geocoding.Tasks.geocode().text("Denver").within(bounds).run(function(err, response){
L.esri.Geocoding.geocode().text("Denver").within(bounds).run(function(err, response){
console.log(response);

@@ -281,3 +280,3 @@ });

L.esri.Geocoding.Tasks.geocode().text("Highlands Ranch").nearby(denver, 20000).run(function(err, response){
L.esri.Geocoding.geocode().text("Highlands Ranch").nearby(denver, 20000).run(function(err, response){
console.log(response);

@@ -306,3 +305,3 @@ });

## L.esri.Geocoding.Tasks.Suggest
## L.esri.Geocoding.suggest

@@ -313,3 +312,3 @@ ### Constructor

--- | ---
`L.esri.Geocoding.Tasks.suggest(options)` | Creates a new Suggest task using the ArcGIS World Geocoder.
`L.esri.Geocoding.suggest(options)` | Creates a new Suggest task using the ArcGIS World Geocoder.

@@ -324,3 +323,3 @@ ### Options

--- | --- | ---
`text(text <String>)` | `this` | The text to recive suggestions for.
`text(text <String>)` | `this` | The text to receive suggestions for.
`category(category <String>)` | The category to search for suggestions. By default no categogy. A list of categories can be found [here](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-category-filtering.htm#ESRI_SECTION1_502B3FE2028145D7B189C25B1A00E17B)

@@ -334,3 +333,3 @@ `within(bounds <L.LatLngBounds>)` | A bounding box to search for suggestions in.

```js
L.esri.Geocoding.Tasks.suggest().text('trea').nearby([45,-121], 5000).run(function(error, response){
L.esri.Geocoding.suggest().text('trea').nearby([45,-121], 5000).run(function(error, response){
// response matches the suggest API response https://developers.arcgis.com/rest/geocode/api-reference/geocoding-suggest.htm#ESRI_SECTION1_FC3884A45AD24E62BD11C9888F1392DB

@@ -340,3 +339,3 @@ });

## L.esri.Geocoding.Tasks.ReverseGeocode
## L.esri.Geocoding.reverseGeocode

@@ -347,3 +346,3 @@ ### Constructor

--- | ---
`L.esri.Geocoding.Tasks.reverseGeocode(options)` | Creates a new ReverseGeocode task. `L.esri.Geocoding.WorldGeocodingService` can be used as a reference to the [ArcGIS World Geocoder](https://developers.arcgis.com/rest/geocode/api-reference/overview-world-geocoding-service.htm).
`L.esri.Geocoding.reverseGeocode(options)` | Creates a new ReverseGeocode task. `L.esri.Geocoding.WorldGeocodingService` can be used as a reference to the [ArcGIS World Geocoder](https://developers.arcgis.com/rest/geocode/api-reference/overview-world-geocoding-service.htm).

@@ -366,3 +365,3 @@ ### Options

```js
L.esri.Geocoding.Tasks.reverseGeocode().latlng([48.8583, 2.2945]).run(function(error, result, response){
L.esri.Geocoding.reverseGeocode().latlng([48.8583, 2.2945]).run(function(error, result, response){
// callback is called with error, result, and response.

@@ -382,6 +381,2 @@ // result.latlng contains the latlng of the located address

## Dependencies
Esri Leaflet Geocoder relies on the minimal Esri Leaflet Core which handles abstraction for requests and authentication when neccessary. You can find out more about the Esri Leaflet Core from the [Esri Leaflet Quickstart](http://esri.github.io/esri-leaflet/examples/).
## Resources

@@ -409,3 +404,3 @@

3. You are allowed to store the results of any geocoding you do if you pass the `forStorage` flag and a valid access token.
4. If you use this library in a revenue generating application or for goverment use you must upgrade to a paid account. You are not allowed to generate revenue while on a free plan.
4. If you use this library in a revenue generating application or for government use you must upgrade to a paid account. You are not allowed to generate revenue while on a free plan.

@@ -412,0 +407,0 @@ This information is from the [ArcGIS for Developers Terms of Use FAQ](https://developers.arcgis.com/en/terms/faq/) and the [ArcGIS Online World Geocoder documentation](http://resources.arcgis.com/en/help/arcgis-rest-api/#/Single_input_field_geocoding/02r300000015000000/)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc