-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanguagesmap.html
116 lines (93 loc) · 2.97 KB
/
languagesmap.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
<!DOCTYPE html>
<html>
<head>
<title>American Languages Map</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script>
<script src="palette.js"></script>
<style>
html, body {
height: 100%;
margin: 0;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id='map'></div>
<script src="language-geojson.js" type="text/javascript"></script>
<script>
var map = L.map('map').setView([13.69, -89], 3);
L.tileLayer('http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}', {
maxZoom: 18,
attribution: 'Map data © <a href="http://maps.google.com/">Google Maps</a>',
id: 'mapbox/light-v9',
subdomains:['mt0','mt1','mt2','mt3']
}).addTo(map);
function onEachFeature(feature, layer) {
var popupContent = feature.properties.family == null || feature.properties.family == "" ?
"<p><b>" + feature.properties.label + "</b><br/>Family: Isolate</p>" :
"<p><b>" + feature.properties.label + "</b><br/>Family: " + feature.properties.family + "</p>";
if (feature.properties && feature.properties.popupContent) {
popupContent += feature.properties.popupContent;
}
if (feature.properties && feature.properties.family != null) {
if (!familyList.has(feature.properties.family)) {
familyList.add(feature.properties.family);
}
}
layer.bindPopup(popupContent);
}
var familyList = new Set()
function countLanguages(feature, layer) {
if (feature.properties && feature.properties.family != null) {
if (!familyList.has(feature.properties.family)) {
familyList.add(feature.properties.family);
}
}
}
L.geoJSON(languages, {
onEachFeature: countLanguages
});
var seq = palette('tol-rainbow', familyList.size);
var familyArray = Array.from(familyList);
var familyToColor = {};
for (i=0; i < familyArray.length; i++) {
familyToColor[familyArray[i]] = seq[i];
}
function pointToLayerFunc(feature, latlng) {
if (feature.properties.family == null || feature.properties.family == "") {
return L.circleMarker(latlng, {
radius: 8,
fillColor: "#fff",
color: "#000",
weight: 1,
opacity: 1,
fillOpacity: 0.8
});
}
else {
return L.circleMarker(latlng, {
radius: 8,
fillColor: "#" + familyToColor[feature.properties.family],
color: "#000",
weight: 1,
opacity: 1,
fillOpacity: 0.8
});
}
}
L.geoJSON(languages, {
style: function (feature) {
return feature.properties && feature.properties.style;
},
onEachFeature: onEachFeature,
pointToLayer: pointToLayerFunc
}).addTo(map);
</script>
</body>
</html>