-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
3256 lines (3101 loc) · 123 KB
/
index.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
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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<link rel = "stylesheet" href = "./CSS/Original_Style_000.css" />
<head>
<meta charset="utf-8" />
<title> How to Use the Leaflet.js on Github </title>
<STYLE>
body {
background-color: #feeded;
background-image: url("./images/map-image.png");
background-repeat: repeat;
}
</STYLE>
</head>
<body>
<center>
<h1>How to draw maps by using the Leaflet.js</h1>
</center>
"Leaflet.js" is an open-source JavaScript library for interactive maps.
This document is a tutorial for beginners to use the "Leaflet.js".
I will show you how to draw a map, how to set markers and/or figures on the map step by step.
<br>
<h2>Step-1: Try to draw some Maps.</h2>
Let's try to draw the open street map as a first step. The source of html is as follows:
<br>
<a href = "./Leaflet_Tutrial_101_EN.html" target="_blank">Demo for Tutorial_101</a>: To draw an open street map.
<span id="code-block" style="height: 100px;">
<PRE>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Leaflet_Tutrial_101_EN.html 2019/7/19 by T. Fujita</title>
<meta charset="utf-8" />
<link rel = "stylesheet" href = "https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src = "https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<style>
html, body {
width: 99%;
height: 98%;
font-size: 14px;
z-index: 0;
}
</style>
<script>
function init() {
var map_101 = L.map('map_101').setView([51.5, 0.0], 8); // Set Latitude and Longitude for the center of Map, then 8 is a zoom level to show the Map.
mapLink = '<a href="https://openstreetmap.org">OpenStreetMap</a>'; // URL for attribution
L.tileLayer(
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { // set tile images for Map
attribution: 'Map data © ' + mapLink, // set the attribution
maxZoom: 18
}).addTo(map_101);
}
</script>
</head>
<body onload="init()">
<div id="map_101" style="width: 100%; height: 100%; border: solid 1px"></div>
</body>
</html>
</PRE>
</span>
<br><br>
Next is a try to change the map style that is Stamen designed. The change points are as follows:
<br>
<a href = "./Leaflet_Tutrial_102_EN.html" target="_blank">Demo for Tutorial_102</a>: To draw a Stamen Design map.
<span id="code-block" style="height: 100px;">
<PRE>
L.tileLayer('http://{s}.tile.stamen.com/{variant}/{z}/{x}/{y}.png', {
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>',
variant: 'toner-lite'
}).addTo(map_102); // The map No. is need to fit the id on the html.
</PRE>
</span>
<br><br>
Try again to change the map style. In this time, to use Esri designed map. Also, the change points are as follows:
<br>
<a href = "./Leaflet_Tutrial_103_EN.html" target="_blank">Demo for Tutorial_103</a>: To draw an Esri designed map.
<span id="code-block" style="height: 100px;">
<PRE>
L.tileLayer('http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles © <a href="http://www.esrij.com/"> Esri </a>'
}).addTo(map_103);
</PRE>
</span>
<br><br>
As a last of Step-1, it is a sample for how to select a map from several maps. The JavaScript section of html is as follows:
<br>
<a href = "./Leaflet_Tutrial_104_EN.html" target="_blank">Demo for Tutorial_104</a>: To select a map from several maps.
<span id="code-block" style="height: 100px;">
<PRE>
function init() {
var Basic_Map = new Array(); // This array is stored map url.
Basic_Map[ 0 ] = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
continuousWorld: false
});
Basic_Map[ 1 ] = L.tileLayer('http://{s}.tile.stamen.com/{variant}/{z}/{x}/{y}.png', {
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, ',
variant: 'toner-background'
});
Basic_Map[ 2 ] = L.tileLayer('http://{s}.tile.stamen.com/{variant}/{z}/{x}/{y}.png', {
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, ',
variant: 'toner-lite'
});
Basic_Map[ 3 ] = L.tileLayer('http://{s}.tile.stamen.com/{variant}/{z}/{x}/{y}.png', {
minZoom: 1,
maxZoom: 16,
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, ',
variant: 'watercolor'
});
Basic_Map[ 4 ] = L.tileLayer('http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles © <a href="http://www.esrij.com/"> Esri Japan </a>'
});
Basic_Map[ 5 ] = L.tileLayer('http://server.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer/tile/{z}/{y}/{x}', {
maxZoom: 13,
attribution: 'Tiles by <a href="http://www.esrij.com/"> Esri Japan </a>'
});
var map_104 = L.map('map_104').setView([51.5, 0.0], 8);
map_104.addLayer( Basic_Map[ 0 ] );
var baseMap = {
"OpenStreetMap": Basic_Map[ 0 ],
"Stamen Toner-Background": Basic_Map[ 1 ],
"Stamen Toner-Lite": Basic_Map[ 2 ],
"Stamen Watercolor": Basic_Map[ 3 ],
"Esri World Topo Map": Basic_Map[ 4 ],
"Esri Ocean Base Map": Basic_Map[ 5 ],
};
L.control.layers(baseMap).addTo(map_104); // Select a map tile
}
</PRE>
</span>
<br><br>
<h2>Step-2: Try to draw Overlays on the Map.</h2>
In the Step-2, I will show you how to draw some overlays based on the Tutorial_104 map. The source of over layers is as follows:
<br>
<a href = "./Leaflet_Tutrial_201_EN.html" target="_blank">Demo for Tutorial_201</a>: Draw some overlays based on Tutorial_104.
<span id="code-block" style="height: 100px;">
<PRE>
var Over_Layer = new Array();
Over_Layer[ 0 ] = L.tileLayer('http://{s}.tile.stamen.com/{variant}/{z}/{x}/{y}.png', {
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 {attribution.OpenStreetMap}',
variant: 'toner-hybrid'
});
Over_Layer[ 1 ] = L.tileLayer('http://{s}.tile.stamen.com/{variant}/{z}/{x}/{y}.png', {
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 {attribution.OpenStreetMap}',
variant: 'toner-lines'
});
Over_Layer[ 2 ] = L.tileLayer('http://{s}.tile.stamen.com/{variant}/{z}/{x}/{y}.png', {
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 {attribution.OpenStreetMap}',
variant: 'toner-labels'
});
Over_Layer[ 3 ] = L.tileLayer('http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png', {
attribution: "<a href='http://www.openseamap.org' target='_blank'>OpenSeaMap</a> contributors"
});
var overLay_201 = {
"Stamen-hybrid": Over_Layer[ 0 ],
"Stamen toner-lines": Over_Layer[ 1 ],
"Stamen toner-labels": Over_Layer[ 2 ],
"OpenSeaMap": Over_Layer[ 3 ],
};
L.control.layers(baseMap, overLay_201).addTo(map_201);
</PRE>
</span>
<br><br>
Next Overlays are based on the data from MODIS (MODerate resolution Imaging Spectroradiometer) and the earthquakes data from USGS (United States Geological Survey).
It is used some Leaflet Plugins for drawing these Overlays. The additional parts for html and JavaScript are as follows:
<br>
<a href = "./Leaflet_Tutrial_202_EN.html" target="_blank">Demo for Tutorial_202</a>: Added overlays for MODIS's data and USGS's earthquakes data.
<span id="code-block" style="height: 100px;">
<PRE>
<CODE class="red">Added to html section:</CODE>
<script src = "./Plugins\leaflet-GIBS-master\src/GIBSMetadata.js" ></script>
<script src = "./Plugins\leaflet-GIBS-master\src/GIBSLayer.js" ></script>
<script src = "./Plugins/leaflet-ajax-master/dist/leaflet.ajax.js" ></script>
<CODE class="red">Added to JavaScript section:</CODE>
Over_Layer[ 4 ] = new L.GIBSLayer('MODIS_Water_Mask', {
date: new Date('2018/11/15'),
transparent: true
});
Over_Layer[ 5 ] = new L.GeoJSON.AJAX(
// "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson",
// "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_week.geojson",
// "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojson",
// "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_week.geojson",
"https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.geojson",
// "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_month.geojson",
// "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_month.geojson",
// "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_month.geojson",
// "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.geojson",
{pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, {
radius: feature.properties.mag * feature.properties.mag / 3,
fillcolor: "#FF7800",
color: "#FF7800",
weight: 1,
opacity: 0.5,
fillOpacity: 0.5
}); },
onEachFeature: function (feature, layer) {
layer.bindPopup(new Date(feature.properties.time).toUTCString() + " / " + feature.properties.title);
}
});
</PRE>
</span>
<br><br>
<h2>Step-3: Try to show some Utilities on the Map.</h2>
As a Step-3, I will show you how to add following utilities to the map. Almost utilities are by using Leaflet Plugins.<br>
(1) Mini Map at the bottom of left side on the map.<br>
(2) Scale at the bottom of left side on the map.<br>
(3) Graticule lines on the map.<br>
(4) Mouse Position at the bottom of right side on the map.<br>
(5) Search Window at the top of right side on the map.<br>
<br>
The map data and the overlay data are separated from html, and then these data are stored as "Map_Data_EN.js".
In addition, I create "Leaflet_Graticule.js" and "Leaflet_Graticule.css" for drawing graticule lines. The source of html is as follows:
<br>
<a href = "./Leaflet_Tutrial_301_EN.html" target="_blank">Demo for Tutorial_301</a>: To show some Utilities on the Map.
<span id="code-block" style="height: 100px;">
<PRE>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Leaflet_Tutrial_301_EN.html 2019/7/19 by T. Fujita</title>
<meta charset = "utf-8" />
<link rel = "stylesheet" href = "https://unpkg.com/[email protected]/dist/leaflet.css" />
<link rel = "stylesheet" href = "./CSS/Leaflet_Graticule.css" />
<link rel = "stylesheet" href = "./Plugins/Leaflet-MousePosition-master/src/L.Control.MousePosition.css" />
<link rel = "stylesheet" href = "./Plugins/Leaflet-MiniMap-master/src/Control.MiniMap.css" />
<link rel = "stylesheet" href = "./Plugins/leaflet-control-osm-geocoder-master/Control.OSMGeocoder.css" />
<script src = "https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src = "./Plugins/leaflet-GIBS-master/src/GIBSMetadata.js" ></script>
<script src = "./Plugins/leaflet-GIBS-master/src/GIBSLayer.js" ></script>
<script src = "./Plugins/leaflet-ajax-master/dist/leaflet.ajax.js" ></script>
<script src = "./Plugins/Leaflet-MousePosition-master/src/L.Control.MousePosition.js" ></script>
<script src = "./Plugins/Leaflet-MiniMap-master/src/Control.MiniMap.js" ></script>
<script src = "./Plugins/leaflet-control-osm-geocoder-master/Control.OSMGeocoder_SRC.js" ></script>
<script src = "./JS/Map_Data_EN.js" ></script> // Separate map and overlay data as a js type of file.
<script src = "./JS/Leaflet_Graticule.js" ></script>
<style>
html, body {
width: 99%;
height: 98%;
font-size: 14px;
z-index: 0;
}
</style>
<script>
var map;
var ClickLat, ClickLon, Act_Zoom, Pre_Zoom;
var Mouse_Position = L.control.mousePosition( {position:'bottomright'} ); // Set Mouse Position
function init() {
map = L.map('map').setView([51.5, 0.0], 8);
map.addLayer( Basic_Map[ 0 ] );
L.control.layers(baseMap, overLay).addTo(map);
L.control.scale().addTo(map); // Show Scale
Mouse_Position.addTo(map); // Show Mouse Position
var osm2 = new L.TileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{minZoom: 0, maxZoom: 15, attribution: 'Map data © OpenStreetMap contributors' });
var miniMap = new L.Control.MiniMap(osm2, { toggleDisplay: true, position: 'bottomleft' }).addTo(map); // Show Mini Map
Grid_on_B(); // Set Graticule Lines
map.on('click', function(e) {
ClickLat = e.latlng.lat;
ClickLon = e.latlng.lng;
if(flag_grid == 1)
{
Act_Zoom = map.getZoom();
Act_Ctn = map.getCenter();
if(Act_Zoom != Pre_Zoom)
{
grid( grid_line_col ); // Show Graticule Lines
Pre_Zoom = Act_Zoom;
}
}
});
osmGeocoder = new L.Control.OSMGeocoder(); // Set Search Window
map.addControl(osmGeocoder); // Show Search Window
}
</script>
</head>
<body onload="init()">
<div id="map" style="width: 100%; height: 100%; border: solid 1px"></div>
</body>
</html>
</PRE>
</span>
<br><br>
<h2>Step-4: Try to show some Markers on the Map.</h2>
First of Step-4, I will show you how to set a fixed Marker with default configuration on the map.
After click this Marker, it is shown the name of point and link URL in a popup balloon.
The source for Marker's section of html is as follows:
<br>
<a href = "./Leaflet_Tutrial_401_EN.html" target="_blank">Demo for Tutorial_401</a>: To show the fixed Marker (with default configuration).
<span id="code-block" style="height: 100px;">
<PRE>
function Leaflet_Marker_401() // Set the Marker
{
var Markers_shape = new Array();
var Markers_shape_pos = new Array();
var Markers_shape_nam = new Array();
var Markers_shape_lnk = new Array();
Markers_shape_pos[ 0 ] = [51.5058, -0.0752]; // Marker Position
Markers_shape_nam[ 0 ] = "Tower Bridge";
Markers_shape_lnk[ 0 ] = "<a href = 'https://www.towerbridge.org.uk/' target='_blank'>Link to Tower Bridge</a>";
Markers_shape[ 0 ] = L.marker([ Markers_shape_pos[ 0 ][ 0 ], Markers_shape_pos[ 0 ][ 1 ] ]);
Markers_shape[ 0 ].bindPopup(Markers_shape_nam[ 0 ] + "<br>" + Markers_shape_lnk[ 0 ]).openPopup();
Layer_401[ 0 ] = Markers_shape[ 0 ];
Layer_401[ 0 ].addTo(map_401);
}
</PRE>
</span>
<br><br>
The next is how to show selected Icons for fixed Markers.
The source for changed Marker's section of html is as follows:
<br>
<a href = "./Leaflet_Tutrial_402_EN.html" target="_blank">Demo for Tutorial_402</a>: To show selected Icons as Markers
<span id="code-block" style="height: 100px;">
<PRE>
function Leaflet_Marker_402() // Set the Markers
{
var Markers_shape = new Array();
var Markers_shape_pos = new Array();
var Markers_shape_nam = new Array();
var Markers_shape_lnk = new Array();
var Markers_shape_icn = new Array();
Markers_shape_pos[ 0 ] = [51.5058, -0.0752];
Markers_shape_nam[ 0 ] = "Tower Bridge";
Markers_shape_lnk[ 0 ] = "<a href= 'https://www.towerbridge.org.uk/' target='_blank'>Link to Tower Bridge</a>";
Markers_shape_icn[ 0 ] = L.icon({
iconUrl: "./ICONS/Flat_Icons/s64_f_business_76_0nbg.png", // Set the Marker's Icon
iconSize: [32, 32], // Size of Icon
iconAnchor: [16, 32], // Set Anchor Point
popupAnchor: [0, -16] // Set Anchor Point for Popup
});
Markers_shape_pos[ 1 ] = [51.47, -0.453];
Markers_shape_nam[ 1 ] = "Heathrow Airport";
Markers_shape_lnk[ 1 ] = "<a href= 'https://www.heathrow.com/' target='_blank'>Link to Heathrow Airport</a>";
Markers_shape_icn[ 1 ] = L.icon({
iconUrl: "./ICONS/BW_Icon/BW_Icons_64/icon_107470_64.png",
iconSize: [32, 32],
iconAnchor: [0, 32],
popupAnchor: [16, -16]
});
Markers_shape_pos[ 2 ] = [51.258, -0.00456];
Markers_shape_nam[ 2 ] = "Oxford";
Markers_shape_lnk[ 2 ] = "<a href= 'https://oxfordcity.co.uk/' target='_blank'>Link to Oxford</a>";
Markers_shape_icn[ 2 ] = L.icon({
iconUrl: "./ICONS/Flat_Icons/s64_f_traffic_45_0nbg.png",
iconSize: [28, 32],
iconAnchor: [0, 32],
popupAnchor: [16, -16]
});
for ( i = 0; i < Markers_shape_pos.length; i++ )
{
if( Markers_shape_pos[ i ] != null ) {
Markers_shape[ i ] = L.marker([ Markers_shape_pos[ i ][ 0 ], Markers_shape_pos[ i ][ 1 ] ],
{icon: Markers_shape_icn[ i ]});
Markers_shape[ i ].bindPopup(Markers_shape_nam[ i ] + "<br>" + Markers_shape_lnk[ i ]).openPopup();
Layer_402[ i ] = Markers_shape[ i ];
Layer_402[ i ].addTo(map_402);
}
}
}
</PRE>
</span>
<br><br>
Add to Draggable Markers. Human type of icons (including clown icon) are movable.
The source for added Draggable Marker's section of html is as follows:
<br>
<a href = "./Leaflet_Tutrial_403_EN.html" target="_blank">Demo for Tutorial_403</a>: Add to Draggable Markers
<span id="code-block" style="height: 100px;">
<PRE>
Drag_Markers_shape_pos[ 0 ] = [52.0, 1.75];
Drag_Markers_shape_nam[ 0 ] = "Movable Marker #1";
Drag_Markers_shape_lnk[ 0 ] = " ";
Drag_Markers_shape_icn[ 0 ] = L.icon({
iconUrl: "./ICONS/Flat_Icons/s64_f_object_116_1nbg.png",
iconSize: [48, 48],
iconAnchor: [24, 24],
popupAnchor: [0, 0]
});
Drag_Markers_shape_pos[ 1 ] = [51.5, 1.0];
Drag_Markers_shape_nam[ 1 ] = "Movable Marker #2";
Drag_Markers_shape_lnk[ 1 ] = "<A HREF = 'http://flat-icon-design.com/' target='_blank'> Link to FLAT ICOON </A>";
Drag_Markers_shape_icn[ 1 ] = L.icon({
iconUrl: "./ICONS/Flat_Icons/s64_f_object_115_0nbg.png",
iconSize: [48, 48],
iconAnchor: [24, 24],
popupAnchor: [0, 0]
});
Drag_Markers_shape_pos[ 2 ] = [51.5, 2.0];
Drag_Markers_shape_nam[ 2 ] = "Movable Marker #3";
Drag_Markers_shape_lnk[ 2 ] = "<A HREF = 'http://icooon-mono.com/' target='_blank'> Link to ICOON MONO </A>";
Drag_Markers_shape_icn[ 2 ] = L.icon({
iconUrl: "./ICONS/BW_Icon/BW_Icons_64/icon_128020_64.png",
iconSize: [48, 48],
iconAnchor: [24, 24],
popupAnchor: [0, 0]
});
for ( i = 0; i < Drag_Markers_shape_pos.length; i++ )
{
if( Drag_Markers_shape_pos[ i ] != null ) {
Drag_Markers_shape[ i ] = L.marker([ Drag_Markers_shape_pos[ i ][ 0 ], Drag_Markers_shape_pos[ i ][ 1 ] ],
{icon: Drag_Markers_shape_icn[ i ], draggable: true}); // Set Draggable Marker
Drag_Markers_shape[ i ].bindPopup(Drag_Markers_shape_nam[ i ] + "<br>" + Drag_Markers_shape_lnk[ i ]);
Layer_403[ i ] = Drag_Markers_shape[ i ];
Layer_403[ i ].addTo(map_403);
}
}
</PRE>
</span>
<br><br>
The last of Step-4 is interactive Markers.
In Demo for Tutorial_404, it is shown the "MARKER MENU" at top of map window, and then you can select the Marker style and set position of Markers anywhere.
Markers that is set on the map are able to save or to load as CSV files.
Therefore, I create next Style Sheets and JavaScript files. <br>
(1) Original_Style_404.css: A Cascading Style Sheets for Dialog Box<br>
(2) scroll_menu.css: A Cascading Style Sheets for the Menu at top of the map wildow<br>
(3) Dialog_404_EN.js: Dialog Boxes to select Icons and to load CSV files<br>
<br>
I was used "ms-Dropdown-master" for loading CSV files.
The source of html, above CSS and JavaScript are as follows:
<br>
<a href = "./Leaflet_Tutrial_404_EN.html" target="_blank">Demo for Tutorial_404</a>: Interactive Markers
<span id="code-block" style="height: 100px;">
<PRE>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Leaflet_Tutrial_404_EN.html 2019/7/19 by T. Fujita</title>
<meta charset = "utf-8" />
<link rel = "stylesheet" href = "https://unpkg.com/[email protected]/dist/leaflet.css" />
<link rel = "stylesheet" href = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<link rel = "stylesheet" href = "./Plugins/ms-Dropdown-master/css/msdropdown/dd.css" />
<link rel = "stylesheet" href = "./CSS/scroll_menu.css" />
<link rel = "stylesheet" href = "./CSS/Original_Style_404.css" />
<style>
html, body {
width: 99%;
height: 98%;
font-size: 14px;
z-index: 0;
}
</style>
<script src = "https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script src = "./Plugins/ms-Dropdown-master/js/msdropdown/jquery.dd.js"></script>
<script src = "./JS/Dialog_404_EN.js" ></script>
<script>
var Marker_LAT = new Array();
var Marker_LON = new Array();
var Marker_NAM = new Array();
var Marker_LNK = new Array();
var Marker_ICN = new Array();
var Marker_ID = new Array();
var Marker_Drag_flag = new Array();
var Marker_Drag_info = new Array();
var ClickLat = null;
var ClickLon = null;
var Marker_count = 0;
var Marker_ID_count = 0;
var SelectedID;
var Marker_flag = 0;
var Temp_shape, Temp_shape_clone;
var Temp, Temp_LAT, Temp_LON, Temp_NAM, Temp_LNK, Temp_ICN, Temp_ID;
var Temp_Drag_flag, Temp_Drag_info;
var Layer_404 = new Array();
var Layer_404_clone = new Array();
var Dialog_flag_001 = 0;
var map_404;
function init() {
map_404 = L.map('map_404').setView([51.5, 0.0], 8);
mapLink = '<a href="https://openstreetmap.org">OpenStreetMap</a>';
L.tileLayer(
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Map data © ' + mapLink,
maxZoom: 18
}).addTo(map_404);
map_404.on('click', function(e) {
ClickLat = e.latlng.lat;
ClickLon = e.latlng.lng;
if ( Marker_flag == 1 ) { Leaflet_Marker_401(); }
if ( Marker_flag == 2 ) { Leaflet_Marker_403(); }
});
}
function Leaflet_Marker_400() { // Initialize for setting a Marker
ClickLat = null;
ClickLon = null;
Marker_flag = 1;
}
function Leaflet_Marker_401() { // Set a Marker
if(Marker_flag == 1) {
Marker_LAT[ Marker_count ] = ClickLat;
Marker_LON[ Marker_count ] = ClickLon;
Marker_NAM[ Marker_count ] = Set_Text;
Marker_LNK[ Marker_count ] = " ";
Marker_ICN[ Marker_count ] = L.icon({
iconUrl: Icon_Url,
iconSize: [Icon_W, Icon_H],
iconAnchor : [Icon_AW, Icon_AH],
popupAnchor: [Icon_PW, Icon_PH]
});
Marker_ID[ Marker_count ] = "Marker" + Marker_ID_count;
Marker_Drag_flag[ Marker_count ] = true;
Marker_Drag_info[ Marker_count ] = "This Marker is movable.";
Temp = Marker_count;
Marker_setting();
Marker_set();
Layer_404[ Temp ] = Temp_shape;
Layer_404[ Temp ].addTo(map_404);
Layer_404_clone[ Temp ] = Temp_shape_clone;
Layer_404_clone[ Temp ].addTo(map_404);
Marker_count = Marker_count + 1;
Marker_ID_count = Marker_ID_count + 1;
Marker_flag = 0;
}
}
function Leaflet_Marker_402() { // Initialize for Setting of Several Markers
ClickLat = null;
ClickLon = null;
Marker_flag = 2;
}
function Leaflet_Marker_403() { // Set Several Markers
if(Marker_flag == 2) {
Marker_LAT[ Marker_count ] = ClickLat;
Marker_LON[ Marker_count ] = ClickLon;
Marker_NAM[ Marker_count ] = Set_Text;
Marker_LNK[ Marker_count ] = " ";
Marker_ICN[ Marker_count ] = L.icon({
iconUrl: Icon_Url,
iconSize: [Icon_W, Icon_H],
iconAnchor : [Icon_AW, Icon_AH],
popupAnchor: [Icon_PW, Icon_PH]
});
Marker_ID[ Marker_count ] = "Marker" + Marker_ID_count;
Marker_Drag_flag[ Marker_count ] = true;
Marker_Drag_info[ Marker_count ] = "This Marker is movable.";
Temp = Marker_count;
Marker_setting();
Marker_set();
Layer_404[ Temp ] = Temp_shape;
Layer_404[ Temp ].addTo(map_404);
Layer_404_clone[ Temp ] = Temp_shape_clone;
Layer_404_clone[ Temp ].addTo(map_404);
Marker_count = Marker_count + 1;
Marker_ID_count = Marker_ID_count + 1;
}
}
function Leaflet_Marker_404() { // End of Setting for Several Markers
Marker_flag = 0;
}
function Leaflet_Marker_405() { // Clear All Markers
var j = Layer_404.length - 1;
for(i = 0; i <= j; i++) {
if(Layer_404[i] != null) {
map_404.removeLayer(Layer_404[i]);
map_404.removeLayer(Layer_404_clone[ i ]);
}
}
Marker_count = 0;
Marker_LAT = new Array();
Marker_LON = new Array();
Marker_NAM = new Array();
Marker_LNK = new Array();
Marker_ICN = new Array();
}
function Leaflet_Marker_406() { // Save Marker's Position as CSV File
for (i = 0; i <= (Marker_LON.length - 1); i++) {
if( !isNaN(Marker_LON[ i ]) ) {
while( (Marker_LON[ i ] * 1.0) < -180) {
Marker_LON[ i ] = (Marker_LON[ i ] * 1.0) + 360;
}
while( (Marker_LON[ i ] * 1.0) > 180) {
Marker_LON[ i ] = (Marker_LON[ i ] * 1.0) - 360;
}
}
}
if(Marker_LAT[ 0 ] == "LAT(deg.)") {
var CSV_content = [];
} else {
var CSV_content = "LAT(deg.),LONG(deg.),Name(by utf-8),Link,\r\n";
}
const aTag = document.createElement('a');
aTag.download = "CSV_Data.csv";
var bom = new Uint8Array([0xEF, 0xBB, 0xBF]);
Temp = Marker_LAT.length;
for ( i = 0; i < Temp; i++ ) {
if( Marker_LAT[ i ] != "" && Marker_LON[ i ] != "" ) {
CSV_content = CSV_content + Marker_LAT[ i ] + "," + Marker_LON[ i ] + "," + Marker_NAM[ i ] + "," + Marker_LNK[ i ] + ",\r\n";
}
}
var blob = new Blob([ bom, CSV_content ], { "type": "text/csv"});
if(window.navigator.msSaveBlob) {
window.navigator.msSaveBlob(blob, aTag.download); // for IE
} else if (window.URL && window.URL.createObjectURL) {
aTag.href = window.URL.createObjectURL(blob); // for FireFox
document.body.appendChild(aTag);
aTag.click();
document.body.removeChild(aTag);
} else if (window.webkitURL && window.webkitURL.createObject) {
aTag.href = (window.URL || window.webkitURL).createObjectURL(blob); // for Chrome
aTag.click();
} else {
alert("Failed to save the file!");
}
}
function Leaflet_Marker_407() { // Load Marker's Position from CSV File
Dialog_002();
}
function Marker_setting() { // Setting Markers
Temp_LAT = Marker_LAT[ Temp ] * 1.0;
Temp_LON = Marker_LON[ Temp ] * 1.0;
Temp_NAM = Marker_NAM[ Temp ];
Temp_LNK = Marker_LNK[ Temp ];
Temp_ICN = Marker_ICN[ Temp ];
Temp_ID = Marker_ID[ Temp ];
Temp_Drag_flag = Marker_Drag_flag[ Temp ]
Temp_Drag_info = Marker_Drag_info[ Temp ]
Set_Link =" ";
if(Temp_LNK != undefined ) {
if( String( Temp_LNK ).length > 5 ) {
Set_Link = "<a href= '" + Temp_LNK + "' target='_blank'> " + "Link to the URL of " + Temp_NAM + " </a>";
}
}
}
function Marker_set() { // Set Markers
if( !isNaN( Temp_LAT ) && !isNaN( Temp_LON ) ) {
if( (Temp_LAT !== undefined) || (Temp_LAT !== "") ) {
if( ((Temp_LAT * 1.0) != 0) || ((Temp_LON * 1.0) != 0) ) {
Temp_shape = L.marker([ Temp_LAT, Temp_LON ],
{icon: Temp_ICN, id: Temp_ID, draggable: Temp_Drag_flag}).bindPopup( Temp_NAM + "<BR>" + Temp_Drag_info + "<BR>" +
"<p> <input type='button' value='Change this Marker' class='marker-change-button'/></p>" +
Set_Link + "<p> <input type='button' value='Delete this Marker' class='marker-delete-button'/></p>");
Temp_shape.on('popupopen', onMarkerOpen ).on('dragend', Dragging);
if(Temp_LON >= 0) {
Temp_shape_clone = L.marker([ Temp_LAT, (Temp_LON - 360) ],
{icon: Temp_ICN, id: Temp_ID, draggable: Temp_Drag_flag}).bindPopup( Temp_NAM + "<BR>" + Temp_Drag_info + "<BR>" +
"<p> <input type='button' value='Change this Marker' class='marker-change-button'/></p>" +
Set_Link + "<p> <input type='button' value='Delete this Marker' class='marker-delete-button'/></p>");
Temp_shape_clone.on('popupopen', onMarkerOpen ).on('dragend', Dragging);
} else {
Temp_shape_clone = L.marker([ Temp_LAT, (Temp_LON + 360) ],
{icon: Temp_ICN, id: Temp_ID, draggable: Temp_Drag_flag}).bindPopup( Temp_NAM + "<BR>" + Temp_Drag_info + "<BR>" +
"<p> <input type='button' value='Change this Marker' class='marker-change-button'/></p>" +
Set_Link + "<p> <input type='button' value='Delete this Marker' class='marker-delete-button'/></p>");
Temp_shape_clone.on('popupopen', onMarkerOpen ).on('dragend', Dragging);
}
}
}
}
}
function onMarkerOpen() { // Action at Click the Marker
var tempMarker = this;
SelectedID = tempMarker.options.id;
$(".marker-delete-button:visible").click(function () {
Marker_DEL(tempMarker);
});
$(".marker-change-button:visible").click(function () {
Dialog_001();
});
}
function Change_Marker() { // Action at Click the Change Button
for(i = 0; i <= Marker_count; i++) {
if(SelectedID == Marker_ID[ i ] ) {
Marker_NAM[ i ] = Set_Text;
Marker_ICN[ i ] = L.icon({
iconUrl: Icon_Url,
iconSize: [Icon_W, Icon_H],
iconAnchor : [Icon_AW, Icon_AH],
popupAnchor: [Icon_PW, Icon_PH]
});
}
}
Marker_Refresh();
}
function Marker_DEL(tempMarker) { // Action at Click the Delete Button
var k = 0;
Marker_flag = 0;
Marker_LAT[ Marker_count + 1 ] = "";
Marker_LON[ Marker_count + 1 ] = "";
Marker_NAM[ Marker_count + 1 ] = "";
Marker_LNK[ Marker_count + 1 ] = "";
Marker_ICN[ Marker_count + 1 ] = "";
Marker_ID[ Marker_count + 1 ] = "";
SelectedID = tempMarker.options.id;
for(i = 0; i <= Marker_count; i++) {
if(SelectedID == Marker_ID[ i ] ) {
for(k = i; k <= Marker_count; k++) {
Marker_LAT[ k ] = Marker_LAT[ k + 1 ];
Marker_LON[ k ] = Marker_LON[ k + 1 ];
Marker_NAM[ k ] = Marker_NAM[ k + 1 ];
Marker_LNK[ k ] = Marker_LNK[ k + 1 ];
Marker_ICN[ k ] = Marker_ICN[ k + 1 ];
Marker_ID[ k ] = Marker_ID[ k + 1 ];
Marker_Drag_flag[ k ] = Marker_Drag_flag[ k + 1 ];
Marker_Drag_info[ k ] = Marker_Drag_info[ k + 1 ];
}
}
}
SelectedID = null;
Marker_count = Marker_count - 1;
Marker_Refresh();
}
function Marker_Refresh() { // Refresh Markers
var j = Layer_404.length - 1;
for(i = 0; i <= j; i++) {
if(Layer_404[ i ] != null) {
map_404.removeLayer(Layer_404[ i ]);
map_404.removeLayer(Layer_404_clone[ i ]);
}
}
for (i = 0; i <= Marker_count - 1; i++)
{
Temp = i;
Marker_setting();
Marker_set();
Layer_404[ Temp ] = Temp_shape;
Layer_404[ Temp ].addTo(map_404);
Layer_404_clone[ Temp ] = Temp_shape_clone;
Layer_404_clone[ Temp ].addTo(map_404);
}
}
function Dragging() { // Get Marker's Position
ClickLat = this._latlng.lat;
ClickLon = this._latlng.lng;
SelectedID = this.options.id;
for(i = 0; i <= Marker_count; i++) {
if(SelectedID == Marker_ID[ i ] ) {
Marker_LAT[ i ] = ClickLat;
Marker_LON[ i ] = ClickLon;
}
}
Marker_Refresh();
SelectedID = null;
}
function CSV_Markers() { // Set Markers from CSV File
for (i = 0; i <= (Data_CSV.length - 1); i++) {
if((Data_CSV[i][0] * 1.0) > 90) {
Data_CSV[i][0] = 90;
}
if((Data_CSV[i][0] * 1.0) < -90) {
Data_CSV[i][0] = -90;
}
while( (Data_CSV[i][1] * 1.0) < -180) {
Data_CSV[i][1] = Data_CSV[i][1] * 1.0 + 360;
}
while( (Data_CSV[i][1] * 1.0) > 180) {
Data_CSV[i][1] = Data_CSV[i][1] * 1.0 - 360;
}
}
for (i = 0; i <= (Data_CSV.length - 1); i++) {
Marker_LAT[ Marker_count ] = Data_CSV[i][0];
Marker_LON[ Marker_count ] = Data_CSV[i][1];
Marker_NAM[ Marker_count ] = Data_CSV[i][2];
Marker_LNK[ Marker_count ] = Data_CSV[i][3];
Marker_ICN[ Marker_count ] = L.icon({
iconUrl: Icon_Url,
iconSize: [Icon_W, Icon_H],
iconAnchor : [Icon_AW, Icon_AH],
popupAnchor: [Icon_PW, Icon_PH]
});
Marker_ID[ Marker_count ] = "Marker" + Marker_ID_count;
Marker_Drag_flag[ Marker_count ] = false;
Marker_Drag_info[ Marker_count ] = "This Marker is Fixed.";
if( Data_CSV[i][0] != "" ) {
if( !isNaN( Data_CSV[i][0] ) ) {
Temp = Marker_count;
Marker_setting();
Marker_set();
Layer_404[ Temp ] = Temp_shape;
Layer_404[ Temp ].addTo(map_404);
Layer_404_clone[ Temp ] = Temp_shape_clone;
Layer_404_clone[ Temp ].addTo(map_404);
}
}
Marker_count = Marker_count + 1;
Marker_ID_count = Marker_ID_count + 1;
}
}
</script>
</head>
<body onload="init()">
<nav id="menu-wrap" style="z-index: 1000;">
<ul id="menu" style="width: 98%;">
<li><a href="#">Marker Menu</a>
<ul>
<li><a href="#" onclick = "Dialog_001()">Select Marker Style</a></li>
<li><a href="#" onclick = "Leaflet_Marker_400()">Set One Marker </a></li>
<li><a href="#" onclick = "Leaflet_Marker_402()">Start to Set Several Markers </a></li>
<li><a href="#" onclick = "Leaflet_Marker_404()">End of Set Several Markers </a></li>
<li><a href="#" onclick = "Leaflet_Marker_405()">Clear All Markers </a></li>
<li><a href="#" onclick = "Leaflet_Marker_406()">Save Marker Position as CSV File </a></li>
<li><a href="#" onclick = "Leaflet_Marker_407()">Load Marker Position from CSV File </a></li>
</ul>
</li>
</ul>
</nav>
<div id="map_Layer">
<div id="map_404" style="width: 100%; height: 96%; border: solid 1px"></div>
These Icons are downloaded from<A HREF = "http://flat-icon-design.com/" target="_blank"> FLAT ICON DESIGN </A>and
<A HREF = "http://icooon-mono.com/" target="_blank"> ICOON MONO </A>.
TopeconHeroes holds the copyright of these Icons.
</div>
</body>
</html>
</PRE>
</span>
<br>
Source of Original_Style_404.css
<span id="code-block" style="height: 100px;">
<PRE>
.leaflet-container {
background: #fff;
outline: 0;
}
.ui-widget {
font-family: Arial,Verdana,sans-serif;
font-size: 0.8em;
}
.ui-slider-range {
background: #808080;
}
#console {
height: 136px;
overflow-y: scroll;
color: white;
background-color: black;
}
</PRE>
</span>
<br>
Source of scroll_menu.css
<span id="code-block" style="height: 100px;">
<PRE>
#menu, #menu ul {
margin: 0;
padding: 0;
list-style: none;
position: absolute;
}
#menu {
width: 100%;
height: 30px;
margin: 0px auto;
border: 1px solid #444;
background-color: #111;
background-image: linear-gradient(#444, #111);
border-top-left-radius: 6px;
border-top-right-radius: 6px;
border-bottom-left-radius: 1px;
border-bottom-right-radius: 1px;
box-shadow: 0 1px 1px #777, 0 1px 0 #666 inset;
}
#menu:before,
#menu:after {
content: "";
display: table;
clear: both;
}
#menu li {
float: left;
border: 1px solid #fff;
box-shadow: 1px 0 0 #444;
position: relative;
border-top-right-radius: 6px;
border-top-left-radius: 6px;
}
#menu a {
float: left;
padding: 5px 10px;
color: #FAFAFA;
text-transform: uppercase;
font: 12px Arial, Helvetica;
text-decoration: none;
text-shadow: 0 1px 0 #000;
}
#menu li:hover > a {
color: #BA0000;
}
#menu ul {
margin: 10px 0 0 0;
opacity: 0;
visibility: hidden;
position: absolute;
top: 24px;
left: 0;
z-index: 1000;
background: #444;
background: linear-gradient(#444, #111);
box-shadow: 0 -1px 0 rgba(255,255,255,.3);
border-radius: 3px;
transition: all .2s ease-in-out;
}
#menu li:hover > ul {
opacity: 1;
visibility: visible;
margin: 0;
}
#menu ul ul {
top: 0;
left: 200px;
margin: 0 0 0 8px;
box-shadow: -1px 0 0 rgba(255,255,255,.3);
}
#menu ul li {
float: none;
display: block;
border: 0;
box-shadow: 0 1px 0 #111, 0 2px 0 #666;
}
#menu ul li:last-child {
box-shadow: none;
}
#menu ul a {
padding: 3px;
width: 200px;
display: block;
white-space: nowrap;
float: none;
text-transform: none;
}
#menu ul a:hover {
color: #FAFAFA;
background-color: #BA0000;
background-image: linear-gradient(#BA0000, #111);
}
#menu ul li:last-child > a {
border-radius: 0 0 3px 3px;
}
#scroll {
max-width: 210px;
max-height: 300px;
overflow-y: auto;
overflow-x: hidden;
}
#myColor {
border: 1px solid #FFFFFF;
position: absolute;
top: 2px;
}
#txtInfo {
position: absolute;