-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1811e6a
commit e2c2579
Showing
4 changed files
with
264 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
flask_project/campaign_manager/templates/campaign_detail/map.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<div id="campaign-map-detail"> | ||
<div class="legend"> | ||
<span><b>Completeness</b></span><br/> | ||
<i style="background-color:#00840d"></i> <span>100%</span><br/> | ||
<i style="background-color:#faff00"></i> <span>75%</span><br/> | ||
<i style="background-color:#ffe500"></i> <span>50%</span><br/> | ||
<i style="background-color:#FD9A08"></i> <span>25%</span><br/> | ||
<i style="background-color:#ff0000"></i> <span>0%</span><br/> | ||
</div> | ||
</div> | ||
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v1.5.0/mapbox-gl.js'></script> | ||
<script> | ||
mapboxgl.accessToken = 'pk.eyJ1Ijoid2lsbGUiLCJhIjoicFNVWk5VWSJ9.hluCd0YGvYHNlFi_utWe2g'; | ||
map = new mapboxgl.Map({ | ||
container: 'campaign-map-detail', | ||
style: 'mapbox://styles/mapbox/light-v10', | ||
center: [0, 0], | ||
zoom: 1 | ||
}); | ||
map.addControl(new mapboxgl.NavigationControl()); | ||
|
||
map.on('load', function() { | ||
map.resize(); | ||
|
||
map.addSource('aoi', { | ||
"type": "geojson", | ||
"data": {{ geometry | safe }} | ||
}); | ||
// load aoi geometry layer | ||
map.addLayer({ | ||
"id": "aoi-geometry", | ||
"type": "fill", | ||
"source": "aoi", | ||
"paint": { | ||
"fill-color": "#3388ff", | ||
"fill-opacity": 0.1 | ||
} | ||
}); | ||
map.addLayer({ | ||
"id": "aoi-bounds", | ||
"type": "line", | ||
"source": "aoi", | ||
"paint": { | ||
"line-color": "#003278" | ||
} | ||
}); | ||
|
||
var popup = new mapboxgl.Popup({ | ||
closeButton: false, | ||
closeOnClick: false | ||
}); | ||
map.on('mouseenter', 'aoi-bounds', function(e) { | ||
map.getCanvas().style.cursor = 'pointer'; | ||
var description = ` | ||
<h4>Area</h4> | ||
<div class="layer-group"> | ||
<div class="layer-popup-area"> | ||
<b>Area:</b> ${e.features[0].properties.area || '-'} | ||
</div> | ||
<div class="layer-popup-area"> | ||
<b>Team:</b> ${e.features[0].properties.team || '-'} | ||
</div> | ||
<div class="layer-popup-area"> | ||
<b>Status:</b> ${e.features[0].properties.status || '-'} | ||
</div> | ||
</div> | ||
`; | ||
popup.setLngLat(e.lngLat) | ||
.setHTML(description) | ||
.addTo(map); | ||
}); | ||
|
||
map.on('click', 'aoi-bounds', function (e) { | ||
let base = 'http://www.openstreetmap.org/edit/#disable_features=boundaries'; | ||
|
||
// Encode geojson within backend endpoint. | ||
let strPolygon = JSON.stringify(e.features[0].toJSON()); | ||
let gpx_url = encodeURIComponent(window.location.origin + '/gpx/' + btoa(strPolygon)) | ||
window.open(base + '&gpx=' + gpx_url) | ||
|
||
}); | ||
|
||
map.on('mouseleave', 'aoi-bounds', function() { | ||
map.getCanvas().style.cursor = ''; | ||
popup.remove(); | ||
}); | ||
map.fitBounds(extent({{ geometry | safe }}), {padding: 40}); | ||
}); | ||
|
||
|
||
["campaign-polygons", "campaign-lines", "campaign-points"].forEach( | ||
layer => { | ||
map.on('mouseenter', layer, () => { | ||
map.getCanvas().style.cursor = 'pointer'; | ||
}); | ||
map.on('mouseleave', layer, () => { | ||
map.getCanvas().style.cursor = ''; | ||
}); | ||
map.on('click', layer, e => displayPopup(e)); | ||
} | ||
); | ||
|
||
function displayPopup(e) { | ||
var feature = e.features[0]; | ||
var link = ` | ||
<a href="https://www.openstreetmap.org/${feature.properties.type}/${feature.properties.id}" target="_blank"> | ||
${feature.properties.type} / ${feature.properties.id} | ||
</a> | ||
`; | ||
var content = `${link}<br />`; | ||
|
||
var percentage = `<b>Completeness</b>: ${feature.properties.completeness_pct}`; | ||
content += percentage; | ||
|
||
if (feature.properties.errors && feature.properties.errors !== "null") { | ||
var errors = `<div style='color:red'><b>Errors</b>: ${feature.properties.errors}</div>`; | ||
content += errors; | ||
} | ||
|
||
if (feature.properties.warnings && feature.properties.warnings !== "null") { | ||
var warnings = `<div style='color:orange'><b>warnings</b>: ${feature.properties.warnings}</div>` | ||
content += warnings; | ||
} | ||
|
||
var tags = Object.entries(JSON.parse(feature.properties.tags)).map( | ||
i => `<b>${i[0]}</b>: ${i[1]}` | ||
); | ||
tags = tags.join('<br />') | ||
content += `<p><i>${tags}</i></p>`; | ||
|
||
new mapboxgl.Popup() | ||
.setLngLat(e.lngLat) | ||
.setHTML(content) | ||
.addTo(map); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters