Skip to content

Commit

Permalink
fix: location map fixed over uk (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland authored Sep 5, 2024
1 parent 1c4f67d commit 73092a0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions js/src/forum/components/ZipCodeMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,25 @@ export default class ZipCodeMap extends Component {

const { boundingbox: bounding, display_name: displayName } = this.data;

this.map = L.map(vnode.dom).setView([51.505, -0.09], 5);
// Extract the latitude and longitude from the bounding box
const lat1 = parseFloat(bounding[0]); // South bound latitude
const lat2 = parseFloat(bounding[1]); // North bound latitude
const lon1 = parseFloat(bounding[2]); // West bound longitude
const lon2 = parseFloat(bounding[3]); // East bound longitude

// Calculate the center of the bounding box
const centerLat = (lat1 + lat2) / 2;
const centerLon = (lon1 + lon2) / 2;

const zoomLevel = 5; // Set your preferred zoom level here

this.map = L.map(vnode.dom).setView([centerLat, centerLon], zoomLevel);

L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
}).addTo(this.map);

L.marker([bounding[0], bounding[2]]).addTo(this.map).openPopup();
// Set a marker at the center of the bounding box
L.marker([centerLat, centerLon]).addTo(this.map).bindPopup(displayName).openPopup();
}
}

0 comments on commit 73092a0

Please sign in to comment.