This commit is contained in:
@@ -63,6 +63,8 @@ export default {
|
|||||||
mapInitializing: false,
|
mapInitializing: false,
|
||||||
markerHeight: 32, //FIXME
|
markerHeight: 32, //FIXME
|
||||||
mapPadding: 16 + 32, //1rem + marker height
|
mapPadding: 16 + 32, //1rem + marker height
|
||||||
|
maxZoom: 15,
|
||||||
|
initialPitch: 45,
|
||||||
lightbox: null,
|
lightbox: null,
|
||||||
hikes: {
|
hikes: {
|
||||||
colors: {},
|
colors: {},
|
||||||
@@ -477,7 +479,8 @@ export default {
|
|||||||
this.map.jumpTo({
|
this.map.jumpTo({
|
||||||
center: new LngLat(oDefaultProject.longitude, oDefaultProject.latitude),
|
center: new LngLat(oDefaultProject.longitude, oDefaultProject.latitude),
|
||||||
zoom: Math.log2(iWorldSize / this.map.transform.tileSize),
|
zoom: Math.log2(iWorldSize / this.map.transform.tileSize),
|
||||||
pitch: 0
|
pitch: 0,
|
||||||
|
bearing: 0
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//Direct link to marker
|
//Direct link to marker
|
||||||
@@ -485,34 +488,74 @@ export default {
|
|||||||
this.map.jumpTo({
|
this.map.jumpTo({
|
||||||
center: new LngLat(oHashMarker.longitude, oHashMarker.latitude),
|
center: new LngLat(oHashMarker.longitude, oHashMarker.latitude),
|
||||||
zoom: 13,
|
zoom: 13,
|
||||||
pitch: 45
|
pitch: this.initialPitch
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//Blog Mode: Fit to last marker
|
//Blog Mode: Fit to last marker
|
||||||
else if(this.project.mode == this.consts.modes.blog && oLastMarker) {
|
else if(this.project.mode == this.consts.modes.blog && oLastMarker) {
|
||||||
this.map.jumpTo({
|
this.map.jumpTo({
|
||||||
center: new LngLat(oLastMarker.longitude, oLastMarker.latitude),
|
center: new LngLat(oLastMarker.longitude, oLastMarker.latitude),
|
||||||
zoom: 15,
|
zoom: this.maxZoom,
|
||||||
pitch: 45
|
pitch: this.initialPitch,
|
||||||
|
bearing: 0
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//Pre Mode, Histo Mode, Blog Mode without markers or missing direct link marker: Fit to track
|
//Pre Mode, Histo Mode, Blog Mode without markers or missing direct link marker: Fit to track
|
||||||
else {
|
else {
|
||||||
let oBounds = new LngLatBounds();
|
let oBounds = new LngLatBounds();
|
||||||
|
const aoTrackCoordinates = [];
|
||||||
for(const iFeatureId in this.track.features) {
|
for(const iFeatureId in this.track.features) {
|
||||||
oBounds = this.track.features[iFeatureId].geometry.coordinates.reduce(
|
oBounds = this.track.features[iFeatureId].geometry.coordinates.reduce(
|
||||||
(bounds, coord) => bounds.extend(coord),
|
(bounds, coord) => {
|
||||||
|
aoTrackCoordinates.push(coord);
|
||||||
|
return bounds.extend(coord);
|
||||||
|
},
|
||||||
oBounds
|
oBounds
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.map.fitBounds(oBounds, {
|
this.map.fitBounds(oBounds, {
|
||||||
padding: this.mapPadding,
|
padding: this.mapPadding,
|
||||||
animate: false,
|
animate: false,
|
||||||
maxZoom: 15,
|
maxZoom: this.maxZoom,
|
||||||
pitch: 45
|
pitch: this.initialPitch,
|
||||||
|
bearing: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.fixPitchedCameraCenter(aoTrackCoordinates);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
fixPitchedCameraCenter(aoTrackCoordinates) {
|
||||||
|
//Project min/max coords (lat, lng) onto map rectangle corner points (x, y)
|
||||||
|
const oScreenBounds = aoTrackCoordinates.reduce((oBounds, coord) => {
|
||||||
|
const oPoint = this.map.project(coord);
|
||||||
|
return {
|
||||||
|
minX: Math.min(oBounds.minX, oPoint.x),
|
||||||
|
minY: Math.min(oBounds.minY, oPoint.y),
|
||||||
|
maxX: Math.max(oBounds.maxX, oPoint.x),
|
||||||
|
maxY: Math.max(oBounds.maxY, oPoint.y)
|
||||||
|
};
|
||||||
|
}, {
|
||||||
|
minX: Infinity,
|
||||||
|
minY: Infinity,
|
||||||
|
maxX: -Infinity,
|
||||||
|
maxY: -Infinity
|
||||||
|
});
|
||||||
|
|
||||||
|
//Current Rectangle center
|
||||||
|
const oTrackCenter = {
|
||||||
|
x: (oScreenBounds.minX + oScreenBounds.maxX) / 2,
|
||||||
|
y: (oScreenBounds.minY + oScreenBounds.maxY) / 2
|
||||||
|
};
|
||||||
|
|
||||||
|
//Convert back center point (x, y) to coords and Move map to the track center
|
||||||
|
this.map.jumpTo({
|
||||||
|
center: this.map.unproject([
|
||||||
|
oTrackCenter.x,
|
||||||
|
oTrackCenter.y
|
||||||
|
])
|
||||||
|
});
|
||||||
|
},
|
||||||
addNewMarkers(aoMarkers) { //FIXME Use its own marker update API
|
addNewMarkers(aoMarkers) { //FIXME Use its own marker update API
|
||||||
this.markers.push(...aoMarkers);
|
this.markers.push(...aoMarkers);
|
||||||
aoMarkers.forEach(this.addMarker);
|
aoMarkers.forEach(this.addMarker);
|
||||||
|
|||||||
Reference in New Issue
Block a user