/
circle.html
109 lines (94 loc) · 3.19 KB
/
circle.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
{% extends "main.html" %}
{% block javascript %}
mapboxgl.accessToken = '{{ accessToken }}';
var map = new mapboxgl.Map({
container: 'map',
style: '{{ styleUrl }}',
center: {{ center }},
zoom: {{ zoom }},
transformRequest: (url, resourceType)=> {
if ( url.slice(0,22) == 'https://api.mapbox.com' ) {
//Add Python Plugin identifier for Mapbox API traffic
return {
url: [url.slice(0, url.indexOf("?")+1), "pluginName=PythonMapboxgl&", url.slice(url.indexOf("?")+1)].join('')
}
}
else {
//Do not transform URL for non Mapbox GET requests
return {url: url}
}
}
});
map.addControl(new mapboxgl.NavigationControl());
calcCircleColorLegend({{ colorStops }}, "{{ colorProperty }}");
map.on('style.load', function() {
map.addSource("data", {
"type": "geojson",
"data": {{ geojson_data }},
"buffer": 1,
"maxzoom": 14
});
map.addLayer({
"id": "label",
"source": "data",
"type": "symbol",
"maxzoom": {{ maxzoom }},
"minzoom": {{ minzoom }},
"layout": {
{% if labelProperty %}
"text-field": "{{ labelProperty }}",
{% endif %}
"text-size" : generateInterpolateExpression('zoom', [[0,8],[22,16]] ),
"text-offset": [0,-1]
},
"paint": {
"text-halo-color": "white",
"text-halo-width": 1
}
}, "{{belowLayer}}" )
map.addLayer({
"id": "circle",
"source": "data",
"type": "circle",
"maxzoom": {{ maxzoom }},
"minzoom": {{ minzoom }},
"paint": {
"circle-color": generatePropertyExpression("{{ colorType }}", "{{ colorProperty }}", {{ colorStops }}, "{{ defaultColor }}" ),
"circle-radius" : generatePropertyExpression('interpolate', 'zoom', [[0,1], [18,10]]),
"circle-stroke-color": "{{ strokeColor }}",
"circle-stroke-width": {{ strokeWidth }},
"circle-opacity" : {{ opacity }}
}
}, "label");
// Create a popup
var popup = new mapboxgl.Popup({
closeButton: false,
closeOnClick: false
});
// Show the popup on mouseover
map.on('mousemove', 'circle', function(e) {
map.getCanvas().style.cursor = 'pointer';
let f = e.features[0];
let popup_html = '<div><li><b>Location</b>: ' + f.geometry.coordinates[0].toPrecision(6) +
', ' + f.geometry.coordinates[1].toPrecision(6) + '</li>';
for (key in f.properties) {
popup_html += '<li><b> ' + key + '</b>: ' + f.properties[key] + ' </li>'
}
popup_html += '</div>'
popup.setLngLat(e.features[0].geometry.coordinates)
.setHTML(popup_html)
.addTo(map);
});
map.on('mouseleave', 'circle', function() {
map.getCanvas().style.cursor = '';
popup.remove();
});
// Fly to on click
map.on('click', 'circle', function(e) {
map.easeTo({
center: e.features[0].geometry.coordinates,
zoom: map.getZoom() + 1
});
});
});
{% endblock %}