-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
164 lines (126 loc) · 5.7 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Twains uWu</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin=""/>
<!-- Make sure you put this AFTER Leaflet's CSS -->
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="/
crossorigin=""></script>
<script src="./fa.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<link rel="stylesheet" href="https://unpkg.com/leaflet-routing-machine@latest/dist/leaflet-routing-machine.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://unpkg.com/leaflet-routing-machine@latest/dist/leaflet-routing-machine.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<!-- Load Esri Leaflet from CDN -->
<script src="https://unpkg.com/[email protected]/dist/esri-leaflet.js"
integrity="sha512-cMQ5e58BDuu1pr9BQ/eGRn6HaR6Olh0ofcHFWe5XesdCITVuSBiBZZbhCijBe5ya238f/zMMRYIMIIg1jxv4sQ=="
crossorigin=""></script>
<!-- Include Leaflet.heat from CDN -->
<script src="https://unpkg.com/[email protected]/dist/leaflet-heat.js"></script>
<!-- Load Heatmap Feature Layer from CDN -->
<script src="https://unpkg.com/[email protected]"></script>
<!-- Esri Leaflet Geocoder -->
<link rel="stylesheet" href="https://unpkg.com/esri-leaflet-geocoder/dist/esri-leaflet-geocoder.css">
<script src="https://unpkg.com/esri-leaflet-geocoder"></script>
<script src="https://www.unpkg.com/browse/[email protected]/turf.min.js"></script>
<style>
#mapid {
height: 95vh;
}
</style>
</head>
<body>
<div id="mapid">
</div>
</body>
<script>
/* https://www.arcgis.com/home/item.html?id=96ec03e4fc8546bd8a864e39a2c3fc41 */
// var geojson;
var position = {lat: 37.762468, lon: -122.419019};
//var mymap = L.map('mapid').setView([0, 0], 1);
var mymap = L.map('mapid', {
preferCanvas: true
}).setView([37.75, -122.23], 6);
var up_geojson = new Request('UnionPacific.geojson');
var bnsf_geojson = new Request('BNSF.geojson')
var csx_geojson = new Request('CSX.geojson')
var cpac_geojson = new Request('CanadianPacific.geojson')
var cnat_geojson = new Request('CanadianNational.geojson')
var kcs_geojson = new Request('KansasCitySouthern.geojson')
var other_geojson = new Request('ShortLines.geojson')
var legend = L.control({ position: "bottomleft" });
legend.onAdd = function(map) {
var div = L.DomUtil.create("div", "legend");
div.innerHTML += "<h4>Legend<g/h4>";
div.innerHTML += '<i style="background-color: #bf8a33">__</i><span>Union Pacific</span><br>';
div.innerHTML += '<i style="background: #448D40">__</i><span>BNSF</span><br>';
div.innerHTML += '<i style="background: #E6E696">__</i><span>CSX</span><br>';
div.innerHTML += '<i style="background: #E8E6E0">__</i><span>Norfolk Southern</span><br>';
div.innerHTML += '<i style="background: #ed1d24">__</i><span>Canadian Pacific (US data only)</span><br>';
div.innerHTML += '<i style="background: blue">__</i><span>Canadian National (US data only)</span><br>';
div.innerHTML += '<i style="background: violet">__</i><span>Kansas Southern</span><br>';
div.innerHTML += '<i style="background: purple">__</i><span>Other / Short Lines</span><br>';
return div;
};
let colors = ["#bf8a33", "#448D40", "#E6E696", "#E8E6E0", "#ed1d24", "blue", "violet", "purple"]
function request_and_render_geojson(url, color= "black") {
let data;
let geojson;
fetch(url)
.then((response) => {
return data = response.json()
})
.then((data) => {
geojson = L.geoJson(data, {
onEachFeature: (feature, layer) => {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
click: () => { console.log(this) }
});
},
style: () => {
return { color: color }
}
})
geojson.addTo(mymap);
})
}
request_and_render_geojson(up_geojson, colors[0]);
request_and_render_geojson(bnsf_geojson, colors[1]);
request_and_render_geojson(csx_geojson, colors[2]);
// TODO: get norfolk geojson
// request_and_render_geojson(norfolk_geojson, colors[3]);
request_and_render_geojson(cpac_geojson, colors[4]);
request_and_render_geojson(cnat_geojson, colors[5]);
request_and_render_geojson(kcs_geojson, colors[6]);
request_and_render_geojson(other_geojson, colors[7]);
L.esri.basemapLayer('Gray').addTo(mymap);
// L.control.scale().addTo(mymap);
legend.addTo(mymap);
function highlightFeature(e) {
var layer = e.target;
layer.setStyle({
color: '#666',
});
if(!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
layer.bringToFront();
}
}
function resetHighlight(e) {
var layer = e.target;
layer.setStyle({
color: e.target.defaultOptions.style().color,
});
if(!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
// e.feature.bringToFront();
}
}
</script>
</html>