-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleaflet_map.js
More file actions
61 lines (56 loc) · 1.63 KB
/
leaflet_map.js
File metadata and controls
61 lines (56 loc) · 1.63 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
var map = L.map("mapbox").setView([54.517461284757104, -125.090299112331], 4);
L.tileLayer(
"https://stamen-tiles-{s}.a.ssl.fastly.net/toner/{z}/{x}/{y}{r}.{ext}",
{
// attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> — Map data © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
maxZoom: 11,
minZoom: 4,
ext: "png",
}
).addTo(map);
map.setMaxBounds(map.getBounds());
// fetch data from json file using ajax
var municipalities = [];
$.ajax({
url: "./Data/GeoJson/municpalities_espg4326_filtered.json",
dataType: "json",
success: function (data) {
municipalities = data;
console.log("fetched geojson data");
},
async: false,
});
function whenClicked(e) {
var style = shapeClicked(e.target.feature.properties, e.target.options.color);
if (style != null) {
e.target.setStyle(style);
}
}
function mouseOver(e) {
this.unbindTooltip();
if (!this.isPopupOpen())
this.bindTooltip(
"<div style='background:white; padding:1px 3px 1px 3px'><b>" +
e.target.feature.properties.mun_name +
"</b></div>",
{
direction: "left",
permanent: false,
sticky: true,
offset: [10, 0],
opacity: 0.75,
className: "leaflet-tooltip-own",
}
).openTooltip();
}
function onEachFeature(feature, layer) {
layer.on({
click: whenClicked,
mouseover: mouseOver,
});
}
var geojsonLayer = new L.GeoJSON(municipalities, {
style: default_feature_style,
onEachFeature: onEachFeature,
});
geojsonLayer.addTo(map);