Skip to content
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
60 changes: 41 additions & 19 deletions src/components/map/OlMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ import {
getDocumentLineStyle,
getDocumentPointStyle,
getElevationProfileMarkerStyle,
isFiniteExtent,
swissExtent,
} from './map-utils';

Expand Down Expand Up @@ -897,27 +898,48 @@ export default {
ol.extent.extend(extent, layer.getSource().getExtent());
}

const a = this.$route.query.a;
if (extent.filter(isFinite).length !== 4 && a) {
if (!isFiniteExtent(extent)) {
const a = this.$route.query.a;
// compute extent for area(s)
const areas = await Promise.all(
(Array.isArray(a) ? a.map((area) => area.toString()) : a.toString().split(',')).map(
async (area) => await c2c.area.get(area)
)
);
extent = areas
.flatMap((response) =>
geoJSONFormat.readGeometry(JSON.parse(response.data.geometry.geom_detail)).getPolygons()
)
.flatMap((polygon) => polygon.getCoordinates())
.map((coords) => ol.extent.boundingExtent(coords))
.reduce((acc, extent) => ol.extent.extend(acc, extent));
}
if (a) {
const areas = await Promise.all(
(Array.isArray(a) ? a.map((area) => area.toString()) : a.toString().split(',')).map(
async (area) => await c2c.area.get(area)
)
);
extent = areas
.flatMap((response) =>
geoJSONFormat.readGeometry(JSON.parse(response.data.geometry.geom_detail)).getPolygons()
)
.flatMap((polygon) => polygon.getCoordinates())
.map((coords) => ol.extent.boundingExtent(coords))
.reduce((acc, ext) => ol.extent.extend(acc, ext));
}

if (extent.filter(isFinite).length !== 4) {
// if there is infinity, default extent
// TODO need to be current extent if it exists ...
extent = DEFAULT_EXTENT;
// add extent for waypoint
const w = this.$route.query.w;
if (w) {
const waypoints = await Promise.all(
(Array.isArray(w) ? w.map((wpt) => wpt.toString()) : w.toString().split(',')).map(
async (wpt) => await c2c.waypoint.get(wpt)
)
);
extent = waypoints
.map((response) => response.data.geometry?.geom)
.filter((geom) => !!geom)
.map((geom) => geoJSONFormat.readFeatures(geom)[0])
.map((point) => ol.extent.buffer(point.getGeometry().getExtent(), 10000))
.reduce(
(acc, ext) => ol.extent.extend(acc, ext),
isFiniteExtent(extent) ? extent : ol.extent.createEmpty()
);
}

if (!isFiniteExtent(extent)) {
// if there is infinity, default extent
// TODO need to be current extent if it exists ...
extent = DEFAULT_EXTENT;
}
}

return this.fit(extent);
Expand Down
4 changes: 4 additions & 0 deletions src/components/map/map-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,7 @@ export const geoJSONFormat = new ol.format.GeoJSON();
// extent of Switzerland in EPSG:3857 projection
// (based on https://epsg.io/21781, [5.96, 45.82, 10.49, 47.81] in EPSG:4326)
export const swissExtent = [663464.1651279106, 5751550.865005549, 1167741.4584214399, 6075303.611974082];

export const isFiniteExtent = function (extent) {
return !!extent && extent.filter(isFinite).length === 4;
};
2 changes: 1 addition & 1 deletion src/views/document/utils/boxes/ToolBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export default {
},
};

if (this.document.geometry && this.document.geometry.geom) {
if (this.document.geometry?.geom) {
const point = GeoJSON.readFeatures(this.document.geometry.geom)[0];
const extent = ol.extent.buffer(point.getGeometry().getExtent(), 10000);

Expand Down