-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.js
More file actions
453 lines (366 loc) · 14.9 KB
/
Copy pathfunctions.js
File metadata and controls
453 lines (366 loc) · 14.9 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
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
// Your functions
//
//
var layers ;
var currentBusStopLayers ;
var basicBusStopLayers ;
var filteredBusStopLayers ;
// onCreate : This function is called when page began.
function onCreate() {
// area.geojason.
$.getJSON('data/area01.geojson', function(data) {
createAreaLayer(data).addTo(map);
});
$.getJSON('data/area02.geojson', function(data) {
createAreaLayer(data).addTo(map);
});
layers = new Array();
basicBusStopLayers = new Array();
filteredBusStopLayers = new Array();
// train data.
$.getJSON('./data/public_transport/train/train_station.geojson', function(data) {
layers.push(createTrainStationLayer(data)) ;
});
$.getJSON('./data/public_transport/train/train_line.geojson', function(data) {
layers.push(createTrainLineLayer(data));
});
// bus data.
$.getJSON('./data/public_transport/bus/bus_stop01.geojson', function(data) {
basicBusStopLayers.push(createBusStopLayer(data, null) ) ;
});
$.getJSON('./data/public_transport/bus/bus_stop02.geojson', function(data) {
basicBusStopLayers.push(createBusStopLayer(data, null)) ;
});
$.getJSON('./data/public_transport/bus/bus_root01.geojson', function(data) {
basicBusStopLayers.push(createBusRootLayer(data, null)) ;
});
$.getJSON('./data/public_transport/bus/bus_root02.geojson', function(data) {
basicBusStopLayers.push(createBusRootLayer(data, null)) ;
});
// Load datas
var markerIcon = L.icon({
iconUrl: 'nursery_icon.png',
iconSize: [30, 30],
popupAnchor: [0, -15]
});
$.getJSON('./data/data.geojson', function(data) {
L.geoJson(data, {
pointToLayer: function(geoJsonPoint, latlng) {
return L.marker(latlng, {icon: markerIcon});
},
onEachFeature: function(feature, layer) {
var popupContents = createNurseryContent(feature) ;
layer.bindPopup(popupContents);
layer.on({
mouseover: function(e){
info.update(popupContents);
},
mouseout: function(e){
},
click: function(e){
}
});
}
}).addTo(map);
});
currentBusStopLayers = basicBusStopLayers ;
map.on('zoomend', function(e) {
if (e.target._zoom > 14) {
for (var i=0; i<layers.length; i++) {
layers[i].addTo(map) ;
}
if (currentBusStopLayers == basicBusStopLayers) {
for (var i=0; i<currentBusStopLayers.length; i++) {
currentBusStopLayers[i].addTo(map) ;
}
}
} else {
for (var i=0; i<layers.length; i++) {
layers[i].remove(map) ;
}
if (currentBusStopLayers == basicBusStopLayers) {
for (var i=0; i<currentBusStopLayers.length; i++) {
currentBusStopLayers[i].remove(map) ;
}
}
}
}) ;
}
// onMapClick : This function is called when map was clicked.
function onMapClick(e) {
//popup.setLatLng(e.latlng).setContent("You clicked the map at " + e.latlng.toString()).openOn(map);
}
function createNurseryContent(feature) {
var popupContents = '<h4>練馬保育園マップ</h4>';
if (feature && feature.properties) {
var iconFilePath = "nursery_icon.png" ;
popupContents = "<img src=\"" + iconFilePath + "\" width=\"30\"/>";
popupContents += "<h2>" + feature.properties.Name + "</h2>";
popupContents += "<table>"
popupContents += "<tr><td>種別 </td><td>" + feature.properties.Type + "</td></tr>" ;
popupContents += "<tr><td>電話番号 </td><td>" + feature.properties.TEL + "</td></tr>" ;
popupContents += "<tr><td>住所 </td><td>" + feature.properties.Add1 + feature.properties.Add2 + "</td></tr>" ;
popupContents += "<tr><td>定員 </td><td>" + feature.properties.Capall + "</td></tr>" ;
popupContents += "<tr><td>開園 </td><td>" + feature.properties.Open + "</td></tr>" ;
popupContents += "<tr><td>閉園 </td><td>" + feature.properties.Close_reg + "</td></tr>" ;
popupContents += "<tr><td>延長 </td><td>" + feature.properties.Close + "</td></tr>" ;
popupContents += "</table>" ;
popupContents += "<br />" + "<a href=\"" + feature.properties.Url + "\">" + "詳細" + "</a>" ;
}
return popupContents ;
}
function createAreaLayer(data) {
return L.geoJson(data, {
style : function(feature) {
if (feature.properties.N03_003 == "練馬区") {
return {
fillColor: 'cyan',
weight: 2,
opacity: 1,
color: 'black', //Outline color
fillOpacity: 0.1
};
} else {
return {
fillColor: 'gray',
weight: 2,
opacity: 1,
color: 'black', //Outline color
fillOpacity: 0.1
};
}
}
}) ;
}
var currentBusStopFeature ;
function createBusStopLayer(data, filterFunc) {
var busIcon = L.icon({
iconUrl: 'data/public_transport/bus/bus_icon.png',
iconSize: [20, 20],
popupAnchor: [0, -10],
});
var filteredBusIcon = L.icon({
iconUrl: 'data/public_transport/bus/filtered_bus_icon.png',
iconSize: [20, 20],
popupAnchor: [0, -10],
}) ;
var currentBusIcon = L.icon({
iconUrl: 'data/public_transport/bus/filtered_bus_icon.png',
iconSize: [40, 40],
popupAnchor: [0, -20],
}) ;
return L.geoJson(data, {
filter: function(feature) {
if (filterFunc != null) {
return filterFunc(feature)
} else {
return true ;
}
},
pointToLayer: function(feature, latlng) {
if (filterFunc != null) {
if (currentBusStopFeature.properties.P11_001 == feature.properties.P11_001) {
return L.marker(latlng, {icon : currentBusIcon}) ;
} else {
return L.marker(latlng, {icon : filteredBusIcon}) ;
}
} else {
return L.marker(latlng, {icon : busIcon}) ;
}
},
onEachFeature: function(feature, layer) {
var iconFilePath = 'data/public_transport/bus/bus_icon.png' ;
var popupContents = "<img src=\"" + iconFilePath + "\" width=\"30\"/>";
popupContents += "<h2>" + feature.properties.P11_001 + "</h2>";
var companies = feature.properties.P11_003_1.split(",");
var identifies = feature.properties.P11_004_1.split(",");
popupContents += "<table>" ;
for (var i=0; i<companies.length; i++) {
popupContents += "<tr><td>" + companies[i] + "</td><td>" + identifies[i] + "</td><tr>" ;
}
popupContents += "</table><br />" ;
popupContents += "<button id=\"search_root\" onclick=\"onSearchRoot()\">検索</button>" ;
popupContents += "<button id=\"search_reset\" onclick=\"onSearchReset()\">リセット</button>" ;
layer.bindPopup(popupContents);
layer.on({
mouseover: function(e){
currentBusStopFeature = feature ;
info.update(popupContents);
},
mouseout: function(e){
},
click: function(e){
currentBusStopFeature = feature ;
}
});
}
})
}
function createBusRootLayer(data, filterFunc) {
return L.geoJson(data, {
filter: function(feature) {
if (filterFunc != null) {
return filterFunc(feature)
} else {
return true ;
}
},
style: function(feature) {
return {
weight: 2,
opacity: 1,
color: 'green', //Outline color
};
}
}) ;
}
function createTrainStationLayer(data) {
var markers = new Array() ;
var layer = L.geoJson(data, {
pointToLayer: function(geoJsonPoint, latlng) {
return L.marker(latlng) ;
},
onEachFeature: function(feature, layer) {
var latlng = [
(feature.geometry.coordinates[0][0][1] + feature.geometry.coordinates[0][1][1])/2,
(feature.geometry.coordinates[0][0][0] + feature.geometry.coordinates[0][1][0])/2
] ;
var iconFilePath = "" ;
if (feature.properties.N02_004 == "西武鉄道" &&
(feature.properties.N02_003 == "池袋線" || feature.properties.N02_003 == "豊島線" || feature.properties.N02_003 == "西武有楽町線")) {
iconFilePath = 'data/public_transport/train/train_icon_seibuikebukuro.png' ;
} else if (feature.properties.N02_004 == "西武鉄道" && feature.properties.N02_003 == "新宿線") {
iconFilePath = 'data/public_transport/train/train_icon_seibushinjuku.png' ;
} else if (feature.properties.N02_004 == "東京地下鉄" && feature.properties.N02_003 == "8号線有楽町線") {
iconFilePath = 'data/public_transport/train/train_icon_yurakucho.png' ;
} else if (feature.properties.N02_004 == "東京都" && feature.properties.N02_003 == "12号線大江戸線") {
iconFilePath = 'data/public_transport/train/train_icon_ooedo.png' ;
} else if (feature.properties.N02_004 == "東武鉄道" && feature.properties.N02_003 == "東上本線") {
iconFilePath = 'data/public_transport/train/train_icon_tobutojo.png' ;
} else if (feature.properties.N02_004 == "東日本旅客鉄道" && feature.properties.N02_003 == "中央線") {
iconFilePath = 'data/public_transport/train/train_icon_jr_chuo.png' ;
} else if (feature.properties.N02_004 == "東京地下鉄" &&
(feature.properties.N02_003 == "4号線丸ノ内線" || feature.properties.N02_003 == "4号線丸ノ内線分岐線")) {
iconFilePath = 'data/public_transport/train/train_icon_marunouchi.png' ;
} else if (feature.properties.N02_004 == "京王電鉄" && feature.properties.N02_003 == "井の頭線") {
iconFilePath = 'data/public_transport/train/train_icon_inogashira.png' ;
} else if (feature.properties.N02_004 == "東京地下鉄" && feature.properties.N02_003 == "5号線東西線") {
iconFilePath = 'data/public_transport/train/train_icon_tozai.png' ;
} else {
iconFilePath = 'data/public_transport/train/train_icon.png' ;
}
var trainIcon = L.icon({
iconUrl: iconFilePath,
iconSize: [30, 30],
popupAnchor: [0, -15],
});
var marker = L.marker(latlng, {icon : trainIcon}) ;
var popupContents = "<img src=\"" + iconFilePath + "\" width=\"30\"/>";
popupContents += "<h2>" + feature.properties.N02_005 + "</h2>";
popupContents += "<table>" ;
popupContents += "<tr><td>" + feature.properties.N02_004 + "</td><td>" + feature.properties.N02_003 + "</td><tr>" ;
popupContents += "</table>" ;
marker.bindPopup(popupContents);
marker.on({
mouseover: function(e){
info.update(popupContents);
},
mouseout: function(e){
},
click: function(e){
}
});
markers.push(marker) ;
}
});
for (var i=0; i<markers.length; i++) {
layer.addLayer(markers[i]) ;
}
return layer ;
}
function createTrainLineLayer(data) {
return L.geoJson(data, {
style: function(feature) {
return {
weight: 2,
opacity: 1,
color: 'green', //Outline color
};
}
}) ;
}
function onSearchRoot(e) {
for (var i=0; i<currentBusStopLayers.length; i++) {
currentBusStopLayers[i].remove(map) ;
}
filteredBusStopLayers = new Array();
currentBusStopLayers = filteredBusStopLayers ;
var onBusStopFilter = function(feature) {
var currentCompanies = currentBusStopFeature.properties.P11_003_1.split(",");
var currentIdentifies = currentBusStopFeature.properties.P11_004_1.split(",");
var array = Array()
for (var i=0; i<currentCompanies.length; i++) {
var key = currentCompanies[i] + currentIdentifies[i] ;
array.push(key) ;
}
var companies = feature.properties.P11_003_1.split(",");
var identifies = feature.properties.P11_004_1.split(",");
for (var i=0; i<companies.length; i++) {
var key = companies[i] + identifies[i] ;
if (array.find(function(element) {
return (element == key);
}) != null) {
return true ;
}
}
return false ;
} ;
var onBusRootFilter = function(feature) {
var currentCompanies = currentBusStopFeature.properties.P11_003_1.split(",");
var currentIdentifies = currentBusStopFeature.properties.P11_004_1.split(",");
var array = Array()
for (var i=0; i<currentCompanies.length; i++) {
var key = currentCompanies[i] + currentIdentifies[i] ;
array.push(key) ;
}
var key = feature.properties.N07_002 + feature.properties.N07_003 ;
if (array.find(function(element) {
return (element == key);
}) != null) {
return true ;
} else {
return false ;
}
} ;
$.getJSON('./data/public_transport/bus/bus_stop01.geojson', function(data) {
var layer = createBusStopLayer(data, onBusStopFilter);
filteredBusStopLayers.push(layer) ;
layer.addTo(map) ;
});
$.getJSON('./data/public_transport/bus/bus_stop02.geojson', function(data) {
var layer = createBusStopLayer(data, onBusStopFilter) ;
filteredBusStopLayers.push(layer) ;
layer.addTo(map) ;
});
$.getJSON('./data/public_transport/bus/bus_root01.geojson', function(data) {
var layer = createBusRootLayer(data, onBusRootFilter) ;
filteredBusStopLayers.push(layer) ;
layer.addTo(map) ;
});
$.getJSON('./data/public_transport/bus/bus_root02.geojson', function(data) {
var layer = createBusRootLayer(data, onBusRootFilter) ;
filteredBusStopLayers.push(layer) ;
layer.addTo(map) ;
});
}
function onSearchReset() {
for (var i=0; i<filteredBusStopLayers.length; i++) {
filteredBusStopLayers[i].remove(map) ;
}
currentBusStopLayers = basicBusStopLayers ;
if (map._zoom > 14) {
for (var i=0; i<currentBusStopLayers.length; i++) {
currentBusStopLayers[i].addTo(map) ;
}
}
}