forked from Princeton-CDH/literary-right-bank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.js
64 lines (55 loc) · 1.9 KB
/
map.js
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
const markerOptions = ({fillColor, tier}) => ({
radius: 6,
fillColor,
tier,
color: "#333",
stroke: 2,
weight: 1,
opacity: 1,
fillOpacity: 0.9 });
const toolTip = name => L.tooltip({ opacity: 0.7, interactive: true }).setContent(name);
const map = L.map('map', {
zoom: 16,
minZoom: 13,
maxZoom: 18,
center: [48.8616, 2.2893],
maxBounds: L.latLngBounds(
L.latLng(48.80993843039284,2.42069331467708),
L.latLng(48.90647632023956, 2.24692255999388)
)
});
const parisTiles = new L.esri.TiledMapLayer({
url: 'https://tiles.arcgis.com/tiles/4Ko8f1mCWFLyY4NV/arcgis/rest/services/Paris_1943/MapServer',
attribution: '<a href="https://maps.princeton.edu/catalog/princeton-2r36tz994">Princeton University Library</a>',
});
parisTiles.addTo(map);
const additions = L.layerGroup(data.filter(e => e.type === "addition").map(element =>
L.circleMarker([element.latitude, element.longitude], markerOptions({fillColor: "#c842f5", tier: element.rank})).bindPopup(`
<h2>${element.name}</h2>
<p>${element.addresses}</p>
`).bindTooltip(toolTip(element.tooltipName))
));
additions.addTo(map);
console.log(additions);
const regulars = L.layerGroup(data.filter(e => e.type === "regular").map(element =>
L.circleMarker([element.latitude, element.longitude], markerOptions({ fillColor: "#eee", tier: element.rank} )).bindPopup(`
<h2>${element.name}</h2>
<p>${element.addresses}</p>
`).bindTooltip(toolTip(element.tooltipName))
));
regulars.addTo(map);
const layers = [additions, regulars];
const handleTooltips = () => {
layers.forEach( layer => {
const features = Object.keys(layer._layers);
features.forEach(feature => {
if(map.getZoom() - layer._layers[feature].options.tier >= 13){
layer._layers[feature].openTooltip();
} else {
layer._layers[feature].closeTooltip();
}
});
});
};
map.on('zoomend', handleTooltips);
map.setZoom(15);