-
Notifications
You must be signed in to change notification settings - Fork 0
/
dd.js
142 lines (104 loc) · 4.01 KB
/
dd.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
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
// for setting the height of the map element, taking into account the height of the navbar
var contentHeight = "height:" + (window.innerHeight - 50) +"px";
document.getElementById('mapid').setAttribute("style",contentHeight);
var mymap = L.map('mapid', {zoomSnap: 0, minZoom: 1}).setView([16.9, -8.7], 2);
mymap.createPane('labels');
// This pane is above markers but below popups
mymap.getPane('labels').style.zIndex = 650;
// Layers in this pane are non-interactive and do not obscure mouse/touch events
mymap.getPane('labels').style.pointerEvents = 'none';
var cartodbAttribution = '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="https://carto.com/attribution">CARTO</a>';
var positron = L.tileLayer('https://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png', {
attribution: cartodbAttribution
}).addTo(mymap);
var positronLabels = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_only_labels/{z}/{x}/{y}.png', {
attribution: cartodbAttribution,
pane: 'labels'
}).addTo(mymap);
// control that shows state info on hover
var info = L.control();
info.onAdd = function (mymap) {
this._div = L.DomUtil.create('div', 'info');
this.update();
return this._div;
};
info.update = function (props) {
this._div.innerHTML = '<h4>Data Deficient Species Richness</h4>' + (props ?
props.Join_Count + ' species'
: 'Hover over a cell');
};
info.addTo(mymap);
var reference = L.control({position: 'bottomleft'});
reference.onAdd = function (map) {
this.div1 = L.DomUtil.create('div', 'info reference'),
this.div1.innerHTML = "<p class='referencetitle'>Reference</p><p>Dulvy et al. (2021) Overfishing drives over one third of all sharks and rays toward a global extinction crisis. <em>Current Biology 31</em>. <a href='https://doi.org/10.1016/j.cub.2021.08.062'>https://doi.org/10.1016/j.cub.2021.08.062</a></p> <p class='referencetitle'>Statistics and maps repository</p><a href='https://github.com/NickDulvy/SharkReassessment'>https://github.com/NickDulvy/SharkReassessment</a>"
return this.div1;
};
reference.addTo(mymap);
var legend = L.control({position: 'bottomright'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend'),
grades = [1, 3, 5, 7, 10,12,14,16],
labels = [],
from, to;
for (var i = 0; i < grades.length-1; i++) {
from = grades[i];
to = grades[i + 1];
labels.push(
'<i style="background:' + getColor(from + 1) + '"></i> ' +
from + (to ? '–' + (to-1) : ''));
}
div.innerHTML = labels.join('<br>');
return div;
};
legend.addTo(mymap);
function getColor(d) {
return d > 13 ? '#6e016b' :
d > 11 ? '#88419d' :
d > 9 ? '#8c6bb1' :
d > 6 ? '#8c96c6' :
d > 4 ? '#9ebcda' :
d > 2 ? '#bfd3e6' :
'#edf8fb';
}
function style(feature) {
return {
fillColor: getColor(feature.properties.Join_Count),
weight: 2,
color: getColor(feature.properties.Join_Count),
opacity: 1,
fillOpacity: 1
};
}
function highlightFeature(e) {
var layer = e.target;
layer.setStyle({
weight: 5,
color: '#666',
dashArray: '',
fillOpacity: 0.7
});
if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
layer.bringToFront();
}
info.update(layer.feature.properties);
}
var geojson;
function resetHighlight(e) {
geojson.resetStyle(e.target);
info.update();
}
function zoomToFeature(e) {
map.fitBounds(e.target.getBounds());
}
function onEachFeature(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
click: zoomToFeature
});
}
geojson = L.geoJson(speciesRichness, {
style: style,
onEachFeature: onEachFeature
}).addTo(mymap);