Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basemap toggle to home page map #225

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions pages/home/static/css/home.css
Original file line number Diff line number Diff line change
Expand Up @@ -392,33 +392,48 @@
.map-legend {
display: flex;
padding: 4px 8px;
align-items: center;
align-items: flex-start;
background-color: #fff;
font-size: 14px;
flex-wrap: wrap;
position: absolute;
bottom: 0;
z-index: 99;
flex-direction: column;
}

.legend-items {
display: flex;
align-items: center;
align-items: flex-start;
flex-wrap: wrap;
flex-direction: column;
}


.legend-item {
display: flex;
align-items: center;
margin-left: 10px;
}

.map-legend .legend-items .legend-item .legend-color {
margin-right: 4px;
height: 12px;
width: 12px;
border:#d4dadc solid 1px;

}

.map-ctrl-icon {
display: block;
width: 24px;
height: 24px;
margin: 5px;
background-size: cover;
border:1px solid #646464;

}



.mapviewer-explore {
display: flex;
Expand Down
Binary file added pages/home/static/img/dark-basemap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/home/static/img/light-basemap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/home/static/img/voyager-basemap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/home/static/img/wikimedia-basemap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 64 additions & 22 deletions pages/home/static/js/weather_watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ $((async function () {
'tiles': [
"https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png"
]
}
},
},
'layers': [{
'id': 'carto-light-layer',
Expand Down Expand Up @@ -72,6 +72,46 @@ $((async function () {
scrollZoom: false,
});

const basemaps = {
'carto-light': 'carto-light-layer',
'carto-dark': 'carto-dark-layer',
'voyager': 'voyager-layer',
'wikimedia': 'wikimedia-layer'
};

Object.keys(basemaps).forEach(basemap => {

document.getElementById(basemap).addEventListener('click', () => {
setBasemap(map,basemap);
});
})

function setBasemap(map,style) {
Object.keys(basemaps).forEach(layer => {
if (map.getLayer(basemaps[layer])) {
map.removeLayer(basemaps[layer]);
map.removeSource(layer);
}
});

if(map.getSource(style)){
map.removeSource(style)
}

if(map.getLayer(basemaps[style])){
map.removeLayer(basemaps[style])
}
map.addSource(style, defaultStyle.sources[style]);

map.addLayer({
'id': basemaps[style],
'source': style,
'type': 'raster',
'minzoom': 0,
'maxzoom': 22
},map.getStyle().layers[0].id);
}


// Add zoom control to the map.
map.addControl(new maplibregl.NavigationControl({showCompass: false}));
Expand Down Expand Up @@ -152,27 +192,7 @@ $((async function () {
});
}

// add city forecast source
map.addSource("city-forecasts", {
type: "geojson",
cluster: true,
clusterMinPoints: 2,
clusterRadius: 25,
data: {type: "FeatureCollection", features: []}
})

// add city forecast layer
map.addLayer({
"id": "city-forecasts",
"type": "symbol",
"layout": {
'icon-image': ['get', 'condition'],
'icon-size': 0.3,
'icon-allow-overlap': true
},
source: "city-forecasts"
})


let zoomLocationsInit = false
const updateMapBounds = () => {
if (bounds) {
Expand Down Expand Up @@ -297,6 +317,28 @@ $((async function () {
updateMapBounds()
}

// add city forecast source
map.addSource("city-forecasts", {
type: "geojson",
cluster: true,
clusterMinPoints: 2,
clusterRadius: 25,
data: {type: "FeatureCollection", features: []}
})

// add city forecast layer
map.addLayer({
"id": "city-forecasts",
"type": "symbol",
"layout": {
'icon-image': ['get', 'condition'],
'icon-size': 0.3,
'icon-allow-overlap': true
},
source: "city-forecasts"
})



const getPopupHTML = (props) => {
const dataParams = forecastSettings?.parameters || []
Expand Down
13 changes: 11 additions & 2 deletions pages/home/templates/home/section/weather_watch_include.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ <h4>
</div>
</div>
</div>
<div id="alerts-legend" class="map-legend" style="position: absolute;bottom: 0;display: none">
<div> {% translate "Alert Severity:" %} </div>
<div id="alerts-legend" class="map-legend elevation-1 py-3 px-4" style="position: absolute;bottom: 5px;left:5px;display: none">
<div> <p class="has-text-weight-medium">{% translate "Alert Severity" %} </p></div>
<div class="legend-items">
<div class="legend-item">
<div class="legend-color" style="background-color: rgb(215, 47, 42);"></div>
Expand All @@ -58,6 +58,15 @@ <h4>
</div>
</div>
</div>

<div class="map-ctrl map-ctrl-group" style="position: absolute;top: 10em; right:0.5em; background: white; z-index:1;
border-radius: 3px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);">
<button id="carto-light" class="map-ctrl-icon" title="Carto Light" style="background-image: url({% static '/img/light-basemap.png' %});"></button>
<button id="carto-dark" class="map-ctrl-icon" title="Carto Dark" style="background-image: url({% static '/img/dark-basemap.png' %});"></button>
<button id="voyager" class="map-ctrl-icon" title="Voyager" style="background-image: url({% static '/img/voyager-basemap.png' %});"></button>
<button id="wikimedia" class="map-ctrl-icon" title="Wikimedia" style="background-image: url({% static '/img/wikimedia-basemap.png' %});"></button>
</div>
</div>
</div>
</div>
Expand Down