Fix initial map positionning
Deploy Spot / deploy (push) Successful in 34s

This commit is contained in:
2026-06-01 23:41:16 +02:00
parent 6cad199431
commit 9ce25e73f0
4 changed files with 59 additions and 58 deletions
+44 -49
View File
@@ -132,13 +132,8 @@ export default {
this.modeHisto = (this.project.mode == this.consts.modes.histo);
await this.$nextTick();
await Promise.all([
this.feed.init(),
this.initProjectMap()
]);
//Direct link post action
if(this.hash.items.length == 3) await this.feed.findPost(this.hash.items[1], this.hash.items[2]);
const pMapReady = this.initProjectMap();
await this.feed.init(pMapReady);
},
initLightbox() {
if(!this.lightbox) {
@@ -174,15 +169,7 @@ export default {
this.api.get('geojson', {id_project: this.project.id})
]);
await this.initMap({
setCamera: () => {
this.map.fitBounds(this.getInitialMapBounds(), {
padding: this.mapPadding,
animate: false,
maxZoom: 15
});
}
});
await this.initMap();
},
async initOverviewMap() {
this.baseMaps = this.consts.default_maps;
@@ -193,27 +180,9 @@ export default {
opacityWhenCovered: 0.3
}));
await this.initMap({
setCamera: () => {
//Center on default project
const oDefaultProject = this.projects.getDefaultProject();
//Get Map / Canvas size
const $Canvas = this.map.getCanvas();
const oMapBounds = this.map.getContainer().getBoundingClientRect();
//Adapt zoom to see whole planet
const iTargetRadius = Math.max(1, Math.min(oMapBounds.width || $Canvas.clientWidth, oMapBounds.height || $Canvas.clientHeight) / 2);
const iWorldSize = iTargetRadius * 2 * Math.PI * Math.cos(oDefaultProject.latitude * Math.PI / 180);
this.map.jumpTo({
center: new LngLat(oDefaultProject.longitude, oDefaultProject.latitude),
zoom: Math.log2(iWorldSize / this.map.transform.tileSize)
});
}
});
await this.initMap();
},
async initMap({setCamera}) {
async initMap() {
//Build map
if(!this.map) this.addMap();
this.updateMapPadding();
@@ -225,7 +194,7 @@ export default {
});
this.map.resize();
setCamera();
this.setInitialProjectCamera();
//Add content: Base Maps, Tracks, Markers
this.addMapContent();
@@ -456,10 +425,8 @@ export default {
this.popup.element = null;
}
},
getInitialMapBounds() {
let oBounds = new LngLatBounds();
setInitialProjectCamera() {
let oHashMarker;
if(this.hash.items.length == 3) {
oHashMarker = this.markers.find((oMarker) => (
oMarker.type == this.hash.items[1] &&
@@ -469,27 +436,55 @@ export default {
)) || null;
}
let oLastMarker = this.markers.at(-1);
//Overview map: Center on default project
if(!this.project) {
//Center on default project
const oDefaultProject = this.projects.getDefaultProject();
//Get Map / Canvas size
const $Canvas = this.map.getCanvas();
const oMapBounds = this.map.getContainer().getBoundingClientRect();
//Adapt zoom to see whole planet
const iTargetRadius = Math.max(1, Math.min(oMapBounds.width || $Canvas.clientWidth, oMapBounds.height || $Canvas.clientHeight) / 2);
const iWorldSize = iTargetRadius * 2 * Math.PI * Math.cos(oDefaultProject.latitude * Math.PI / 180);
this.map.jumpTo({
center: new LngLat(oDefaultProject.longitude, oDefaultProject.latitude),
zoom: Math.log2(iWorldSize / this.map.transform.tileSize)
});
}
//Direct link to marker
if(oHashMarker) {
oBounds.extend(new LngLat(oHashMarker.longitude, oHashMarker.latitude));
else if(oHashMarker) {
this.map.jumpTo({
center: new LngLat(oHashMarker.longitude, oHashMarker.latitude),
zoom: 13
});
}
//Blog Mode: Fit to last marker
else if(this.project.mode == this.consts.modes.blog && this.markers.length > 0) {
let oLastMarker = this.markers.at(-1);
if(oLastMarker) oBounds.extend(new LngLat(oLastMarker.longitude, oLastMarker.latitude));
else if(this.project.mode == this.consts.modes.blog && oLastMarker) {
this.map.jumpTo({
center: new LngLat(oLastMarker.longitude, oLastMarker.latitude),
zoom: 15
});
}
//Pre Mode, Histo Mode, Blog Mode without markers or missing direct link marker: Fit to track
if(oBounds.isEmpty()) {
else {
let oBounds = new LngLatBounds();
for(const iFeatureId in this.track.features) {
oBounds = this.track.features[iFeatureId].geometry.coordinates.reduce(
(bounds, coord) => bounds.extend(coord),
oBounds
);
}
this.map.fitBounds(oBounds, {
padding: this.mapPadding,
animate: false,
maxZoom: 15
});
}
return oBounds;
},
addNewMarkers(aoMarkers) { //FIXME Use its own marker update API
this.markers.push(...aoMarkers);