-
-
Notifications
You must be signed in to change notification settings - Fork 268
/
l.geosearch.provider.openstreetmap.js
50 lines (41 loc) · 1.41 KB
/
l.geosearch.provider.openstreetmap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* L.Control.GeoSearch - search for an address and zoom to it's location
* L.GeoSearch.Provider.OpenStreetMap uses openstreetmap geocoding service
* https://github.com/smeijer/L.GeoSearch
*/
L.GeoSearch.Provider.OpenStreetMap = L.Class.extend({
options: {},
initialize: function(options) {
options = L.Util.setOptions(this, options);
},
GetServiceUrl: function (qry) {
var parameters = L.Util.extend({
q: qry,
format: 'json'
}, this.options);
return location.protocol
+ '//nominatim.openstreetmap.org/search'
+ L.Util.getParamString(parameters);
},
ParseJSON: function (data) {
var results = [];
for (var i = 0; i < data.length; i++) {
var boundingBox = data[i].boundingbox,
northEastLatLng = new L.LatLng( boundingBox[1], boundingBox[3] ),
southWestLatLng = new L.LatLng( boundingBox[0], boundingBox[2] );
if (data[i].address)
data[i].address.type = data[i].type;
results.push(new L.GeoSearch.Result(
data[i].lon,
data[i].lat,
data[i].display_name,
new L.LatLngBounds([
northEastLatLng,
southWestLatLng
]),
data[i].address
));
}
return results;
}
});