-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfront.js
68 lines (68 loc) · 2.73 KB
/
front.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*global osmtogeojson*/
L.K.Map.addInitHook(function () {
this.whenReady(function () {
this.settingsForm.addElement(['osmdatalayer', {handler: L.K.Switch, label: 'OSM data layer (alt-ctrl-D)'}]);
var urlTemplate = 'http://overpass-api.de/api/interpreter?data=[out:json];(node({s},{w},{n},{e});<;);out;',
url, bounds,
pointToLayer = function (feature, latlng) {
return L.circleMarker(latlng);
},
onEachFeature = function (feature, layer) {
layer.bindPopup(L.K.Util.renderPropertiesTable(feature.properties));
};
this.osmdatalayer = L.geoJson(null, {pointToLayer: pointToLayer, onEachFeature: onEachFeature});
var fetch = function () {
if (L.K.Config.osmdatalayer) {
this.setState('loading');
bounds = this.getBounds();
url = L.Util.template(urlTemplate, {
e: bounds.getEast(),
s: bounds.getSouth(),
w: bounds.getWest(),
n: bounds.getNorth()
});
L.K.Xhr.get(url, {
callback: function (status, data) {
if (status === 200 && data) {
this.osmdatalayer.clearLayers();
this.osmdatalayer.addData(osmtogeojson(JSON.parse(data), {flatProperties: true}));
this.osmdatalayer.addTo(this);
}
this.unsetState('loading');
},
context: this
});
} else {
this.removeLayer(this.osmdatalayer);
}
};
this.on('settings:synced', function (e) {
if (e.helper.field === 'osmdatalayer') L.bind(fetch, this)();
}, this);
this.on('moveend', fetch);
var commandCallback = function () {
L.K.Config.osmdatalayer = !L.K.Config.osmdatalayer;
L.bind(fetch, this)();
this.settingsForm.fetchAll();
};
this.commands.add({
keyCode: L.K.Keys.D,
ctrlKey: true,
altKey: true,
callback: commandCallback,
context: this,
name: 'OSM data layer: toggle'
});
var openInOSM = function () {
window.open(`https://openstreetmap.org#map=${this.getZoom()}/${this.getCenter().lat}/${this.getCenter().lng}`, '_blank');
};
this.commands.add({
keyCode: L.K.Keys.O,
altKey: true,
ctrlKey: true,
callback: openInOSM,
context: this,
name: 'OSM: open in openstreetmap.org'
});
});
});