Skip to content

Commit 38d13c7

Browse files
author
Maxim Dolgov
committed
SM only mode
1 parent 8108ccd commit 38d13c7

File tree

10 files changed

+160
-42
lines changed

10 files changed

+160
-42
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"repository": {
1212
"type": "git",
13-
"url": "git://github.com/perliedman/leaflet-control-geocoder.git"
13+
"url": "git://github.com/sputnik-maps/leaflet-control-geocoder.git"
1414
},
1515
"keywords": [
1616
"leaflet",

src/all.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
var L = require('leaflet'),
2+
Control = require('./control'),
3+
Sputnik = require('./geocoders/sputnik'),
4+
Nominatim = require('./geocoders/nominatim'),
5+
Bing = require('./geocoders/bing'),
6+
MapQuest = require('./geocoders/mapquest'),
7+
Mapbox = require('./geocoders/mapbox'),
8+
What3Words = require('./geocoders/what3words'),
9+
Google = require('./geocoders/google'),
10+
Photon = require('./geocoders/photon'),
11+
Mapzen = require('./geocoders/mapzen'),
12+
ArcGis = require('./geocoders/arcgis'),
13+
HERE = require('./geocoders/here');
14+
15+
module.exports = L.Util.extend(Control.class, {
16+
Sputnik: Sputnik.class,
17+
sputnik: Sputnik.factory,
18+
Nominatim: Nominatim.class,
19+
nominatim: Nominatim.factory,
20+
Bing: Bing.class,
21+
bing: Bing.factory,
22+
MapQuest: MapQuest.class,
23+
mapQuest: MapQuest.factory,
24+
Mapbox: Mapbox.class,
25+
mapbox: Mapbox.factory,
26+
What3Words: What3Words.class,
27+
what3words: What3Words.factory,
28+
Google: Google.class,
29+
google: Google.factory,
30+
Photon: Photon.class,
31+
photon: Photon.factory,
32+
Mapzen: Mapzen.class,
33+
mapzen: Mapzen.factory,
34+
ArcGis: ArcGis.class,
35+
arcgis: ArcGis.factory,
36+
HERE: HERE.class,
37+
here: HERE.factory
38+
});
39+
40+
L.Util.extend(L.Control, {
41+
Geocoder: module.exports,
42+
geocoder: Control.factory
43+
});

src/control.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var L = require('leaflet'),
2-
Nominatim = require('./geocoders/nominatim').class;
2+
Sputnik = require('./geocoders/sputnik').class;
33

44
module.exports = {
55
class: L.Control.extend({
@@ -8,8 +8,8 @@ module.exports = {
88
collapsed: true,
99
expand: 'click',
1010
position: 'topright',
11-
placeholder: 'Search...',
12-
errorMessage: 'Nothing found.',
11+
placeholder: 'Поиск...',
12+
errorMessage: 'Не найдено',
1313
suggestMinLength: 3,
1414
suggestTimeout: 250,
1515
defaultMarkGeocode: true
@@ -20,7 +20,7 @@ module.exports = {
2020
initialize: function (options) {
2121
L.Util.setOptions(this, options);
2222
if (!this.options.geocoder) {
23-
this.options.geocoder = new Nominatim();
23+
this.options.geocoder = new Sputnik();
2424
}
2525

2626
this._requestCount = 0;
@@ -120,7 +120,7 @@ module.exports = {
120120
this._map.removeLayer(this._geocodeMarker);
121121
}
122122

123-
this._geocodeMarker = new L.Marker(result.center)
123+
this._geocodeMarker = new (L.sm.Marker || L.Marker)(result.center)
124124
.bindPopup(result.html || result.name)
125125
.addTo(this._map)
126126
.openPopup();

src/geocoders/sputnik.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
var L = require('leaflet'),
2+
Util = require('../util');
3+
4+
module.exports = {
5+
class: L.Class.extend({
6+
options: {
7+
markerClass: Util.extract(L, 'sm.Marker', L.Marker),
8+
geocoderUrl: 'http://search.maps.sputnik.ru/search/addr',
9+
reverseGeocoderUrl: 'http://whatsthere.maps.sputnik.ru/point'
10+
},
11+
12+
_bboxDeltas: {
13+
"country": {
14+
"latD": 29.4912965,
15+
"lngD": 122.871094
16+
},
17+
"region": {
18+
"latD": 2.2116335,
19+
"lngD": 7.6794435
20+
},
21+
"district": {
22+
"latD": 0.2752005,
23+
"lngD": 0.9599305
24+
},
25+
"place": {
26+
"latD": 0.1496885,
27+
"lngD": 0.4837415
28+
},
29+
"street": {
30+
"latD": 0.004543,
31+
"lngD": 0.015117
32+
},
33+
"house": {
34+
"latD": 0.0011355,
35+
"lngD": 0.0037795
36+
},
37+
"default": {
38+
"latD": 0.1,
39+
"lngD": 0.1
40+
}
41+
},
42+
43+
getBBox: function ( center, type ) {
44+
type = type in this._bboxDeltas ? type : 'default';
45+
var deltas = this._bboxDeltas[type];
46+
return L.latLngBounds(
47+
L.latLng(center.lat - deltas.latD, center.lng - deltas.lngD ),
48+
L.latLng(center.lat + deltas.latD, center.lng + deltas.lngD )
49+
)
50+
},
51+
52+
geocode: function (query, cb, context) {
53+
Util.jsonp(this.options.geocoderUrl, {
54+
q: query
55+
}, function(data) {
56+
cb.call(context, this._prepareResult(data));
57+
}, this, 'callback');
58+
},
59+
60+
reverse: function(location, scale, cb, context) {
61+
Util.jsonp(this.options.reverseGeocoderUrl , {
62+
lat: location.lat,
63+
lon: location.lng,
64+
houses : true
65+
}, function(data) {
66+
cb.call(context, this._prepareResult(data));
67+
}, this, 'callback');
68+
},
69+
_prepareResult: function (data) {
70+
var _this = this;
71+
var features = [].concat(Util.extract(data, 'result.address.0.features', []), Util.extract(data, 'result.address.1.features', []));
72+
return features.map(function(feature){
73+
var feats = L.geoJson(feature);
74+
var bounds = feats && feats.getBounds(),
75+
center = bounds.getCenter();
76+
var bbox = _this.getBBox(center, feature.properties.type);
77+
var name = [feature.properties.title, feature.properties.description]
78+
.filter(function(value){ return !! value; })
79+
.join(', ');
80+
return {
81+
name: name,
82+
bbox: bbox,
83+
center: bounds.getCenter()
84+
}
85+
});
86+
}
87+
}),
88+
89+
factory: function(options) {
90+
return new L.Control.Geocoder.Sputnik(options);
91+
}
92+
};

src/index.js

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,10 @@
11
var L = require('leaflet'),
22
Control = require('./control'),
3-
Nominatim = require('./geocoders/nominatim'),
4-
Bing = require('./geocoders/bing'),
5-
MapQuest = require('./geocoders/mapquest'),
6-
Mapbox = require('./geocoders/mapbox'),
7-
What3Words = require('./geocoders/what3words'),
8-
Google = require('./geocoders/google'),
9-
Photon = require('./geocoders/photon'),
10-
Mapzen = require('./geocoders/mapzen'),
11-
ArcGis = require('./geocoders/arcgis'),
12-
HERE = require('./geocoders/here');
3+
Sputnik = require('./geocoders/sputnik');
134

145
module.exports = L.Util.extend(Control.class, {
15-
Nominatim: Nominatim.class,
16-
nominatim: Nominatim.factory,
17-
Bing: Bing.class,
18-
bing: Bing.factory,
19-
MapQuest: MapQuest.class,
20-
mapQuest: MapQuest.factory,
21-
Mapbox: Mapbox.class,
22-
mapbox: Mapbox.factory,
23-
What3Words: What3Words.class,
24-
what3words: What3Words.factory,
25-
Google: Google.class,
26-
google: Google.factory,
27-
Photon: Photon.class,
28-
photon: Photon.factory,
29-
Mapzen: Mapzen.class,
30-
mapzen: Mapzen.factory,
31-
ArcGis: ArcGis.class,
32-
arcgis: ArcGis.factory,
33-
HERE: HERE.class,
34-
here: HERE.factory
6+
Sputnik: Sputnik.class,
7+
sputnik: Sputnik.factory
358
});
369

3710
L.Util.extend(L.Control, {

src/util.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ var L = require('leaflet'),
3838
})();
3939

4040
module.exports = {
41+
extract: function extract(root, path, def){
42+
var key,
43+
val = !!root ? root : this,
44+
arr = String(path).replace(/'|"|\]/g,'').replace(/\[/g,'.').split('.');
45+
while ((key = arr.shift()) && 'object' == typeof val && val) {
46+
val = 'undefined' == typeof val[key]? ('undefined' == typeof def? false : def) : val[key];
47+
}
48+
return val;
49+
},
50+
4151
jsonp: function(url, params, callback, context, jsonpParam) {
4252
var callbackId = '_l_geocoder_' + (lastCallbackId++);
4353
params[jsonpParam || 'callback'] = callbackId;

test/browserify.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<title>Leaflet Control Geocoder</title>
55

6-
<meta name='viewport' content='width=device-width, user-scalable=no initial-scale=1, maximum-scale=1'>
6+
<meta name='viewport' content='width=device-width, user-scalable=no initial-scale=1, maximum-scale=1'>
77

88
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
99
<link rel="stylesheet" href="../dist/Control.Geocoder.css" />

test/browserify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var L = require('leaflet');
22
require('../dist/Control.Geocoder');
33

44
var map = L.map('map').setView([0, 0], 2),
5-
geocoder = L.Control.Geocoder.mapzen('search-DopSHJw'),
5+
geocoder = L.Control.Geocoder.sputnik(),
66
control = L.Control.geocoder({
77
geocoder: geocoder
88
}).addTo(map),

test/position.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<head>
44
<title>Leaflet Control Geocoder</title>
55

6-
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
6+
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.1/dist/leaflet.css" />
77
<link rel="stylesheet" href="../Control.Geocoder.css" />
88

9-
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet-src.js"></script>
9+
<script src="https://unpkg.com/leaflet@1.0.1/dist/leaflet.js"></script>
1010
<script src="../Control.Geocoder.js"></script>
1111
<style type="text/css">
1212
body {

test/touch.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
55
<title>Leaflet Control Geocoder</title>
66

7-
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
7+
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.1/dist/leaflet.css" />
88
<link rel="stylesheet" href="../Control.Geocoder.css" />
99

10-
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet-src.js"></script>
10+
<script src="https://unpkg.com/leaflet@1.0.1/dist/leaflet.js"></script>
1111
<script src="../Control.Geocoder.js"></script>
1212
<style type="text/css">
1313
body {

0 commit comments

Comments
 (0)