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 1.0.0-rc.2 to 1.0.0-rc.3

bower.json

23

CHANGELOG.md
# Changelog
## Release Candidate 1
Please read through the docs and changes list carefully. There has been a major refactoring.
** Breaking Changes **
* Namespacing has changed. All methods and classes are now under `L.esri.Geocoding`. `L.esri.Geocoding` organizes everything into `Controls`, `Services`, and `Tasks`.
* `GeocodeService` has been rewritten from scratch to mirror the Esri Leaflet service style that returns tasks.
* `GeocodeService.suggest`, `GeocodeService.geocode` and `GeocodeService.reverse` all return their respective tasks.
** Changes **
* New tasks for `Suggest`, `Geocode` and `ReverseGeocode` that mirror the Esri Leaflet task structure.
* `L.esri.Geocoding.Controls.Geosearch` can now search multiple providers.
* Available on NPM and Bower
* Wrapped as a CommonJS module
* Wrapped as an AMD module
* Basic unit tests
* TravisCI support
* Source maps for compressed builds
## Beta 5

@@ -51,2 +72,2 @@

* Inital alpha release
* Inital alpha release

182

dist/esri-leaflet-geocoder-src.js

@@ -1,3 +0,3 @@

/*! esri-leaflet-geocoder - v1.0.0-rc.2 - 2014-10-26
* Copyright (c) 2014 Environmental Systems Research Institute, Inc.
/*! esri-leaflet-geocoder - v1.0.0-rc.3 - 2015-01-06
* Copyright (c) 2015 Environmental Systems Research Institute, Inc.
* Apache 2.0 License */

@@ -23,4 +23,6 @@

}(function (L, Esri) {
var protocol = window.location.protocol === 'https:' ? 'https:' : 'http:';
var EsriLeafletGeocoding = {
WorldGeocodingService: '//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/',
WorldGeocodingService: protocol + '//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/',
Tasks: {},

@@ -68,6 +70,12 @@ Services: {},

initialize: function(options){
options = options || {};
options.url = options.url || EsriLeafletGeocoding.WorldGeocodingService;
Esri.Tasks.Task.prototype.initialize.call(this, options);
},
within: function(bounds){
bounds = L.latLngBounds(bounds);
console.log(bounds);
this.params.bbox = Esri.Util.boundsToExtent(bounds);
return this;
},

@@ -79,2 +87,3 @@

this.params.distance = Math.min(Math.max(radius, 2000), 50000);
return this;
},

@@ -137,4 +146,4 @@

EsriLeafletGeocoding.Tasks.geocode = function(url, options){
return new EsriLeafletGeocoding.Tasks.Geocode(url, options);
EsriLeafletGeocoding.Tasks.geocode = function(options){
return new EsriLeafletGeocoding.Tasks.Geocode(options);
};

@@ -148,2 +157,3 @@

},
setters: {

@@ -154,2 +164,8 @@ 'distance': 'distance',

initialize: function(options){
options = options || {};
options.url = options.url || EsriLeafletGeocoding.WorldGeocodingService;
Esri.Tasks.Task.prototype.initialize.call(this, options);
},
latlng: function (latlng) {

@@ -179,4 +195,4 @@ latlng = L.latLng(latlng);

EsriLeafletGeocoding.Tasks.reverseGeocode = function(url, options){
return new EsriLeafletGeocoding.Tasks.ReverseGeocode(url, options);
EsriLeafletGeocoding.Tasks.reverseGeocode = function(options){
return new EsriLeafletGeocoding.Tasks.ReverseGeocode(options);
};

@@ -194,2 +210,9 @@

initialize: function(options){
options = options || {};
options.url = options.url || EsriLeafletGeocoding.WorldGeocodingService;
Esri.Tasks.Task.prototype.initialize.call(this, options);
},
within: function(bounds){

@@ -220,15 +243,14 @@ bounds = L.latLngBounds(bounds);

EsriLeafletGeocoding.Tasks.suggest = function(url, options){
return new EsriLeafletGeocoding.Tasks.Suggest(url, options);
EsriLeafletGeocoding.Tasks.suggest = function(options){
return new EsriLeafletGeocoding.Tasks.Suggest(options);
};
EsriLeafletGeocoding.Services.Geocoding = Esri.Services.Service.extend({
includes: L.Mixin.Events,
initialize: function (url, options) {
url = (typeof url === 'string') ? url : EsriLeafletGeocoding.WorldGeocodingService;
options = (typeof url === 'object') ? url : (options || {});
this.url = Esri.Util.cleanUrl(url);
L.Util.setOptions(this, options);
Esri.Services.Service.prototype.initialize.call(this, url, options);
initialize: function(options){
options = options || {};
options.url = options.url || EsriLeafletGeocoding.WorldGeocodingService;
Esri.Services.Service.prototype.initialize.call(this, options);
},

@@ -245,4 +267,5 @@

suggest: function(){
if(this.url !== EsriLeafletGeocoding.WorldGeocodingService && console && console.warn){
if(this.options.url !== EsriLeafletGeocoding.WorldGeocodingService && console && console.warn){
console.warn('Only the ArcGIS Online World Geocoder supports suggestions');
return;
}

@@ -253,4 +276,4 @@ return new EsriLeafletGeocoding.Tasks.Suggest(this);

EsriLeafletGeocoding.Services.geocoding = function(url, options){
return new EsriLeafletGeocoding.Services.Geocoding(url, options);
EsriLeafletGeocoding.Services.geocoding = function(options){
return new EsriLeafletGeocoding.Services.Geocoding(options);
};

@@ -270,3 +293,4 @@

providers: [],
placeholder: 'Search for places or addresses'
placeholder: 'Search for places or addresses',
title: 'Location Search'
},

@@ -372,5 +396,5 @@

if(provider.nodes){
for (i = 0; i < provider.nodes.length; i++) {
if(provider.nodes[i].parentElement){
this._suggestions.removeChild(provider.nodes[i]);
for (var k = 0; k < provider.nodes.length; k++) {
if(provider.nodes[k].parentElement){
this._suggestions.removeChild(provider.nodes[k]);
}

@@ -394,4 +418,2 @@ }

var provider = this.options.providers[i];
console.log(!!provider);
console.log(provider.options.label);
var request = provider.suggestions(text, this._searchBounds(), createCallback(text, provider));

@@ -421,2 +443,10 @@ this._pendingSuggestions.push(request);

this._suggestions.style.display = 'block';
// set the maxHeight of the suggestions box to
// map height
// - suggestions offset (distance from top of suggestions to top of control)
// - control offset (distance from top of control to top of map)
// - 10 (extra padding)
this._suggestions.style.maxHeight = (this._map.getSize().y - this._suggestions.offsetTop - this._wrapper.offsetTop - 10) + 'px';
var nodes = [];

@@ -447,3 +477,2 @@ var list;

nodes.push(list);
console.log(nodes.length);
return nodes;

@@ -484,2 +513,6 @@ },

}
if(!this._map.scrollWheelZoom.enabled() && this._map.options.scrollWheelZoom){
this._map.scrollWheelZoom.enable();
}
},

@@ -496,2 +529,3 @@

this._input = L.DomUtil.create('input', 'geocoder-control-input leaflet-bar', this._wrapper);
this._input.title = this.options.title;

@@ -620,2 +654,16 @@ this._suggestions = L.DomUtil.create('div', 'geocoder-control-suggestions leaflet-bar', this._wrapper);

// when mouse moves over suggestions disable scroll wheel zoom if its enabled
L.DomEvent.addListener(this._suggestions, 'mouseover', function(e){
if(map.scrollWheelZoom.enabled() && map.options.scrollWheelZoom){
map.scrollWheelZoom.disable();
}
});
// when mouse moves leaves suggestions enable scroll wheel zoom if its disabled
L.DomEvent.addListener(this._suggestions, 'mouseout', function(e){
if(!map.scrollWheelZoom.enabled() && map.options.scrollWheelZoom){
map.scrollWheelZoom.enable();
}
});
return this._wrapper;

@@ -637,5 +685,6 @@ },

options: {
label: "Places and Addresses",
label: 'Places and Addresses',
maxResults: 5
},
suggestions: function(text, bounds, callback){

@@ -774,3 +823,3 @@ var request = this.suggest().text(text);

var field = this.options.searchFields[i];
queryString.push(field + " LIKE '%" + text + "%'"); // jshint ignore:line
queryString.push(field + ' LIKE \'%' + text + '%\'');
}

@@ -819,3 +868,3 @@

options: {
layer: 0,
layers: [0],
label: 'Map Service',

@@ -825,3 +874,3 @@ bufferRadius: 1000,

formatSuggestion: function(feature){
return feature.properties[this.options.searchFields[0]];
return feature.properties[feature.displayFieldName] + ' <small>' + feature.layerName + '</small>';
}

@@ -831,25 +880,28 @@ },

L.esri.Services.MapService.prototype.initialize.call(this, url, options);
this._getIdField();
this._getIdFields();
},
suggestions: function(text, bounds, callback){
var request = this.find().text(text).returnGeometry(false).layers(this.options.layer);
var request = this.find().text(text).fields(this.options.searchFields).returnGeometry(false).layers(this.options.layers);
if (this._idField) {
request.fields(this.options.searchFields);
}
return request.run(function(error, results){
return request.run(function(error, results, raw){
var suggestions = [];
if(this._idField && !error){
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];
suggestions.push({
text: this.options.formatSuggestion.call(this, feature),
magicKey: feature.properties[this._idField]
});
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());

@@ -863,17 +915,23 @@ }, this);

if(key){
request = this.query().layer(this.options.layer).featureIds(key);
var featureId = key.split(':')[0];
var layer = key.split(':')[1];
request = this.query().layer(layer).featureIds(featureId);
} else {
request = this.find().text(text).contains(false).layers(this.options.layer);
request = this.find().text(text).fields(this.options.searchFields).contains(false).layers(this.options.layers);
}
if(this._idField){
request.fields([this.options.searchFields, this.options._idField]);
}
return request.run(function(error, features){
if(this._idField && !error){
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];
if(feature){
layer = (layer) ? layer : response.results[i].layerId;
if(feature && layer !== undefined) {
var bounds = this._featureBounds(feature);
var idField = this._idFields[layer];
feature.layerId = layer;
feature.layerName = this._layerNames[layer];
feature.displayFieldName = this._displayFields[layer];
var result = {

@@ -901,9 +959,10 @@ latlng: bounds.getCenter(),

},
_getIdField: function(){
this.get(this.options.layer, {}, function(error, metadata){
_layerMetadataCallback: function(layerid){
return L.Util.bind(function(error, metadata){
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._idField = field.name;
this.options.searchFields.push(field.name);
this._idFields[layerid] = field.name;
break;

@@ -913,2 +972,11 @@ }

}, 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));
}
}

@@ -915,0 +983,0 @@ });

@@ -1,3 +0,3 @@

/*! esri-leaflet-geocoder - v1.0.0-rc.2 - 2014-10-26
* Copyright (c) 2014 Environmental Systems Research Institute, Inc.
/*! esri-leaflet-geocoder - v1.0.0-rc.3 - 2015-01-06
* Copyright (c) 2015 Environmental Systems Research Institute, Inc.
* Apache 2.0 License */

@@ -24,3 +24,3 @@

var EsriLeafletGeocoding={WorldGeocodingService:"//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/",Tasks:{},Services:{},Controls:{}};if("undefined"!=typeof window&&window.L&&window.L.esri&&(window.L.esri.Geocoding=EsriLeafletGeocoding),!Esri)var Esri=window.L.esri;EsriLeafletGeocoding.Tasks.Geocode=Esri.Tasks.Task.extend({path:"find",params:{outSr:4326,forStorage:!1,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"},within:function(a){a=L.latLngBounds(a),console.log(a),this.params.bbox=Esri.Util.boundsToExtent(a)},nearby:function(a,b){a=L.latLng(a),this.params.location=a.lng+","+a.lat,this.params.distance=Math.min(Math.max(b,2e3),5e4)},run:function(a,b){return this.path=this.params.text?"find":"findAddressCandidates","findAddressCandidates"===this.path&&this.params.bbox&&(this.params.searchExtent=this.params.bbox,delete this.params.bbox),this.request(function(c,d){var e="find"===this.path?this._processFindResponse:this._processFindAddressCandidatesResponse,f=c?void 0:e(d);a.call(b,c,{results:f},d)},this)},_processFindResponse:function(a){for(var b=[],c=0;c<a.locations.length;c++){var d=a.locations[c],e=Esri.Util.extentToBounds(d.extent);b.push({text:d.name,bounds:e,score:d.feature.attributes.Score,latlng:new L.LatLng(d.feature.geometry.y,d.feature.geometry.x),properties:d.feature.attributes})}return b},_processFindAddressCandidatesResponse:function(a){for(var b=[],c=0;c<a.candidates.length;c++){var d=a.candidates[c],e=Esri.Util.extentToBounds(d.extent);b.push({text:d.address,bounds:e,score:d.score,latlng:new L.LatLng(d.location.y,d.location.x),properties:d.attributes})}return b}}),EsriLeafletGeocoding.Tasks.geocode=function(a,b){return new EsriLeafletGeocoding.Tasks.Geocode(a,b)},EsriLeafletGeocoding.Tasks.ReverseGeocode=Esri.Tasks.Task.extend({path:"reverseGeocode",params:{outSR:4326},setters:{distance:"distance",language:"language"},latlng:function(a){return a=L.latLng(a),this.params.location=a.lng+","+a.lat,this},run:function(a,b){return this.request(function(c,d){var e;e=c?void 0:{latlng:new L.LatLng(d.location.y,d.location.x),address:d.address},a.call(b,c,e,d)},this)}}),EsriLeafletGeocoding.Tasks.reverseGeocode=function(a,b){return new EsriLeafletGeocoding.Tasks.ReverseGeocode(a,b)},EsriLeafletGeocoding.Tasks.Suggest=Esri.Tasks.Task.extend({path:"suggest",params:{},setters:{text:"text",category:"category"},within:function(a){a=L.latLngBounds(a),a=a.pad(.5);var b=a.getCenter(),c=a.getNorthWest();return this.params.location=b.lng+","+b.lat,this.params.distance=Math.min(Math.max(b.distanceTo(c),2e3),5e4),this},nearby:function(a,b){return a=L.latLng(a),this.params.location=a.lng+","+a.lat,this.params.distance=Math.min(Math.max(b,2e3),5e4),this},run:function(a,b){return this.request(function(c,d){a.call(b,c,d,d)},this)}}),EsriLeafletGeocoding.Tasks.suggest=function(a,b){return new EsriLeafletGeocoding.Tasks.Suggest(a,b)},EsriLeafletGeocoding.Services.Geocoding=Esri.Services.Service.extend({includes:L.Mixin.Events,initialize:function(a,b){a="string"==typeof a?a:EsriLeafletGeocoding.WorldGeocodingService,b="object"==typeof a?a:b||{},this.url=Esri.Util.cleanUrl(a),L.Util.setOptions(this,b),Esri.Services.Service.prototype.initialize.call(this,a,b)},geocode:function(){return new EsriLeafletGeocoding.Tasks.Geocode(this)},reverse:function(){return new EsriLeafletGeocoding.Tasks.ReverseGeocode(this)},suggest:function(){return this.url!==EsriLeafletGeocoding.WorldGeocodingService&&console&&console.warn&&console.warn("Only the ArcGIS Online World Geocoder supports suggestions"),new EsriLeafletGeocoding.Tasks.Suggest(this)}}),EsriLeafletGeocoding.Services.geocoding=function(a,b){return new EsriLeafletGeocoding.Services.Geocoding(a,b)},EsriLeafletGeocoding.Controls.Geosearch=L.Control.extend({includes:L.Mixin.Events,options:{position:"topleft",zoomToResult:!0,useMapBounds:12,collapseAfterResult:!0,expanded:!1,forStorage:!1,allowMultipleResults:!0,useArcgisWorldGeocoder:!0,providers:[],placeholder:"Search for places or addresses"},initialize:function(a){if(L.Util.setOptions(this,a),this.options.useArcgisWorldGeocoder){var b=new EsriLeafletGeocoding.Controls.Geosearch.Providers.ArcGISOnline;this.options.providers.push(b)}if(this.options.maxResults)for(var c=0;c<this.options.providers.length;c++)this.options.providers[c].options.maxResults=this.options.maxResults;this._pendingSuggestions=[]},_geocode:function(a,b,c){var d,e=0,f=[],g=L.Util.bind(function(b,c){e--,c&&(f=f.concat(c)),0>=e&&(d=this._boundsFromResults(f),this.fire("results",{results:f,bounds:d,latlng:d?d.getCenter():void 0,text:a}),this.options.zoomToResult&&d&&this._map.fitBounds(d),L.DomUtil.removeClass(this._input,"geocoder-control-loading"),this.fire("load"),this.clear(),this._input.blur())},this);if(b)e++,c.results(a,b,this._searchBounds(),g);else for(var h=0;h<this.options.providers.length;h++)e++,this.options.providers[h].results(a,b,this._searchBounds(),g)},_suggest:function(a){L.DomUtil.addClass(this._input,"geocoder-control-loading");var b=this.options.providers.length,c=L.Util.bind(function(a,c){return L.Util.bind(function(d,e){var f;if(b-=1,this._input.value<2)return this._suggestions.innerHTML="",void(this._suggestions.style.display="none");if(e)for(f=0;f<e.length;f++)e[f].provider=c;if(c._lastRender!==a&&c.nodes){for(f=0;f<c.nodes.length;f++)c.nodes[f].parentElement&&this._suggestions.removeChild(c.nodes[f]);c.nodes=[]}if(e.length&&this._input.value===a){if(c.nodes)for(f=0;f<c.nodes.length;f++)c.nodes[f].parentElement&&this._suggestions.removeChild(c.nodes[f]);c._lastRender=a,c.nodes=this._renderSuggestions(e)}0===b&&L.DomUtil.removeClass(this._input,"geocoder-control-loading")},this)},this);this._pendingSuggestions=[];for(var d=0;d<this.options.providers.length;d++){var e=this.options.providers[d];console.log(!!e),console.log(e.options.label);var f=e.suggestions(a,this._searchBounds(),c(a,e));this._pendingSuggestions.push(f)}},_searchBounds:function(){return this.options.useMapBounds===!1?null:this.options.useMapBounds===!0?this._map.getBounds():this.options.useMapBounds<=this._map.getZoom()?this._map.getBounds():null},_renderSuggestions:function(a){var b;this._suggestions.style.display="block";for(var c,d,e=[],f=0;f<a.length;f++){var g=a[f];!d&&this.options.providers.length>1&&b!==g.provider.options.label&&(d=L.DomUtil.create("span","geocoder-control-header",this._suggestions),d.textContent=g.provider.options.label,d.innerText=g.provider.options.label,b=g.provider.options.label,e.push(d)),c||(c=L.DomUtil.create("ul","geocoder-control-list",this._suggestions));var h=L.DomUtil.create("li","geocoder-control-suggestion",c);h.innerHTML=g.text,h.provider=g.provider,h["data-magic-key"]=g.magicKey}return e.push(c),console.log(e.length),e},_boundsFromResults:function(a){if(a.length){for(var b=new L.LatLngBounds([0,0],[0,0]),c=new L.LatLngBounds,d=a.length-1;d>=0;d--){var e=a[d];e.bounds.isValid()&&!e.bounds.equals(b)&&c.extend(e.bounds),c.extend(e.latlng)}return c}},clear:function(){this._suggestions.innerHTML="",this._suggestions.style.display="none",this._input.value="",this.options.collapseAfterResult&&(this._input.placeholder="",L.DomUtil.removeClass(this._wrapper,"geocoder-control-expanded"))},onAdd:function(a){return this._map=a,a.attributionControl&&a.attributionControl.addAttribution("Geocoding by Esri"),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._suggestions=L.DomUtil.create("div","geocoder-control-suggestions leaflet-bar",this._wrapper),L.DomEvent.addListener(this._input,"focus",function(){this._input.placeholder=this.options.placeholder,L.DomUtil.addClass(this._wrapper,"geocoder-control-expanded")},this),L.DomEvent.addListener(this._wrapper,"click",function(){L.DomUtil.addClass(this._wrapper,"geocoder-control-expanded"),this._input.focus()},this),L.DomEvent.addListener(this._suggestions,"mousedown",function(a){var b=a.target||a.srcElement;this._geocode(b.innerHTML,b["data-magic-key"],b.provider),this.clear()},this),L.DomEvent.addListener(this._input,"blur",function(){this.clear()},this),L.DomEvent.addListener(this._input,"keydown",function(a){L.DomUtil.addClass(this._wrapper,"geocoder-control-expanded");for(var b,c=this._suggestions.querySelectorAll(".geocoder-control-suggestion"),d=this._suggestions.querySelectorAll(".geocoder-control-selected")[0],e=0;e<c.length;e++)if(c[e]===d){b=e;break}switch(a.keyCode){case 13:d?(this._geocode(d.innerHTML,d["data-magic-key"],d.provider),this.clear()):this.options.allowMultipleResults?(this._geocode(this._input.value,void 0),this.clear()):L.DomUtil.addClass(c[0],"geocoder-control-selected"),L.DomEvent.preventDefault(a);break;case 38:d&&L.DomUtil.removeClass(d,"geocoder-control-selected");var f=c[b-1];d&&f?L.DomUtil.addClass(f,"geocoder-control-selected"):L.DomUtil.addClass(c[c.length-1],"geocoder-control-selected"),L.DomEvent.preventDefault(a);break;case 40:d&&L.DomUtil.removeClass(d,"geocoder-control-selected");var g=c[b+1];d&&g?L.DomUtil.addClass(g,"geocoder-control-selected"):L.DomUtil.addClass(c[0],"geocoder-control-selected"),L.DomEvent.preventDefault(a);break;default:for(var h=0;h<this._pendingSuggestions.length;h++){var i=this._pendingSuggestions[h];i&&i.abort&&!i.id?i.abort():i.id&&window._EsriLeafletCallbacks[i.id].abort&&window._EsriLeafletCallbacks[i.id].abort()}}},this),L.DomEvent.addListener(this._input,"keyup",L.Util.limitExecByInterval(function(a){var b=a.which||a.keyCode,c=(a.target||a.srcElement).value;return c.length<2?(this._suggestions.innerHTML="",this._suggestions.style.display="none",void L.DomUtil.removeClass(this._input,"geocoder-control-loading")):27===b?(this._suggestions.innerHTML="",void(this._suggestions.style.display="none")):void(13!==b&&38!==b&&40!==b&&this._input.value!==this._lastValue&&(this._lastValue=this._input.value,this._suggest(c)))},50,this),this),L.DomEvent.disableClickPropagation(this._wrapper),this._wrapper},onRemove:function(a){a.attributionControl.removeAttribution("Geocoding by Esri")}}),EsriLeafletGeocoding.Controls.geosearch=function(a){return new EsriLeafletGeocoding.Controls.Geosearch(a)},EsriLeafletGeocoding.Controls.Geosearch.Providers={},EsriLeafletGeocoding.Controls.Geosearch.Providers.ArcGISOnline=EsriLeafletGeocoding.Services.Geocoding.extend({options:{label:"Places and Addresses",maxResults:5},suggestions:function(a,b,c){var d=this.suggest().text(a);return b&&d.within(b),d.run(function(a,b,d){var e=[];if(!a)for(;d.suggestions.length&&e.length<=this.options.maxResults-1;){var f=d.suggestions.shift();f.isCollection||e.push({text:f.text,magicKey:f.magicKey})}c(a,e)},this)},results:function(a,b,c,d){var e=this.geocode().text(a);return b?e.key(b):e.maxLocations(this.options.maxResults),c&&e.within(c),this.options.forStorage&&e.forStorage(!0),e.run(function(a,b){d(a,b.results)},this)}}),EsriLeafletGeocoding.Controls.Geosearch.Providers.FeatureLayer=L.esri.Services.FeatureLayer.extend({options:{label:"Feature Layer",maxResults:5,bufferRadius:1e3,formatSuggestion:function(a){return a.properties[this.options.searchFields[0]]}},intialize:function(a,b){L.esri.Services.FeatureLayer.prototype.call(this,a,b),L.Util.setOptions(this,b),"string"==typeof this.options.searchFields&&(this.options.searchFields=[this.options.searchFields])},suggestions:function(a,b,c){var d=this.query().where(this._buildQuery(a)).returnGeometry(!1);b&&d.intersects(b),this.options.idField&&d.fields([this.options.idField].concat(this.options.searchFields));var e=d.run(function(a,b,d){if(a)c(a,[]);else{this.options.idField=d.objectIdFieldName;for(var e=[],f=Math.min(b.features.length,this.options.maxResults),g=0;f>g;g++){var h=b.features[g];e.push({text:this.options.formatSuggestion.call(this,h),magicKey:h.id})}c(a,e.slice(0,this.options.maxResults).reverse())}},this);return e},results:function(a,b,c,d){var e=this.query();return b?e.featureIds([b]):e.where(this._buildQuery(a)),c&&e.within(c),e.run(L.Util.bind(function(a,b){for(var c=[],e=0;e<b.features.length;e++){var f=b.features[e];if(f){var g=this._featureBounds(f),h={latlng:g.getCenter(),bounds:g,text:this.options.formatSuggestion.call(this,f),properties:f.properties};c.push(h)}}d(a,c)},this))},_buildQuery:function(a){for(var b=[],c=this.options.searchFields.length-1;c>=0;c--){var d=this.options.searchFields[c];b.push(d+" LIKE '%"+a+"%'")}return b.join(" OR ")},_featureBounds:function(a){var b=L.geoJson(a);if("Point"===a.geometry.type){var c=b.getBounds().getCenter();return new L.Circle(c,this.options.bufferRadius).getBounds()}return b.getBounds()}}),EsriLeafletGeocoding.Controls.Geosearch.Providers.GeocodeService=EsriLeafletGeocoding.Services.Geocoding.extend({options:{label:"Geocode Server",maxResults:5},suggestions:function(a,b,c){return c(void 0,[]),!1},results:function(a,b,c,d){var e=this.geocode().text(a);return e.maxLocations(this.options.maxResults),c&&e.within(c),e.run(function(a,b){d(a,b.results)},this)}}),EsriLeafletGeocoding.Controls.Geosearch.Providers.MapService=L.esri.Services.MapService.extend({options:{layer:0,label:"Map Service",bufferRadius:1e3,maxResults:5,formatSuggestion:function(a){return a.properties[this.options.searchFields[0]]}},initialize:function(a,b){L.esri.Services.MapService.prototype.initialize.call(this,a,b),this._getIdField()},suggestions:function(a,b,c){var d=this.find().text(a).returnGeometry(!1).layers(this.options.layer);return this._idField&&d.fields(this.options.searchFields),d.run(function(a,b){var d=[];if(this._idField&&!a)for(var e=Math.min(this.options.maxResults,b.features.length),f=0;e>f;f++){var g=b.features[f];d.push({text:this.options.formatSuggestion.call(this,g),magicKey:g.properties[this._idField]})}c(a,d.reverse())},this)},results:function(a,b,c,d){var e,f=[];return e=b?this.query().layer(this.options.layer).featureIds(b):this.find().text(a).contains(!1).layers(this.options.layer),this._idField&&e.fields([this.options.searchFields,this.options._idField]),e.run(function(a,b){if(this._idField&&!a)for(var c=0;c<b.features.length;c++){var e=b.features[c];if(e){var g=this._featureBounds(e),h={latlng:g.getCenter(),bounds:g,text:this.options.formatSuggestion.call(this,e),properties:e.properties};f.push(h)}}d(a,f.reverse())},this)},_featureBounds:function(a){var b=L.geoJson(a);if("Point"===a.geometry.type){var c=b.getBounds().getCenter();return new L.Circle(c,this.options.bufferRadius).getBounds()}return b.getBounds()},_getIdField:function(){this.get(this.options.layer,{},function(a,b){for(var c=0;c<b.fields.length;c++){var d=b.fields[c];if("esriFieldTypeOID"===d.type){this._idField=d.name,this.options.searchFields.push(d.name);break}}},this)}});
var protocol="https:"===window.location.protocol?"https:":"http:",EsriLeafletGeocoding={WorldGeocodingService:protocol+"//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/",Tasks:{},Services:{},Controls:{}};if("undefined"!=typeof window&&window.L&&window.L.esri&&(window.L.esri.Geocoding=EsriLeafletGeocoding),!Esri)var Esri=window.L.esri;EsriLeafletGeocoding.Tasks.Geocode=Esri.Tasks.Task.extend({path:"find",params:{outSr:4326,forStorage:!1,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(a){a=a||{},a.url=a.url||EsriLeafletGeocoding.WorldGeocodingService,Esri.Tasks.Task.prototype.initialize.call(this,a)},within:function(a){return a=L.latLngBounds(a),this.params.bbox=Esri.Util.boundsToExtent(a),this},nearby:function(a,b){return a=L.latLng(a),this.params.location=a.lng+","+a.lat,this.params.distance=Math.min(Math.max(b,2e3),5e4),this},run:function(a,b){return this.path=this.params.text?"find":"findAddressCandidates","findAddressCandidates"===this.path&&this.params.bbox&&(this.params.searchExtent=this.params.bbox,delete this.params.bbox),this.request(function(c,d){var e="find"===this.path?this._processFindResponse:this._processFindAddressCandidatesResponse,f=c?void 0:e(d);a.call(b,c,{results:f},d)},this)},_processFindResponse:function(a){for(var b=[],c=0;c<a.locations.length;c++){var d=a.locations[c],e=Esri.Util.extentToBounds(d.extent);b.push({text:d.name,bounds:e,score:d.feature.attributes.Score,latlng:new L.LatLng(d.feature.geometry.y,d.feature.geometry.x),properties:d.feature.attributes})}return b},_processFindAddressCandidatesResponse:function(a){for(var b=[],c=0;c<a.candidates.length;c++){var d=a.candidates[c],e=Esri.Util.extentToBounds(d.extent);b.push({text:d.address,bounds:e,score:d.score,latlng:new L.LatLng(d.location.y,d.location.x),properties:d.attributes})}return b}}),EsriLeafletGeocoding.Tasks.geocode=function(a){return new EsriLeafletGeocoding.Tasks.Geocode(a)},EsriLeafletGeocoding.Tasks.ReverseGeocode=Esri.Tasks.Task.extend({path:"reverseGeocode",params:{outSR:4326},setters:{distance:"distance",language:"language"},initialize:function(a){a=a||{},a.url=a.url||EsriLeafletGeocoding.WorldGeocodingService,Esri.Tasks.Task.prototype.initialize.call(this,a)},latlng:function(a){return a=L.latLng(a),this.params.location=a.lng+","+a.lat,this},run:function(a,b){return this.request(function(c,d){var e;e=c?void 0:{latlng:new L.LatLng(d.location.y,d.location.x),address:d.address},a.call(b,c,e,d)},this)}}),EsriLeafletGeocoding.Tasks.reverseGeocode=function(a){return new EsriLeafletGeocoding.Tasks.ReverseGeocode(a)},EsriLeafletGeocoding.Tasks.Suggest=Esri.Tasks.Task.extend({path:"suggest",params:{},setters:{text:"text",category:"category"},initialize:function(a){a=a||{},a.url=a.url||EsriLeafletGeocoding.WorldGeocodingService,Esri.Tasks.Task.prototype.initialize.call(this,a)},within:function(a){a=L.latLngBounds(a),a=a.pad(.5);var b=a.getCenter(),c=a.getNorthWest();return this.params.location=b.lng+","+b.lat,this.params.distance=Math.min(Math.max(b.distanceTo(c),2e3),5e4),this},nearby:function(a,b){return a=L.latLng(a),this.params.location=a.lng+","+a.lat,this.params.distance=Math.min(Math.max(b,2e3),5e4),this},run:function(a,b){return this.request(function(c,d){a.call(b,c,d,d)},this)}}),EsriLeafletGeocoding.Tasks.suggest=function(a){return new EsriLeafletGeocoding.Tasks.Suggest(a)},EsriLeafletGeocoding.Services.Geocoding=Esri.Services.Service.extend({includes:L.Mixin.Events,initialize:function(a){a=a||{},a.url=a.url||EsriLeafletGeocoding.WorldGeocodingService,Esri.Services.Service.prototype.initialize.call(this,a)},geocode:function(){return new EsriLeafletGeocoding.Tasks.Geocode(this)},reverse:function(){return new EsriLeafletGeocoding.Tasks.ReverseGeocode(this)},suggest:function(){return this.options.url!==EsriLeafletGeocoding.WorldGeocodingService&&console&&console.warn?void console.warn("Only the ArcGIS Online World Geocoder supports suggestions"):new EsriLeafletGeocoding.Tasks.Suggest(this)}}),EsriLeafletGeocoding.Services.geocoding=function(a){return new EsriLeafletGeocoding.Services.Geocoding(a)},EsriLeafletGeocoding.Controls.Geosearch=L.Control.extend({includes:L.Mixin.Events,options:{position:"topleft",zoomToResult:!0,useMapBounds:12,collapseAfterResult:!0,expanded:!1,forStorage:!1,allowMultipleResults:!0,useArcgisWorldGeocoder:!0,providers:[],placeholder:"Search for places or addresses",title:"Location Search"},initialize:function(a){if(L.Util.setOptions(this,a),this.options.useArcgisWorldGeocoder){var b=new EsriLeafletGeocoding.Controls.Geosearch.Providers.ArcGISOnline;this.options.providers.push(b)}if(this.options.maxResults)for(var c=0;c<this.options.providers.length;c++)this.options.providers[c].options.maxResults=this.options.maxResults;this._pendingSuggestions=[]},_geocode:function(a,b,c){var d,e=0,f=[],g=L.Util.bind(function(b,c){e--,c&&(f=f.concat(c)),0>=e&&(d=this._boundsFromResults(f),this.fire("results",{results:f,bounds:d,latlng:d?d.getCenter():void 0,text:a}),this.options.zoomToResult&&d&&this._map.fitBounds(d),L.DomUtil.removeClass(this._input,"geocoder-control-loading"),this.fire("load"),this.clear(),this._input.blur())},this);if(b)e++,c.results(a,b,this._searchBounds(),g);else for(var h=0;h<this.options.providers.length;h++)e++,this.options.providers[h].results(a,b,this._searchBounds(),g)},_suggest:function(a){L.DomUtil.addClass(this._input,"geocoder-control-loading");var b=this.options.providers.length,c=L.Util.bind(function(a,c){return L.Util.bind(function(d,e){var f;if(b-=1,this._input.value<2)return this._suggestions.innerHTML="",void(this._suggestions.style.display="none");if(e)for(f=0;f<e.length;f++)e[f].provider=c;if(c._lastRender!==a&&c.nodes){for(f=0;f<c.nodes.length;f++)c.nodes[f].parentElement&&this._suggestions.removeChild(c.nodes[f]);c.nodes=[]}if(e.length&&this._input.value===a){if(c.nodes)for(var g=0;g<c.nodes.length;g++)c.nodes[g].parentElement&&this._suggestions.removeChild(c.nodes[g]);c._lastRender=a,c.nodes=this._renderSuggestions(e)}0===b&&L.DomUtil.removeClass(this._input,"geocoder-control-loading")},this)},this);this._pendingSuggestions=[];for(var d=0;d<this.options.providers.length;d++){var e=this.options.providers[d],f=e.suggestions(a,this._searchBounds(),c(a,e));this._pendingSuggestions.push(f)}},_searchBounds:function(){return this.options.useMapBounds===!1?null:this.options.useMapBounds===!0?this._map.getBounds():this.options.useMapBounds<=this._map.getZoom()?this._map.getBounds():null},_renderSuggestions:function(a){var b;this._suggestions.style.display="block",this._suggestions.style.maxHeight=this._map.getSize().y-this._suggestions.offsetTop-this._wrapper.offsetTop-10+"px";for(var c,d,e=[],f=0;f<a.length;f++){var g=a[f];!d&&this.options.providers.length>1&&b!==g.provider.options.label&&(d=L.DomUtil.create("span","geocoder-control-header",this._suggestions),d.textContent=g.provider.options.label,d.innerText=g.provider.options.label,b=g.provider.options.label,e.push(d)),c||(c=L.DomUtil.create("ul","geocoder-control-list",this._suggestions));var h=L.DomUtil.create("li","geocoder-control-suggestion",c);h.innerHTML=g.text,h.provider=g.provider,h["data-magic-key"]=g.magicKey}return e.push(c),e},_boundsFromResults:function(a){if(a.length){for(var b=new L.LatLngBounds([0,0],[0,0]),c=new L.LatLngBounds,d=a.length-1;d>=0;d--){var e=a[d];e.bounds.isValid()&&!e.bounds.equals(b)&&c.extend(e.bounds),c.extend(e.latlng)}return c}},clear:function(){this._suggestions.innerHTML="",this._suggestions.style.display="none",this._input.value="",this.options.collapseAfterResult&&(this._input.placeholder="",L.DomUtil.removeClass(this._wrapper,"geocoder-control-expanded")),!this._map.scrollWheelZoom.enabled()&&this._map.options.scrollWheelZoom&&this._map.scrollWheelZoom.enable()},onAdd:function(a){return this._map=a,a.attributionControl&&a.attributionControl.addAttribution("Geocoding by Esri"),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(){this._input.placeholder=this.options.placeholder,L.DomUtil.addClass(this._wrapper,"geocoder-control-expanded")},this),L.DomEvent.addListener(this._wrapper,"click",function(){L.DomUtil.addClass(this._wrapper,"geocoder-control-expanded"),this._input.focus()},this),L.DomEvent.addListener(this._suggestions,"mousedown",function(a){var b=a.target||a.srcElement;this._geocode(b.innerHTML,b["data-magic-key"],b.provider),this.clear()},this),L.DomEvent.addListener(this._input,"blur",function(){this.clear()},this),L.DomEvent.addListener(this._input,"keydown",function(a){L.DomUtil.addClass(this._wrapper,"geocoder-control-expanded");for(var b,c=this._suggestions.querySelectorAll(".geocoder-control-suggestion"),d=this._suggestions.querySelectorAll(".geocoder-control-selected")[0],e=0;e<c.length;e++)if(c[e]===d){b=e;break}switch(a.keyCode){case 13:d?(this._geocode(d.innerHTML,d["data-magic-key"],d.provider),this.clear()):this.options.allowMultipleResults?(this._geocode(this._input.value,void 0),this.clear()):L.DomUtil.addClass(c[0],"geocoder-control-selected"),L.DomEvent.preventDefault(a);break;case 38:d&&L.DomUtil.removeClass(d,"geocoder-control-selected");var f=c[b-1];d&&f?L.DomUtil.addClass(f,"geocoder-control-selected"):L.DomUtil.addClass(c[c.length-1],"geocoder-control-selected"),L.DomEvent.preventDefault(a);break;case 40:d&&L.DomUtil.removeClass(d,"geocoder-control-selected");var g=c[b+1];d&&g?L.DomUtil.addClass(g,"geocoder-control-selected"):L.DomUtil.addClass(c[0],"geocoder-control-selected"),L.DomEvent.preventDefault(a);break;default:for(var h=0;h<this._pendingSuggestions.length;h++){var i=this._pendingSuggestions[h];i&&i.abort&&!i.id?i.abort():i.id&&window._EsriLeafletCallbacks[i.id].abort&&window._EsriLeafletCallbacks[i.id].abort()}}},this),L.DomEvent.addListener(this._input,"keyup",L.Util.limitExecByInterval(function(a){var b=a.which||a.keyCode,c=(a.target||a.srcElement).value;return c.length<2?(this._suggestions.innerHTML="",this._suggestions.style.display="none",void L.DomUtil.removeClass(this._input,"geocoder-control-loading")):27===b?(this._suggestions.innerHTML="",void(this._suggestions.style.display="none")):void(13!==b&&38!==b&&40!==b&&this._input.value!==this._lastValue&&(this._lastValue=this._input.value,this._suggest(c)))},50,this),this),L.DomEvent.disableClickPropagation(this._wrapper),L.DomEvent.addListener(this._suggestions,"mouseover",function(){a.scrollWheelZoom.enabled()&&a.options.scrollWheelZoom&&a.scrollWheelZoom.disable()}),L.DomEvent.addListener(this._suggestions,"mouseout",function(){!a.scrollWheelZoom.enabled()&&a.options.scrollWheelZoom&&a.scrollWheelZoom.enable()}),this._wrapper},onRemove:function(a){a.attributionControl.removeAttribution("Geocoding by Esri")}}),EsriLeafletGeocoding.Controls.geosearch=function(a){return new EsriLeafletGeocoding.Controls.Geosearch(a)},EsriLeafletGeocoding.Controls.Geosearch.Providers={},EsriLeafletGeocoding.Controls.Geosearch.Providers.ArcGISOnline=EsriLeafletGeocoding.Services.Geocoding.extend({options:{label:"Places and Addresses",maxResults:5},suggestions:function(a,b,c){var d=this.suggest().text(a);return b&&d.within(b),d.run(function(a,b,d){var e=[];if(!a)for(;d.suggestions.length&&e.length<=this.options.maxResults-1;){var f=d.suggestions.shift();f.isCollection||e.push({text:f.text,magicKey:f.magicKey})}c(a,e)},this)},results:function(a,b,c,d){var e=this.geocode().text(a);return b?e.key(b):e.maxLocations(this.options.maxResults),c&&e.within(c),this.options.forStorage&&e.forStorage(!0),e.run(function(a,b){d(a,b.results)},this)}}),EsriLeafletGeocoding.Controls.Geosearch.Providers.FeatureLayer=L.esri.Services.FeatureLayer.extend({options:{label:"Feature Layer",maxResults:5,bufferRadius:1e3,formatSuggestion:function(a){return a.properties[this.options.searchFields[0]]}},intialize:function(a,b){L.esri.Services.FeatureLayer.prototype.call(this,a,b),L.Util.setOptions(this,b),"string"==typeof this.options.searchFields&&(this.options.searchFields=[this.options.searchFields])},suggestions:function(a,b,c){var d=this.query().where(this._buildQuery(a)).returnGeometry(!1);b&&d.intersects(b),this.options.idField&&d.fields([this.options.idField].concat(this.options.searchFields));var e=d.run(function(a,b,d){if(a)c(a,[]);else{this.options.idField=d.objectIdFieldName;for(var e=[],f=Math.min(b.features.length,this.options.maxResults),g=0;f>g;g++){var h=b.features[g];e.push({text:this.options.formatSuggestion.call(this,h),magicKey:h.id})}c(a,e.slice(0,this.options.maxResults).reverse())}},this);return e},results:function(a,b,c,d){var e=this.query();return b?e.featureIds([b]):e.where(this._buildQuery(a)),c&&e.within(c),e.run(L.Util.bind(function(a,b){for(var c=[],e=0;e<b.features.length;e++){var f=b.features[e];if(f){var g=this._featureBounds(f),h={latlng:g.getCenter(),bounds:g,text:this.options.formatSuggestion.call(this,f),properties:f.properties};c.push(h)}}d(a,c)},this))},_buildQuery:function(a){for(var b=[],c=this.options.searchFields.length-1;c>=0;c--){var d=this.options.searchFields[c];b.push(d+" LIKE '%"+a+"%'")}return b.join(" OR ")},_featureBounds:function(a){var b=L.geoJson(a);if("Point"===a.geometry.type){var c=b.getBounds().getCenter();return new L.Circle(c,this.options.bufferRadius).getBounds()}return b.getBounds()}}),EsriLeafletGeocoding.Controls.Geosearch.Providers.GeocodeService=EsriLeafletGeocoding.Services.Geocoding.extend({options:{label:"Geocode Server",maxResults:5},suggestions:function(a,b,c){return c(void 0,[]),!1},results:function(a,b,c,d){var e=this.geocode().text(a);return e.maxLocations(this.options.maxResults),c&&e.within(c),e.run(function(a,b){d(a,b.results)},this)}}),EsriLeafletGeocoding.Controls.Geosearch.Providers.MapService=L.esri.Services.MapService.extend({options:{layers:[0],label:"Map Service",bufferRadius:1e3,maxResults:5,formatSuggestion:function(a){return a.properties[a.displayFieldName]+" <small>"+a.layerName+"</small>"}},initialize:function(a,b){L.esri.Services.MapService.prototype.initialize.call(this,a,b),this._getIdFields()},suggestions:function(a,b,c){var d=this.find().text(a).fields(this.options.searchFields).returnGeometry(!1).layers(this.options.layers);return d.run(function(a,b,d){var e=[];if(!a){var f=Math.min(this.options.maxResults,b.features.length);d.results=d.results.reverse();for(var g=0;f>g;g++){var h=b.features[g],i=d.results[g],j=i.layerId,k=this._idFields[j];h.layerId=j,h.layerName=this._layerNames[j],h.displayFieldName=this._displayFields[j],k&&e.push({text:this.options.formatSuggestion.call(this,h),magicKey:i.attributes[k]+":"+j})}}c(a,e.reverse())},this)},results:function(a,b,c,d){var e,f=[];if(b){var g=b.split(":")[0],h=b.split(":")[1];e=this.query().layer(h).featureIds(g)}else e=this.find().text(a).fields(this.options.searchFields).contains(!1).layers(this.options.layers);return e.run(function(a,b,c){if(!a){c.results&&(c.results=c.results.reverse());for(var e=0;e<b.features.length;e++){var g=b.features[e];if(h=h?h:c.results[e].layerId,g&&void 0!==h){{var i=this._featureBounds(g);this._idFields[h]}g.layerId=h,g.layerName=this._layerNames[h],g.displayFieldName=this._displayFields[h];var j={latlng:i.getCenter(),bounds:i,text:this.options.formatSuggestion.call(this,g),properties:g.properties};f.push(j)}}}d(a,f.reverse())},this)},_featureBounds:function(a){var b=L.geoJson(a);if("Point"===a.geometry.type){var c=b.getBounds().getCenter();return new L.Circle(c,this.options.bufferRadius).getBounds()}return b.getBounds()},_layerMetadataCallback:function(a){return L.Util.bind(function(b,c){this._displayFields[a]=c.displayField,this._layerNames[a]=c.name;for(var d=0;d<c.fields.length;d++){var e=c.fields[d];if("esriFieldTypeOID"===e.type){this._idFields[a]=e.name;break}}},this)},_getIdFields:function(){this._idFields={},this._displayFields={},this._layerNames={};for(var a=0;a<this.options.layers.length;a++){var b=this.options.layers[a];this.get(b,{},this._layerMetadataCallback(b))}}});
//# sourceMappingURL=esri-leaflet-geocoder.js.map

@@ -27,0 +27,0 @@

{
"name": "esri-leaflet-geocoder",
"version": "1.0.0-rc.2",
"version": "1.0.0-rc.3",
"description": "Esri Geocoding utilities and search plguin for Leaflet.",

@@ -44,4 +44,4 @@ "homepage": "https://github.com/Esri/esri-leaflet-geocoder",

"leaflet": "^0.7.0",
"esri-leaflet": "1.0.0-rc.3"
"esri-leaflet": "1.0.0-rc.5"
}
}

@@ -5,7 +5,7 @@ # Esri Leaflet Geocoder

https://travis-ci.org/Esri/esri-leaflet-geocoder.svg
![Travis CI](https://travis-ci.org/Esri/esri-leaflet-geocoder.svg)
**Currently Esri Leaflet Geocoder is in development and should be thoguht of as a beta or preview**
**Currently Esri Leaflet Geocoder is in development and should be thought of as a beta or preview**
Esri Leaflet Geocoder relies on the minimal Esri Leaflet Core which handles abstraction for requests and authentication when neccessary. You can fine out more about teh Esri Leaflet Core on the [Esri Leaflet downloads page](http://esri.github.com/esri-leaflet/downloads).
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).

@@ -94,2 +94,4 @@ ## Example

`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.
`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.

@@ -127,10 +129,10 @@ ### Methods

The `Geosearch` control can also search for results from a varity of sources includeing Feature Layers and Map Services. This is done with plain text matching and is not "real" geocoding. But it allows you to mix custom results into search box.
The `Geosearch` control can also search for results from a varity of sources including Feature Layers and Map Services. This is done with plain text matching and is not "real" geocoding. But it allows you to mix custom results into search box.
```js
var gisDay = new L.esri.Geocoding.Controls.Geosearch.Providers.FeatureLayer('https://services.arcgis.com/uCXeTVveQzP4IIcx/arcgis/rest/services/GIS_Day/FeatureServer/0', {
searchFields: ['EventName', 'Organizati'], // Search these fields for text matches
var gisDay = new L.esri.Geocoding.Controls.Geosearch.Providers.FeatureLayer('https://services.arcgis.com/uCXeTVveQzP4IIcx/arcgis/rest/services/GIS_Day_Final/FeatureServer/0', {
searchFields: ['Name', 'Organization'], // Search these fields for text matches
label: 'GIS Day Events', // Group suggestions under this header
formatSuggestion: function(feature){
return feature.properties.EventName + ' - ' + feature.properties.Organizati; // format suggestions like this.
return feature.properties.Name + ' - ' + feature.properties.Organization; // format suggestions like this.
}

@@ -156,7 +158,7 @@ });

`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 matchs on.
`layer` | `Integer` | `0` | Only valid for `MapService` providers, the layer to find text matches on.
`label` | `String` | Provider Type | Text that will be used to group suggestions under.
`maxResults` | `Integer` | 5 | Maxiumum 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 | Formating function for the suggestion text. Recives a feature and returns a string.
`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 | Formating function for the suggestion text. Receives a feature and returns a string.

@@ -167,3 +169,3 @@ #### Results Event

--- | --- | ---
`bounds` | [`L.LatLngBounds`](http://leafletjs.com/reference.html#latlngbounds)| The bounds arround this suggestion. Good for zooming to results like cities and states.
`bounds` | [`L.LatLngBounds`](http://leafletjs.com/reference.html#latlngbounds)| The bounds around this suggestion. Good for zooming to results like cities and states.
`latlng` | [`L.LatLng`](http://leafletjs.com/reference.html#latlng)| The center of the result.

@@ -179,3 +181,3 @@ `results` | [`[<ResultObject>]`](#result-object) | An array of [result objects](#result-object).

`text` | `String` | The text that was passed to the geocoder.
`bounds` | [`L.LatLngBounds`](http://leafletjs.com/reference.html#latlngbounds)| The bounds arround this suggestion. Good for zooming to results like cities and states.
`bounds` | [`L.LatLngBounds`](http://leafletjs.com/reference.html#latlngbounds)| The bounds around this suggestion. Good for zooming to results like cities and states.
`latlng` | [`L.LatLng`](http://leafletjs.com/reference.html#latlng)| The center of the result.

@@ -192,3 +194,3 @@

--- | ---
`new L.esri.Geocoding.Geocoding(url, options)`<br>`L.esri.Controls.geosearch(url, options)`<br>`new L.esri.Services.Geocoding(options)`<br>`L.esri.Controls.geosearch(options)` | Creates a new Geosearch control you can pass the url as the first parameter or as `url` in the options to a custom geocoding enpoint if you do no want to use the ArcGIS Online World Geocoding service.
`new L.esri.Geocoding.Geocoding(url, options)`<br>`L.esri.Controls.geosearch(url, options)`<br>`new L.esri.Services.Geocoding(options)`<br>`L.esri.Controls.geosearch(options)` | Creates a new Geosearch control. You can pass the url as the first parameter or as `url` in the options to a custom geocoding endpoint if you do not want to use the ArcGIS Online World Geocoding service.

@@ -227,14 +229,14 @@ ### Options

--- | --- | ---
`text(text &lt;String&gt;)` | `this` | The text to geocode. If you specify `text` all other params like `address`, `city`, `subregion`, and `region`, `postal`, and `country` will be ignored.
`address(text &lt;String&gt;)` | Specify the street and house number to be geocoded.
`neighborhood(text &lt;String&gt;)` | Specify the neighborhood to be geocoded.
`city(text &lt;String&gt;)` | Specify the city to be geocoded.
`subregion(text &lt;String&gt;)` | Specify the subregion to be geocoded. Depending on the country, subregion can represent a county, state, or province.
`region(text &lt;String&gt;)` | Specify the region to be geocoded. Typically a state or province
`postal(text &lt;String&gt;)` | Specify the postal code to be geocoded.
`country(text &lt;String&gt;)` | Specify the country to be geocoded.
`category(category &lt;String&gt;)` | 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
`within(bounds &lt;L.LatLngBounds&gt;)` | A bounding box to search for suggestions in.
`nearby(latlng &lt;L.LatLng&gt;, distance &lt;Integer&gt;)` | Searches for suggestions only inside an area around the LatLng. `distance` is in meters.
`run(callback &lt;Function&gt;, context&lt;Object&gt;)` | `XMLHttpRequest` | Executes this request chain and accepts the response callback.
`text(text <String>)` | `this` | The text to geocode. If you specify `text` all other params like `address`, `city`, `subregion`, and `region`, `postal`, and `country` will be ignored.
`address(text <String>)` | Specify the street and house number to be geocoded.
`neighborhood(text <String>)` | Specify the neighborhood to be geocoded.
`city(text <String>)` | Specify the city to be geocoded.
`subregion(text <String>)` | Specify the subregion to be geocoded. Depending on the country, subregion can represent a county, state, or province.
`region(text <String>)` | Specify the region to be geocoded. Typically a state or province
`postal(text <String>)` | Specify the postal code to be geocoded.
`country(text <String>)` | Specify the country to be geocoded.
`category(category <String>)` | The category to search for suggestions. By default no category. A list of categories can be found here https://developers.arcgis.com/rest/geocode/api-reference/geocoding-category-filtering.htm#ESRI_SECTION1_502B3FE2028145D7B189C25B1A00E17B
`within(bounds <L.LatLngBounds>)` | A bounding box to search for suggestions in.
`nearby(latlng <L.LatLng>, distance <Integer>)` | Searches for suggestions only inside an area around the LatLng. `distance` is in meters.
`run(callback <Function>, context <Object>)` | `XMLHttpRequest` | Executes this request chain and accepts the response callback.

@@ -244,3 +246,3 @@ ### Examples

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

@@ -251,3 +253,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.Tasks.geocode(L.esri.Geocoding.WorldGeocodingService).address('380 New York St').city('Redlands').region('California').postal(92373).run(function(err, results, response){
console.log(results);

@@ -257,2 +259,23 @@ });

```js
//Using .within()
var southWest = L.latLng(37.712, -108.227),
northEast = L.latLng(41.774, -102.125),
bounds = L.latLngBounds(southWest, northEast); // Colorado
L.esri.Geocoding.Tasks.geocode(L.esri.Geocoding.WorldGeocodingService).text("Denver").within(bounds).run(function(err, response){
console.log(response);
});
```
```js
//Using .nearby()
var denver = L.latLng(37.712, -108.227);
L.esri.Geocoding.Tasks.geocode(L.esri.Geocoding.WorldGeocodingService).text("Highlands Ranch").nearby(denver, 20000).run(function(err, response){
console.log(response);
});
```
### Results Object

@@ -294,7 +317,7 @@

--- | --- | ---
`text(text &lt;String&gt;)` | `this` | The text to recive suggestions for.
`category(category &lt;String&gt;)` | 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
`within(bounds &lt;L.LatLngBounds&gt;)` | A bounding box to search for suggestions in.
`nearby(latlng &lt;L.LatLng&gt;, distance &lt;Integer&gt;)` | Searches for suggestions only inside an area around the LatLng. `distance` is in meters.
`run(callback &lt;Function&gt;, context&lt;Object&gt;)` | `XMLHttpRequest` | Executes this request chain and accepts the response callback.
`text(text <String>)` | `this` | The text to recive 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
`within(bounds <L.LatLngBounds>)` | A bounding box to search for suggestions in.
`nearby(latlng <L.LatLng>, distance <Integer>)` | Searches for suggestions only inside an area around the LatLng. `distance` is in meters.
`run(callback <Function>, context<Object>)` | `XMLHttpRequest` | Executes this request chain and accepts the response callback.

@@ -325,6 +348,6 @@ ### Example

--- | --- | ---
`latlng(latlng &lt;L.LatLng&gt;)` | The L.LatLng object for which the address will be looked up.
`distance(distance &lt;Integer&gt;)` | The distance (in meters) around the point for which addresses will be looked up.
`language(language &lt;String&gt;)` | `this` | The language to return the address in.
`run(callback &lt;Function&gt;, context&lt;Object&gt;)` | `XMLHttpRequest` | Executes this request chain and accepts the response callback.
`latlng(latlng <L.LatLng>)` | The L.LatLng object for which the address will be looked up.
`distance(distance <Integer>)` | The distance (in meters) around the point for which addresses will be looked up.
`language(language <String>)` | `this` | The language to return the address in.
`run(callback <Function>, context <Object>)` | `XMLHttpRequest` | Executes this request chain and accepts the response callback.

@@ -345,3 +368,3 @@ ### Example

2. `cd` into the `esri-leaflet-geocoder` folder
5. Instal the dependancies with `npm install`
5. Install the dependencies with `npm install`
5. The example at `/index.html` should work

@@ -352,3 +375,3 @@ 6. Make your changes and create a [pull request](https://help.github.com/articles/creating-a-pull-request)

Esri Leaflet Geocoder relies on the minimal Esri Leaflet Core which handles abstraction for requests and authentication when neccessary. You can fine out more about teh Esri Leaflet Core on the [Esri Leaflet downloads page](http://esri.github.com/esri-leaflet/downloads).
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).

@@ -355,0 +378,0 @@ ## Resources

@@ -11,3 +11,4 @@ describe('L.esri.Controls.Geosearch.Providers.FeatureLayer', function () {

xhr = sinon.useFakeXMLHttpRequest();
provider = new L.esri.Geocoding.Controls.Geosearch.Providers.FeatureLayer('http://example.com/arcgis/arcgis/rest/services/MockService/0', {
provider = new L.esri.Geocoding.Controls.Geosearch.Providers.FeatureLayer({
url: 'http://example.com/arcgis/arcgis/rest/services/MockService/0',
searchFields: ['Name']

@@ -14,0 +15,0 @@ });

@@ -7,3 +7,5 @@ describe('Providers.GeocodeService', function () {

xhr = sinon.useFakeXMLHttpRequest();
provider = new L.esri.Geocoding.Controls.Geosearch.Providers.GeocodeService('http://example.com/arcgis/arcgis/rest/services/MockGeocodeService');
provider = new L.esri.Geocoding.Controls.Geosearch.Providers.GeocodeService({
url: 'http://example.com/arcgis/arcgis/rest/services/MockGeocodeService'
});
});

@@ -10,0 +12,0 @@

@@ -46,3 +46,3 @@ describe('L.esri.Controls.Geosearch.Providers.MapService', function () {

'fieldAliases': {
'ObjectID': 'ObjectID',
'OBJECTID': 'OBJECTID',
'Name': 'Name'

@@ -52,5 +52,5 @@ },

{
'name': 'ObjectID',
'name': 'OBJECTID',
'type': 'esriFieldTypeOID',
'alias': 'ObjectID'
'alias': 'OBJECTID'
},

@@ -66,3 +66,3 @@ {

'attributes': {
'ObjectID': 1,
'OBJECTID': 1,
'Name': 'Place 1'

@@ -83,6 +83,10 @@ },

xhr = sinon.useFakeXMLHttpRequest();
provider = new L.esri.Geocoding.Controls.Geosearch.Providers.MapService('http://example.com/arcgis/arcgis/rest/services/MockService', {
searchFields: ['Name']
provider = new L.esri.Geocoding.Controls.Geosearch.Providers.MapService({
url: 'http://example.com/arcgis/arcgis/rest/services/MockService',
layer: 0,
searchFields: ['Name', 'OBJECTID']
});
provider._idField = 'OBJECTID';
provider._idFields = {0:'OBJECTID'};
provider._displayFields = {0:'Name'};
provider._layerNames = {0:'Layer'};
});

@@ -97,4 +101,4 @@

expect(results.length).to.equal(2);
expect(results[0].text).to.equal('Place 1');
expect(results[0].magicKey).to.equal(1);
expect(results[0].text).to.contain('Place 1');
expect(results[0].magicKey).to.equal('1:0');
done();

@@ -105,3 +109,3 @@ });

expect(request.url).to.contain("searchText=Pla");
expect(request.url).to.contain("searchFields=Name");
expect(request.url).to.contain("searchFields=Name%2COBJECTID");
expect(request.url).to.contain("layers=0");

@@ -112,7 +116,7 @@

it('should geocode with a magic key', function(done){
var request = provider.results('Place 1', '1', null, function(error, results){
it('should query for geometry with a magic key', function(done){
var request = provider.results('Place 1', '1:0', null, function(error, results){
expect(results[0].latlng.lat).to.equal(45.48);
expect(results[0].latlng.lng).to.equal(-122.81);
expect(results[0].text).to.equal('Place 1');
expect(results[0].text).to.contain('Place 1');
done();

@@ -129,3 +133,3 @@ });

expect(results.length).to.equal(2);
expect(results[0].text).to.equal('Place 1');
expect(results[0].text).to.contain('Place 1');
done();

@@ -132,0 +136,0 @@ });

@@ -9,3 +9,3 @@ describe('L.esri.Geocoding.Services.Geocoding', function () {

it('should initalize with the ArcGIS Online Geocoder URL by default', function(){
expect(geocoder.url).to.equal('//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/');
expect(geocoder.options.url).to.contain('//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/');
});

@@ -12,0 +12,0 @@

@@ -95,2 +95,130 @@ describe('L.esri.Tasks.Geocode', function () {

var sampleFindWithinResponse = JSON.stringify({
"spatialReference": {
"wkid": 4326,
"latestWkid": 4326
},
"locations": [
{
"name": "380 New York St, Redlands, California, 92373",
"extent": {
"xmin": -117.196667,
"ymin": 34.055491,
"xmax": -117.194667,
"ymax": 34.057491
},
"feature": {
"geometry": {
"x": -117.19566602536605,
"y": 34.056490511029324
},
"attributes": {
"Loc_name": "USA.PointAddress",
"Score": 100,
"Match_addr": "380 New York St, Redlands, California, 92373",
"Addr_type": "PointAddress",
"Type": "",
"PlaceName": "",
"Place_addr": "",
"Phone": "",
"URL": "",
"Rank": "",
"AddBldg": "",
"AddNum": "380",
"AddNumFrom": "",
"AddNumTo": "",
"Side": "R",
"StPreDir": "",
"StPreType": "",
"StName": "New York",
"StType": "St",
"StDir": "",
"StAddr": "",
"Nbrhd": "",
"City": "Redlands",
"Subregion": "",
"Region": "California",
"Postal": "92373",
"PostalExt": "",
"Country": "USA",
"LangCode": "ENG",
"Distance": 0,
"X": -117.195667,
"Y": 34.056491,
"DisplayX": -117.195311,
"DisplayY": 34.05611,
"Xmin": -117.196667,
"Xmax": -117.194667,
"Ymin": 34.055491,
"Ymax": 34.057491
}
}
}
]
});
var sampleFindNearbyResponse = JSON.stringify( {
"spatialReference": {
"wkid": 4326,
"latestWkid": 4326
},
"locations": [
{
"name": "Highlands Ranch, Colorado, United States",
"extent": {
"xmin": -105.053427,
"ymin": 39.469876,
"xmax": -104.885427,
"ymax": 39.637876
},
"feature": {
"geometry": {
"x": -104.96942569799967,
"y": 39.55387558400048
},
"attributes": {
"Loc_name": "Gaz.WorldGazetteer.POI1",
"Score": 100,
"Match_addr": "Highlands Ranch, Colorado, United States",
"Addr_type": "POI",
"Type": "City",
"PlaceName": "Highlands Ranch",
"Place_addr": "",
"Phone": "",
"URL": "",
"Rank": "8.04",
"AddBldg": "",
"AddNum": "",
"AddNumFrom": "",
"AddNumTo": "",
"Side": "",
"StPreDir": "",
"StPreType": "",
"StName": "",
"StType": "",
"StDir": "",
"StAddr": "",
"Nbrhd": "",
"City": "",
"Subregion": "Douglas",
"Region": "Colorado",
"Postal": "",
"PostalExt": "",
"Country": "USA",
"LangCode": "",
"Distance": 349299.97,
"X": -104.969427,
"Y": 39.553876,
"DisplayX": -104.969427,
"DisplayY": 39.553876,
"Xmin": -105.053427,
"Xmax": -104.885427,
"Ymin": 39.469876,
"Ymax": 39.637876
}
}
}
]
});
var xhr;

@@ -107,3 +235,3 @@

it('should make a basic geocode request to ArcGIS Online', function(done){
var request = new L.esri.Geocoding.Tasks.geocode(L.esri.Geocoding.WorldGeocodingService).text('380 New York St, Redlands, California, 92373').run(function(err, response){
var request = new L.esri.Geocoding.Tasks.geocode().text('380 New York St, Redlands, California, 92373').run(function(err, response){
expect(response.results[0].latlng.lat).to.equal(34.056490727765947);

@@ -124,3 +252,5 @@ expect(response.results[0].latlng.lng).to.equal(-117.19566584280369);

it('should make a basic find request to a Geocode Service', function(done){
var request = new L.esri.Geocoding.Tasks.geocode('http://gis.example.com/arcgis/rest/services/Geocoder').text('380 New York St, Redlands, California, 92373').run(function(err, response){
var request = new L.esri.Geocoding.Tasks.geocode({
url: 'http://gis.example.com/arcgis/rest/services/Geocoder'
}).text('380 New York St, Redlands, California, 92373').run(function(err, response){
expect(response.results[0].latlng.lat).to.equal(34.056490727765947);

@@ -141,3 +271,3 @@ expect(response.results[0].latlng.lng).to.equal(-117.19566584280369);

it('should make a findAddressCanidates request to ArcGIS Online', function(done){
var request = new L.esri.Geocoding.Tasks.geocode(L.esri.Geocoding.WorldGeocodingService).address('380 New York St').city('Redlands').region('California').postal(92373).run(function(err, response){
var request = new L.esri.Geocoding.Tasks.geocode().address('380 New York St').city('Redlands').region('California').postal(92373).run(function(err, response){
expect(response.results[0].latlng.lat).to.equal(34.056490727765947);

@@ -161,3 +291,5 @@ expect(response.results[0].latlng.lng).to.equal(-117.19566584280369);

it('should make a findAddressCanidates request to a Geocode Service', function(done){
var request = new L.esri.Geocoding.Tasks.geocode('http://gis.example.com/arcgis/rest/services/Geocoder').address('380 New York St').city('Redlands').region('California').postal(92373).run(function(err, response){
var request = new L.esri.Geocoding.Tasks.geocode({
url:'http://gis.example.com/arcgis/rest/services/Geocoder'
}).address('380 New York St').city('Redlands').region('California').postal(92373).run(function(err, response){
expect(response.results[0].latlng.lat).to.equal(34.056490727765947);

@@ -180,2 +312,46 @@ expect(response.results[0].latlng.lng).to.equal(-117.19566584280369);

it('should make a `within` request to ArcGIS Online', function(done){
var southWest = L.latLng(34.0500, -117.2000),
northEast = L.latLng(34.0600, -117.1900),
bounds = L.latLngBounds(southWest, northEast);
var request = new L.esri.Geocoding.Tasks.geocode().text('380 New York St').within(bounds).run(function(err, response){
expect(response.results[0].latlng.lat).to.equal(34.056490511029324);
expect(response.results[0].latlng.lng).to.equal(-117.19566602536605);
expect(response.results[0].text).to.equal('380 New York St, Redlands, California, 92373');
expect(response.results[0].score).to.equal(100);
expect(response.results[0].properties.Region).to.equal('California');
expect(response.results[0].properties.Addr_type).to.equal('PointAddress');
done();
});
expect(request.url).to.contain('//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find');
expect(request.url).to.contain('text=380%20New%20York%20St');
expect(request.url).to.contain('bbox=%7B%22xmin%22%3A-117.2%2C%22ymin%22%3A34.05%2C%22xmax%22%3A-117.19%2C%22ymax%22%3A34.06%2C%22spatialReference%22%3A%7B%22wkid%22%3A4326%7D%7D');
request.respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, sampleFindWithinResponse);
});
it('should make a `nearby` request to ArcGIS Online', function(done){
var denver = L.latLng(37.712, -108.227);
var request = new L.esri.Geocoding.Tasks.geocode().text('Highlands Ranch').nearby(denver, 10000).run(function(err, response){
expect(response.results[0].latlng.lat).to.equal(39.55387558400048);
expect(response.results[0].latlng.lng).to.equal(-104.96942569799967);
expect(response.results[0].text).to.equal('Highlands Ranch, Colorado, United States');
expect(response.results[0].score).to.equal(100);
expect(response.results[0].properties.Subregion).to.equal('Douglas');
expect(response.results[0].properties.Region).to.equal('Colorado');
expect(response.results[0].properties.Addr_type).to.equal('POI');
done();
});
expect(request.url).to.contain('//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find');
expect(request.url).to.contain('text=Highlands%20Ranch');
expect(request.url).to.contain('location=-108.227%2C37.712');
expect(request.url).to.contain('distance=10000');
request.respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, sampleFindNearbyResponse);
});
});

@@ -58,3 +58,3 @@ describe('L.esri.Tasks.ReverseGeocode', function () {

it('should make a reverse geocode request to ArcGIS Online', function(done){
var request = L.esri.Geocoding.Tasks.reverseGeocode(L.esri.Geocoding.WorldGeocodingService).latlng([48.8583, 2.2945]).run(function(error, result, response){
var request = L.esri.Geocoding.Tasks.reverseGeocode().latlng([48.8583, 2.2945]).run(function(error, result, response){
expect(result.latlng.lat).to.equal(48.857489996304814);

@@ -73,3 +73,5 @@ expect(result.latlng.lng).to.equal(2.2946500041892821);

it('should make a reverse geocode request to a Geocode service', function(done){
var request = L.esri.Geocoding.Tasks.reverseGeocode('http://gis.example.com/arcgis/rest/services/Geocoder').latlng([48.8583, 2.2945]).run(function(error, result, response){
var request = L.esri.Geocoding.Tasks.reverseGeocode({
url: 'http://gis.example.com/arcgis/rest/services/Geocoder'
}).latlng([48.8583, 2.2945]).run(function(error, result, response){
expect(result.latlng.lat).to.equal(48.857489996304814);

@@ -88,3 +90,3 @@ expect(result.latlng.lng).to.equal(2.2946500041892821);

it('should make a reverse geocode request with a distance param', function(done){
var request = L.esri.Geocoding.Tasks.reverseGeocode(L.esri.Geocoding.WorldGeocodingService).latlng([48.8583, 2.2945]).distance(200).run(function(error, result, response){
var request = L.esri.Geocoding.Tasks.reverseGeocode().latlng([48.8583, 2.2945]).distance(200).run(function(error, result, response){
done();

@@ -99,3 +101,3 @@ });

it('should make a reverse geocode request with a language param', function(done){
var request = L.esri.Geocoding.Tasks.reverseGeocode(L.esri.Geocoding.WorldGeocodingService).latlng([48.8583, 2.2945]).language('fr').distance(200).run(function(error, result, response){
var request = L.esri.Geocoding.Tasks.reverseGeocode().latlng([48.8583, 2.2945]).language('fr').distance(200).run(function(error, result, response){
expect(result.address.Address).to.equal('Rue de la Sablonnière 16');

@@ -102,0 +104,0 @@ done();

@@ -44,3 +44,3 @@ describe('L.esri.Tasks.Suggest', function () {

it('should make a suggest request to ArcGIS Online', function(done){
var request = L.esri.Geocoding.Tasks.suggest(L.esri.Geocoding.WorldGeocodingService).text('trea').run(function(error, response){
var request = L.esri.Geocoding.Tasks.suggest().text('trea').run(function(error, response){
expect(response.suggestions.length).to.equal(5);

@@ -57,3 +57,3 @@ done();

it('should make a suggest request with a nearby filter', function(done){
var request = L.esri.Geocoding.Tasks.suggest(L.esri.Geocoding.WorldGeocodingService).text('trea').nearby([45,-121], 5000).run(function(error, response){
var request = L.esri.Geocoding.Tasks.suggest().text('trea').nearby([45,-121], 5000).run(function(error, response){
expect(response.suggestions.length).to.equal(5);

@@ -70,3 +70,3 @@ done();

it('should make a suggest request with a bounds filter', function(done){
var request = L.esri.Geocoding.Tasks.suggest(L.esri.Geocoding.WorldGeocodingService).text('trea').within([[0,0],[100,100]]).run(function(error, response){
var request = L.esri.Geocoding.Tasks.suggest().text('trea').within([[0,0],[100,100]]).run(function(error, response){
expect(response.suggestions.length).to.equal(5);

@@ -73,0 +73,0 @@ done();

@@ -13,3 +13,4 @@ EsriLeafletGeocoding.Controls.Geosearch = L.Control.extend({

providers: [],
placeholder: 'Search for places or addresses'
placeholder: 'Search for places or addresses',
title: 'Location Search'
},

@@ -115,5 +116,5 @@

if(provider.nodes){
for (i = 0; i < provider.nodes.length; i++) {
if(provider.nodes[i].parentElement){
this._suggestions.removeChild(provider.nodes[i]);
for (var k = 0; k < provider.nodes.length; k++) {
if(provider.nodes[k].parentElement){
this._suggestions.removeChild(provider.nodes[k]);
}

@@ -137,4 +138,2 @@ }

var provider = this.options.providers[i];
console.log(!!provider);
console.log(provider.options.label);
var request = provider.suggestions(text, this._searchBounds(), createCallback(text, provider));

@@ -164,2 +163,10 @@ this._pendingSuggestions.push(request);

this._suggestions.style.display = 'block';
// set the maxHeight of the suggestions box to
// map height
// - suggestions offset (distance from top of suggestions to top of control)
// - control offset (distance from top of control to top of map)
// - 10 (extra padding)
this._suggestions.style.maxHeight = (this._map.getSize().y - this._suggestions.offsetTop - this._wrapper.offsetTop - 10) + 'px';
var nodes = [];

@@ -190,3 +197,2 @@ var list;

nodes.push(list);
console.log(nodes.length);
return nodes;

@@ -227,2 +233,6 @@ },

}
if(!this._map.scrollWheelZoom.enabled() && this._map.options.scrollWheelZoom){
this._map.scrollWheelZoom.enable();
}
},

@@ -239,2 +249,3 @@

this._input = L.DomUtil.create('input', 'geocoder-control-input leaflet-bar', this._wrapper);
this._input.title = this.options.title;

@@ -363,2 +374,16 @@ this._suggestions = L.DomUtil.create('div', 'geocoder-control-suggestions leaflet-bar', this._wrapper);

// when mouse moves over suggestions disable scroll wheel zoom if its enabled
L.DomEvent.addListener(this._suggestions, 'mouseover', function(e){
if(map.scrollWheelZoom.enabled() && map.options.scrollWheelZoom){
map.scrollWheelZoom.disable();
}
});
// when mouse moves leaves suggestions enable scroll wheel zoom if its disabled
L.DomEvent.addListener(this._suggestions, 'mouseout', function(e){
if(!map.scrollWheelZoom.enabled() && map.options.scrollWheelZoom){
map.scrollWheelZoom.enable();
}
});
return this._wrapper;

@@ -365,0 +390,0 @@ },

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

var protocol = window.location.protocol === 'https:' ? 'https:' : 'http:';
var EsriLeafletGeocoding = {
WorldGeocodingService: '//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/',
WorldGeocodingService: protocol + '//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/',
Tasks: {},

@@ -4,0 +6,0 @@ Services: {},

EsriLeafletGeocoding.Controls.Geosearch.Providers.ArcGISOnline = EsriLeafletGeocoding.Services.Geocoding.extend({
options: {
label: "Places and Addresses",
label: 'Places and Addresses',
maxResults: 5
},
suggestions: function(text, bounds, callback){

@@ -7,0 +8,0 @@ var request = this.suggest().text(text);

@@ -87,3 +87,3 @@ EsriLeafletGeocoding.Controls.Geosearch.Providers.FeatureLayer = L.esri.Services.FeatureLayer.extend({

var field = this.options.searchFields[i];
queryString.push(field + " LIKE '%" + text + "%'"); // jshint ignore:line
queryString.push(field + ' LIKE \'%' + text + '%\'');
}

@@ -90,0 +90,0 @@

EsriLeafletGeocoding.Controls.Geosearch.Providers.MapService = L.esri.Services.MapService.extend({
options: {
layer: 0,
layers: [0],
label: 'Map Service',

@@ -8,3 +8,3 @@ bufferRadius: 1000,

formatSuggestion: function(feature){
return feature.properties[this.options.searchFields[0]];
return feature.properties[feature.displayFieldName] + ' <small>' + feature.layerName + '</small>';
}

@@ -14,25 +14,28 @@ },

L.esri.Services.MapService.prototype.initialize.call(this, url, options);
this._getIdField();
this._getIdFields();
},
suggestions: function(text, bounds, callback){
var request = this.find().text(text).returnGeometry(false).layers(this.options.layer);
var request = this.find().text(text).fields(this.options.searchFields).returnGeometry(false).layers(this.options.layers);
if (this._idField) {
request.fields(this.options.searchFields);
}
return request.run(function(error, results){
return request.run(function(error, results, raw){
var suggestions = [];
if(this._idField && !error){
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];
suggestions.push({
text: this.options.formatSuggestion.call(this, feature),
magicKey: feature.properties[this._idField]
});
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());

@@ -46,17 +49,23 @@ }, this);

if(key){
request = this.query().layer(this.options.layer).featureIds(key);
var featureId = key.split(':')[0];
var layer = key.split(':')[1];
request = this.query().layer(layer).featureIds(featureId);
} else {
request = this.find().text(text).contains(false).layers(this.options.layer);
request = this.find().text(text).fields(this.options.searchFields).contains(false).layers(this.options.layers);
}
if(this._idField){
request.fields([this.options.searchFields, this.options._idField]);
}
return request.run(function(error, features){
if(this._idField && !error){
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];
if(feature){
layer = (layer) ? layer : response.results[i].layerId;
if(feature && layer !== undefined) {
var bounds = this._featureBounds(feature);
var idField = this._idFields[layer];
feature.layerId = layer;
feature.layerName = this._layerNames[layer];
feature.displayFieldName = this._displayFields[layer];
var result = {

@@ -84,9 +93,10 @@ latlng: bounds.getCenter(),

},
_getIdField: function(){
this.get(this.options.layer, {}, function(error, metadata){
_layerMetadataCallback: function(layerid){
return L.Util.bind(function(error, metadata){
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._idField = field.name;
this.options.searchFields.push(field.name);
this._idFields[layerid] = field.name;
break;

@@ -96,3 +106,12 @@ }

}, 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));
}
}
});
EsriLeafletGeocoding.Services.Geocoding = Esri.Services.Service.extend({
includes: L.Mixin.Events,
initialize: function (url, options) {
url = (typeof url === 'string') ? url : EsriLeafletGeocoding.WorldGeocodingService;
options = (typeof url === 'object') ? url : (options || {});
this.url = Esri.Util.cleanUrl(url);
L.Util.setOptions(this, options);
Esri.Services.Service.prototype.initialize.call(this, url, options);
initialize: function(options){
options = options || {};
options.url = options.url || EsriLeafletGeocoding.WorldGeocodingService;
Esri.Services.Service.prototype.initialize.call(this, options);
},

@@ -21,4 +20,5 @@

suggest: function(){
if(this.url !== EsriLeafletGeocoding.WorldGeocodingService && console && console.warn){
if(this.options.url !== EsriLeafletGeocoding.WorldGeocodingService && console && console.warn){
console.warn('Only the ArcGIS Online World Geocoder supports suggestions');
return;
}

@@ -29,4 +29,4 @@ return new EsriLeafletGeocoding.Tasks.Suggest(this);

EsriLeafletGeocoding.Services.geocoding = function(url, options){
return new EsriLeafletGeocoding.Services.Geocoding(url, options);
EsriLeafletGeocoding.Services.geocoding = function(options){
return new EsriLeafletGeocoding.Services.Geocoding(options);
};

@@ -28,6 +28,12 @@ EsriLeafletGeocoding.Tasks.Geocode = Esri.Tasks.Task.extend({

initialize: function(options){
options = options || {};
options.url = options.url || EsriLeafletGeocoding.WorldGeocodingService;
Esri.Tasks.Task.prototype.initialize.call(this, options);
},
within: function(bounds){
bounds = L.latLngBounds(bounds);
console.log(bounds);
this.params.bbox = Esri.Util.boundsToExtent(bounds);
return this;
},

@@ -39,2 +45,3 @@

this.params.distance = Math.min(Math.max(radius, 2000), 50000);
return this;
},

@@ -97,4 +104,4 @@

EsriLeafletGeocoding.Tasks.geocode = function(url, options){
return new EsriLeafletGeocoding.Tasks.Geocode(url, options);
EsriLeafletGeocoding.Tasks.geocode = function(options){
return new EsriLeafletGeocoding.Tasks.Geocode(options);
};

@@ -7,2 +7,3 @@ EsriLeafletGeocoding.Tasks.ReverseGeocode = Esri.Tasks.Task.extend({

},
setters: {

@@ -13,2 +14,8 @@ 'distance': 'distance',

initialize: function(options){
options = options || {};
options.url = options.url || EsriLeafletGeocoding.WorldGeocodingService;
Esri.Tasks.Task.prototype.initialize.call(this, options);
},
latlng: function (latlng) {

@@ -38,4 +45,4 @@ latlng = L.latLng(latlng);

EsriLeafletGeocoding.Tasks.reverseGeocode = function(url, options){
return new EsriLeafletGeocoding.Tasks.ReverseGeocode(url, options);
EsriLeafletGeocoding.Tasks.reverseGeocode = function(options){
return new EsriLeafletGeocoding.Tasks.ReverseGeocode(options);
};

@@ -11,2 +11,9 @@ EsriLeafletGeocoding.Tasks.Suggest = Esri.Tasks.Task.extend({

initialize: function(options){
options = options || {};
options.url = options.url || EsriLeafletGeocoding.WorldGeocodingService;
Esri.Tasks.Task.prototype.initialize.call(this, options);
},
within: function(bounds){

@@ -37,4 +44,4 @@ bounds = L.latLngBounds(bounds);

EsriLeafletGeocoding.Tasks.suggest = function(url, options){
return new EsriLeafletGeocoding.Tasks.Suggest(url, options);
EsriLeafletGeocoding.Tasks.suggest = function(options){
return new EsriLeafletGeocoding.Tasks.Suggest(options);
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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