map.js
2.05 KB
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
69
var OSMAP = {
map: null,
marker: new Array,
popup: new Array,
loc: null,
layerLine: null,
layerFeatures: null,
setMarker: function (index, latlng) {
if (!this.marker[index]) {
this.marker[index] = L.marker(latlng)
.addTo(this.map);
} else {
this.marker[index].setLatLng(latlng);
}
},
popupMarker: function (index, text) {
this.popup[index] = this.marker[index].bindPopup(text)
.openPopup();
this.popup[index].autoPan = true;
},
setTooltip: function (index, text) {
if (this.marker[index]) {
this.marker[index].bindTooltip(text).openTooltip();
}
},
setCenter: function(latlng)
{
this.map.setView(latlng);
},
init: function (div, lat, lng, zoom)
{
if (this.map) return;
this.map = L.map('map').setView([lat, lng], zoom);
L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a>'
}).addTo(this.map);
},
getCurrentLocation: function()
{
var options = {
enableHighAccuracy: true,
timeout: 10000,
maximumAge: 10000,
};
navigator.geolocation.getCurrentPosition(function (pos) { OSMAP.loc = pos.coords; }, null, options);
},
line: function (line, lineStyle, popup)
{
this.layerLine = L.geoJSON(line, {
style: lineStyle,
onEachFeature: function (f, l) {
l.bindPopup(popup);
}
}).addTo(this.map);
},
features: function (features, style) {
this.layerFeatures = L.geoJSON(features, {
style: style,
onEachFeature: function (f, l) {
l.bindPopup("<strong>" + f.properties.name + "</strong><br/>" + f.properties.info);
}
}).addTo(this.map);
},
clear: function()
{
if (this.layerLine) this.map.removeLayer(this.layerLine);
if (this.layerFeatures) this.map.removeLayer(this.layerFeatures);
}
};