-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspc.js
67 lines (58 loc) · 2.01 KB
/
spc.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
var visitedCount = 0;
for(var i=0; i < geojson.features.length; i++){
parkName = geojson.features[i]['properties']['name']
if(parkName in localStorage){
geojson.features[i]['properties']['visit'] = '#89959C'
visitedCount++;
}
}
updateProgress();
var map = L.map('map').setView([47.6031447,-122.3285673], 12);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
function getProgress(numOfParks, visited) {
if (numOfParks === 0 || isNaN(numOfParks)) return 0;
var result = parseInt(visited, 10) / parseInt(numOfParks, 10) * 100;
console.log(result);
return result.toFixed(2) + '%';
}
function updateProgress() {
document.getElementById("myModalLabel").innerHTML = getProgress(geojson.features.length, visitedCount);
}
function onEachFeature(feature, layer) {
layer.bindPopup(feature.properties.name, {
closeButton: false,
offset: L.point(0, -10)
});
layer.on('mouseover', function (e) {
this.openPopup();
});
layer.on('mouseout', function (e) {
this.closePopup();
});
layer.on('click', function (e) {
placeName = feature.properties.name;
if(placeName in localStorage){
localStorage.removeItem(placeName);
this.setStyle({fillColor: '#8EDD65', stroke: '#8EDD65'});
visitedCount--;
} else {
localStorage.setItem(placeName, this.getLatLng().toString());
this.setStyle({fillColor: '#89959C', stroke: '#000000'});
visitedCount++;
}
updateProgress();
});
}
geojsonLayer = L.geoJson(geojson, {
style: function(feature) {
return {color: feature.properties.visit};
},
pointToLayer: function(feature, latlng) {
var currentZoom = map.getZoom();
return new L.CircleMarker(latlng, {radius: 10, fillOpacity: 0.85});
},
onEachFeature: onEachFeature
});
map.addLayer(geojsonLayer);