leaflet-control-geocoder
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -41,7 +41,8 @@ (function (factory) { | ||
container = L.DomUtil.create('div', className), | ||
icon = L.DomUtil.create('div', 'leaflet-control-geocoder-icon', container), | ||
form = this._form = L.DomUtil.create('form', className + '-form', container), | ||
input, | ||
icon; | ||
input; | ||
this._map = map; | ||
this._container = container; | ||
input = this._input = L.DomUtil.create('input'); | ||
@@ -54,5 +55,2 @@ input.type = 'text'; | ||
icon = L.DomUtil.create('div', 'leaflet-control-geocoder-icon'); | ||
container.appendChild(icon); | ||
this._errorElement = document.createElement('div'); | ||
@@ -136,2 +134,4 @@ this._errorElement.className = className + '-form-no-error'; | ||
this._collapse(); | ||
} else { | ||
this._clearResults(); | ||
} | ||
@@ -157,2 +157,3 @@ this.markGeocode(result); | ||
L.DomUtil.addClass(this._alts, 'leaflet-control-geocoder-alternatives-minimized'); | ||
L.DomUtil.removeClass(this._errorElement, 'leaflet-control-geocoder-error'); | ||
}, | ||
@@ -392,4 +393,78 @@ | ||
L.Control.Geocoder.MapQuest = L.Class.extend({ | ||
initialize: function(key) { | ||
// MapQuest seems to provide URI encoded API keys, | ||
// so to avoid encoding them twice, we decode them here | ||
this._key = decodeURIComponent(key); | ||
}, | ||
_formatName: function() { | ||
var r = [], | ||
i; | ||
for (i = 0; i < arguments.length; i++) { | ||
if (arguments[i]) { | ||
r.push(arguments[i]); | ||
} | ||
} | ||
return r.join(', '); | ||
}, | ||
geocode: function(query, cb, context) { | ||
L.Control.Geocoder.jsonp('http://www.mapquestapi.com/geocoding/v1/address', { | ||
key: this._key, | ||
location: query, | ||
limit: 5, | ||
outFormat: 'json' | ||
}, function(data) { | ||
var results = [], | ||
loc, | ||
latLng; | ||
if (data.results && data.results[0].locations) { | ||
for (var i = data.results[0].locations.length - 1; i >= 0; i--) { | ||
loc = data.results[0].locations[i]; | ||
latLng = L.latLng(loc.latLng); | ||
results[i] = { | ||
name: this._formatName(loc.street, loc.adminArea4, loc.adminArea3, loc.adminArea1), | ||
bbox: L.latLngBounds(latLng, latLng), | ||
center: latLng | ||
}; | ||
} | ||
} | ||
cb.call(context, results); | ||
}, this); | ||
}, | ||
reverse: function(location, scale, cb, context) { | ||
L.Control.Geocoder.jsonp('http://www.mapquestapi.com/geocoding/v1/reverse', { | ||
key: this._key, | ||
location: location.lat + ',' + location.lng, | ||
outputFormat: 'json' | ||
}, function(data) { | ||
var results = [], | ||
loc, | ||
latLng; | ||
if (data.results && data.results[0].locations) { | ||
for (var i = data.results[0].locations.length - 1; i >= 0; i--) { | ||
loc = data.results[0].locations[i]; | ||
latLng = L.latLng(loc.latLng); | ||
results[i] = { | ||
name: this._formatName(loc.street, loc.adminArea4, loc.adminArea3, loc.adminArea1), | ||
bbox: L.latLngBounds(latLng, latLng), | ||
center: latLng | ||
}; | ||
} | ||
} | ||
cb.call(context, results); | ||
}, this); | ||
} | ||
}); | ||
L.Control.Geocoder.mapQuest = function(key) { | ||
return new L.Control.Geocoder.MapQuest(key); | ||
}; | ||
return L.Control.Geocoder; | ||
})); |
{ | ||
"name": "leaflet-control-geocoder", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Extendable geocoder with builtin OSM/Nominatim support", | ||
@@ -5,0 +5,0 @@ "main": "Control.Geocoder.js", |
@@ -97,3 +97,3 @@ Leaflet Control Geocoder [![NPM version](https://badge.fury.io/js/leaflet-control-geocoder.png)](http://badge.fury.io/js/leaflet-control-geocoder) | ||
| --------------- | ---------------- | ----------------- | ----------- | | ||
| serviceUrl | String | "http://nominatim.openstreetmap.org/search/" | URL of the service | | ||
| serviceUrl | String | "http://nominatim.openstreetmap.org/" | URL of the service | | ||
@@ -100,0 +100,0 @@ ## L.Control.Geocoder.Bing |
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
32678
512