-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
140 lines (126 loc) · 3.57 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
<!DOCTYPE html>
<html>
<head>
<title>Map preview</title>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.4.0/leaflet.css"
/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.4.0/leaflet.js"></script>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<div
id="map"
style="position: absolute; top: 0; bottom: 0; left: 0; right: 0"
></div>
</body>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
var map = L.map("map").setView([36, 28], 7);
L.tileLayer(
"https://stamen-tiles-{s}.a.ssl.fastly.net/toner-lite/{z}/{x}/{y}{r}.{ext}",
{
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 © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
subdomains: "abcd",
minZoom: 0,
maxZoom: 20,
ext: "png"
}
).addTo(map);
const path = "./../data/";
const addData = (file, options = {}, next = () => {}) => {
$.getJSON(path + file + ".geojson", data => {
next(
L.geoJSON(data, options)
.addTo(map)
.bringToBack()
);
});
};
const nodeStyle = nodeProps => {
const radius = visits => Math.pow(visits, 0.6) + 3;
const style = {
color: "grey",
radius: radius(nodeProps.visits),
fillColor: "grey",
opacity: 1,
fillOpacity: 1
};
if (nodeProps.port) {
style.color = "blue";
}
if (nodeProps.settlement) {
style.fillColor = "red";
}
if (!nodeProps.settlement && !nodeProps.port) {
style.radius = 2;
}
return style;
};
const edgeOptions = {
road: {
weight: 3,
color: "green"
},
maritime: {
weight: 3,
color: "#000080"
}
};
addData("nodes", {
pointToLayer: f => {
const coords = f.geometry.coordinates;
return L.circleMarker([coords[1], coords[0]], {
...nodeStyle(f.properties)
}).bindTooltip(buildTable(f.properties), {
permanent: false
});
}
});
addData(
"edges",
{
style: f => {
return {
...edgeOptions[f.properties.type],
...{ fillOpacity: 0 }
};
}
},
layer => {
layer.eachLayer(l => {
l.bindTooltip(buildTable(l.feature.properties), {
permanent: !(l.feature.properties.to || l.feature.properties.from)
});
});
}
);
addData("./pois/temples", {
pointToLayer: f => {
const coords = f.geometry.coordinates;
return L.circleMarker([coords[1], coords[0]], {
color: "black"
});
}
});
//addData("original/nodes");
});
const buildTable = props => {
let html = "<table><tbody>";
Object.keys(props).forEach(key => {
html += `<tr>`;
html += `<th>${key}</th>`;
if (props[key] instanceof Array) {
html += `<td>${props[key].join()}</td>`;
} else {
html += `<td>${props[key]}</td>`;
}
html += `</tr>`;
});
html += "</tbody></table>";
return html;
};
</script>
</html>