-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinteractiveMap.html
248 lines (205 loc) · 6.09 KB
/
interactiveMap.html
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<!DOCTYPE html>
<html lang="en">
<head>
<base target="_top">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Interactive Leaflet Map</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.2/dist/leaflet.css" integrity="sha256-sA+zWATbFveLLNqWO2gtiw3HL/lh1giY/Inf1BJ0z14=" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.9.2/dist/leaflet.js" integrity="sha256-o9N1jGDZrf5tS+Ft4gbIK7mYMipq9lqpVJ91xHSyKhg=" crossorigin=""></script>
<style>
html, body {
height: 100%;
margin: 0;
}
.leaflet-container {
height: 650px;
width: 1270px;
max-width: 100%;
max-height: 100%;
}
</style>
</head>
<body>
<div class="container-fluid">
<div id='map'></div>
</div>
<script src="TrainStation.js" type="text/javascript"></script>
<script>
const map = L.map('map').setView([1.35, 103.80], 12);
const tiles = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
function onEachFeature(feature, layer) {
let popupContent = `<p>${feature.properties.STN_NAME + " (" + feature.properties.STN_NO + ")"}</p>`;
if (feature.properties && feature.properties.popupContent) {
popupContent += feature.properties.popupContent;
}
layer.bindPopup(popupContent);
}
var markerIcon = L.Icon.extend({
options: {
iconSize: [30, 30],
iconAnchor: [12, 23],
popupAnchor: [4, -1]
}
});
var greenIcon = new markerIcon({iconUrl: 'marker-green.png'}),
redIcon = new markerIcon({iconUrl: 'marker-red.png'}),
orangeIcon = new markerIcon({iconUrl: 'marker-orange.png'}),
blueIcon = new markerIcon({iconUrl: 'marker-blue.png'}),
purpleIcon = new markerIcon({iconUrl: 'marker-purple.png'}),
brownIcon = new markerIcon({iconUrl: 'marker-brown.png'}),
grIcon = new markerIcon({iconUrl: 'marker-green-red.png'}),
gpIcon = new markerIcon({iconUrl: 'marker-green-purple.png'}),
goIcon = new markerIcon({iconUrl: 'marker-green-orange.png'}),
gbIcon = new markerIcon({iconUrl: 'marker-green-blue.png'}),
rbnIcon = new markerIcon({iconUrl: 'marker-red-brown.png'}),
roIcon = new markerIcon({iconUrl: 'marker-red-orange.png'}),
rbIcon = new markerIcon({iconUrl: 'marker-red-blue.png'}),
opIcon = new markerIcon({iconUrl: 'marker-orange-purple.png'}),
obIcon = new markerIcon({iconUrl: 'marker-orange-blue.png'}),
obnIcon = new markerIcon({iconUrl: 'marker-orange-brown.png'}),
pbIcon = new markerIcon({iconUrl: 'marker-purple-blue.png'}),
dhobyghautIcon = new markerIcon({iconUrl: 'marker-dhobyghaut.png'}),
marinabayIcon = new markerIcon({iconUrl: 'marker-marinabay.png'}),
lrtIcon = new markerIcon({iconUrl: 'marker-lrt.png'});
const trainStationLayer = L.geoJSON(trainStations, {
style(feature) {
return feature.properties && feature.properties.style;
},
onEachFeature,
pointToLayer(feature, latlng) {
var stnName = feature.properties.STN_NAME
var stnNo = feature.properties.STN_NO
if (stnNo.indexOf("/") === -1) {
// green
if (stnNo.startsWith("EW") || stnNo.startsWith("CG")) {
return L.marker(latlng, {
icon: greenIcon
})
}
// red
if (stnNo.startsWith("NS")) {
return L.marker(latlng, {
icon: redIcon
})
}
// orange
if (stnNo.startsWith("CC")) {
return L.marker(latlng, {
icon: orangeIcon
})
}
// blue
if (stnNo.startsWith("DT")) {
return L.marker(latlng, {
icon: blueIcon
})
}
// purple
if (stnNo.startsWith("NE")) {
return L.marker(latlng, {
icon: purpleIcon
})
}
// brown
if (stnNo.startsWith("TE")) {
return L.marker(latlng, {
icon: brownIcon
})
}
// lrt
if (stnName.match("LRT")) {
return L.marker(latlng, {
icon: lrtIcon
})
}
}
// 2 or more mrt lines
else {
// dhoby ghaut mrt
if (stnName.match("DHOBY GHAUT")) {
return L.marker(latlng, {
icon: dhobyghautIcon
})
}
// marina bay mrt
else if (stnName.match("MARINA BAY")) {
return L.marker(latlng, {
icon: marinabayIcon
})
}
// green and red
if (stnNo.match("EW") && stnNo.match("NS")) {
return L.marker(latlng, {
icon: grIcon
})
}
// green and purple
if (stnNo.match("EW") && stnNo.match("NE")) {
return L.marker(latlng, {
icon: gpIcon
})
}
// green and orange
if (stnNo.match("EW") && stnNo.match("CC")) {
return L.marker(latlng, {
icon: goIcon
})
}
// green and blue
if ( (stnNo.match("EW") && stnNo.match("DT")) || (stnNo.match("CG") && stnNo.match("DT")) ) {
return L.marker(latlng, {
icon: gbIcon
})
}
// red and brown
if (stnNo.match("NS") && stnNo.match("TE")) {
return L.marker(latlng, {
icon: rbnIcon
})
}
// red and orange
if (stnNo.match("NS") && stnNo.match("CC")) {
return L.marker(latlng, {
icon: roIcon
})
}
// red and blue
if (stnNo.match("NS") && stnNo.match("DT")) {
return L.marker(latlng, {
icon: rbIcon
})
}
// orange and purple
if (stnNo.match("CC") && stnNo.match("NE")) {
return L.marker(latlng, {
icon: opIcon
})
}
// orange and blue
if ( (stnNo.match("CC") && stnNo.match("DT")) || (stnNo.match("CE") && stnNo.match("DT")) ) {
return L.marker(latlng, {
icon: obIcon
})
}
// orange and brown
if (stnNo.match("CC") && stnNo.match("TE")) {
return L.marker(latlng, {
icon: obnIcon
})
}
// purple and blue
if (stnNo.match("NE") && stnNo.match("DT")) {
return L.marker(latlng, {
icon: pbIcon
})
}
}
}
}).addTo(map);
</script>
</body>
</html>