-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.js
178 lines (160 loc) · 4.71 KB
/
map.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
let map = L.map("mainmap").setView([24.47, 103.1], 10);
let currentMarker = 0;
L.tileLayer(
"https://api.mapbox.com/styles/v1/waisaed/cjy64a0ag1aln1cqikvlq5mhx/tiles/256/{z}/{x}/{y}@2x?access_token={accessToken}",
{
attribution:
'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 18,
id: "cjy64a0ag1aln1cqikvlq5mhx",
accessToken:
"pk.eyJ1Ijoid2Fpc2FlZCIsImEiOiJjanQzcjg4djgwdnBiNDNsbGg3eWhhbGtmIn0.OMUaek-cJfJhpH1z6Gg5gA"
}
).addTo(map);
//create info window
let info = L.control();
info.onAdd = function(map) {
this._div = L.DomUtil.create("div", "info"); // create a div with a class "info"
this.update();
return this._div;
};
//legend colors
function getColor(d) {
return d === "Reduce Source (ultimate)"
? "#d0c547"
: d === "Reduce Input of pollution into the lake(s)"
? "#377eb8"
: d === "Increase water regeneration/lake quality (proximate)"
? "#de2d26"
: "";
}
//create legend
let legend = L.control({ position: "bottomright" });
legend.onAdd = function(map) {
let div = L.DomUtil.create("div", "info legend"),
labels = ["<h4>Type of Intervention:</h4>"],
categories = [
"Reduce Source (ultimate)",
"Reduce Input of pollution into the lake(s)",
"Increase water regeneration/lake quality (proximate)"
];
for (var i = 0; i < categories.length; i++) {
div.innerHTML += labels.push(
'<i class="circle" style="background:' +
getColor(categories[i]) +
'"></i> ' +
(categories[i] ? categories[i] : "+")
);
}
div.innerHTML = labels[0] + labels.slice(1).join("<br>");
return div;
};
legend.addTo(map);
// update info window
info.update = function() {
this._div.innerHTML =
"<div class='info-inner'>" +
"<h2>Lake Restoration Measures</h2> " +
"<p class='infotext'>Click the markers to explore examples of lake restoration efforts.</p>" +
"</div";
};
info.addTo(map);
//create markers feature group and add to map
let siteMarkers = L.featureGroup();
siteMarkers.addTo(map);
//marker colors
const blueIcon = new L.Icon({
iconUrl:
"https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-blue.png",
shadowUrl:
"https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png",
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
}),
redIcon = new L.Icon({
iconUrl:
"https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-red.png",
shadowUrl:
"https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png",
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
}),
yellowIcon = new L.Icon({
iconUrl:
"https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-yellow.png",
shadowUrl:
"https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png",
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
});
function whichIcon(i) {
switch (markers["markers"][i]["category"]) {
case "proximate":
return "redIcon";
case "ultimate":
return "yellowIcon";
case "input":
return "blueIcon";
}
}
// is there an image?
function isImage(i) {
imgUrl = markers["markers"][i]["image"];
if (imgUrl != undefined) {
return "<img class='inpopup' src='assets/" + imgUrl + "'>";
} else {
return "";
}
}
//add all the markers to the feature group
for (let i = 0; i < markers["markers"].length; i++) {
addmarker = new L.marker(
[markers["markers"][i]["lat"], markers["markers"][i]["long"]],
{ icon: eval(whichIcon(i)) }
)
.bindPopup(
"<h3>" +
markers["markers"][i]["header"] +
"</h3><div class='inpopup'>" +
markers["markers"][i]["body"] +
"</div>" +
isImage(i),
{ maxWidth: 450 }
)
.addTo(siteMarkers);
}
//listeners
/* function highlightFeature(e) {
let layer = e.target;
layer.setStyle({
weight: 3,
color: "#ffaa33",
dashArray: "",
fillOpacity: 0.3,
opacity: 0.65
});
if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
layer.bringToFront();
}
info.update(layer.feature.properties);
}
function resetHighlight(e) {
geojson.resetStyle(e.target);
info.update();
}
function zoomToFeature(e) {
map.fitBounds(e.target.getBounds());
}
function onEachFeature(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
click: zoomToFeature
});
} */