Skip to content

Commit

Permalink
Merge pull request #42 from CUAHSI/adjust-map-view
Browse files Browse the repository at this point in the history
adjusted the map view
  • Loading branch information
devincowan authored Feb 4, 2025
2 parents a866d26 + 10a778a commit 6a65676
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 6 additions & 0 deletions frontend/src/components/TheLeafletMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ onMounted(async () => {
// query the api for the features
await mapStore.fetchPerceptualModelsGeojson()
// Convert to Leaflet LatLngBounds
const bounds = L.latLngBounds(mapStore.allAvailableCoordinates);
// Restrict panning to within bounds
leaflet.setMaxBounds(bounds);
// layer toggling
let mixed = {
"Perceptual Models": layerGroup,
Expand Down
16 changes: 13 additions & 3 deletions frontend/src/stores/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const useMapStore = defineStore('map', () => {
const perceptualModelsGeojson = ref([])
const mapLoaded = ref(false)
let currentFilteredData = ref([])
const allAvailableCoordinates = []
const markerClusterGroup = L.markerClusterGroup({
iconCreateFunction: (cluster) => {
const childCount = cluster.getChildCount();
Expand Down Expand Up @@ -41,9 +42,8 @@ export const useMapStore = defineStore('map', () => {
},
});

function onEachFeature(feature, layer) {
function onEachFeature(feature, layer) {
let content = `<h3>Perceptual model of <strong>${feature.properties.location.long_name}</strong></h3>`

if(feature.properties.citation.url) {
content += '<br>'
content += '<h4 class="d-inline-block mr-2">URL:</h4>'
Expand Down Expand Up @@ -104,6 +104,9 @@ export const useMapStore = defineStore('map', () => {
content += '<h4>Temporal zone:</h4>'
content += `${feature.properties.temporal_zone_type.temporal_property}`
}

allAvailableCoordinates.push(adjustLatLon(feature.properties.location.lat, feature.properties.location.lon))

layer.bindPopup(content, {
maxWidth: 400,
maxHeight: 300,
Expand Down Expand Up @@ -183,6 +186,12 @@ export const useMapStore = defineStore('map', () => {
layerGroup.value.addLayer(markerClusterGroup);
}

function adjustLatLon(lat, lon) {
return [
lat < 0 ? lat - 10 : lat + 10,
lon < 0 ? lon - 10 : lon + 10
];
}
return {
leaflet,
modelFeatures,
Expand All @@ -191,6 +200,7 @@ export const useMapStore = defineStore('map', () => {
fetchPerceptualModelsGeojson,
filterFeatures,
resetFilter,
currentFilteredData
currentFilteredData,
allAvailableCoordinates
}
})

0 comments on commit 6a65676

Please sign in to comment.