|
|
|
@ -14,14 +14,19 @@ export function getLayersExtent( |
|
|
|
|
return layers |
|
|
|
|
.filter((l) => l.layer instanceof VectorLayer || l.layer instanceof LayerGroup || l.layer instanceof VectorImage) |
|
|
|
|
.flatMap((ll) => { |
|
|
|
|
const layerName = ll.options.name; |
|
|
|
|
const l = ll.layer; |
|
|
|
|
if (l instanceof LayerGroup) { |
|
|
|
|
return getLayerGroupExtent(l); |
|
|
|
|
// If not all layers check for matching layer name
|
|
|
|
|
if (!allLayers && layerName !== layer) { |
|
|
|
|
return []; |
|
|
|
|
} |
|
|
|
|
return getLayerGroupExtent(l, lastOnly); |
|
|
|
|
} else if (l instanceof VectorLayer || l instanceof VectorImage) { |
|
|
|
|
if (allLayers) { |
|
|
|
|
// Return everything from all layers
|
|
|
|
|
return [l.getSource().getExtent()]; |
|
|
|
|
} else if (lastOnly && layer === ll.options.name) { |
|
|
|
|
} else if (lastOnly && layer === layerName) { |
|
|
|
|
// Return last only for selected layer
|
|
|
|
|
const feat = l.getSource().getFeatures(); |
|
|
|
|
const featOfInterest = feat[feat.length - 1]; |
|
|
|
@ -30,7 +35,7 @@ export function getLayersExtent( |
|
|
|
|
return [geo.getExtent()]; |
|
|
|
|
} |
|
|
|
|
return []; |
|
|
|
|
} else if (!lastOnly && layer === ll.options.name) { |
|
|
|
|
} else if (!lastOnly && layer === layerName) { |
|
|
|
|
// Return all points for selected layer
|
|
|
|
|
return [l.getSource().getExtent()]; |
|
|
|
|
} |
|
|
|
@ -42,13 +47,30 @@ export function getLayersExtent( |
|
|
|
|
.reduce(extend, createEmpty()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function getLayerGroupExtent(lg: LayerGroup) { |
|
|
|
|
export function getLayerGroupExtent(lg: LayerGroup, lastOnly: boolean) { |
|
|
|
|
return lg |
|
|
|
|
.getLayers() |
|
|
|
|
.getArray() |
|
|
|
|
.filter((l) => l instanceof VectorLayer) |
|
|
|
|
.filter((l) => l instanceof VectorLayer || l instanceof VectorImage) |
|
|
|
|
.map((l) => { |
|
|
|
|
if (l instanceof VectorLayer) { |
|
|
|
|
if (l instanceof VectorLayer || l instanceof VectorImage) { |
|
|
|
|
if (lastOnly) { |
|
|
|
|
// Return last coordinate only
|
|
|
|
|
const feat = l.getSource().getFeatures(); |
|
|
|
|
const featOfInterest = feat[feat.length - 1]; |
|
|
|
|
const geo = featOfInterest?.getGeometry(); |
|
|
|
|
if (geo) { |
|
|
|
|
// Look at flatCoordinates for more robust support including route layer
|
|
|
|
|
const flatCoordinates = geo.flatCoordinates; |
|
|
|
|
const flatCoordinatesLength = flatCoordinates.length; |
|
|
|
|
if (flatCoordinatesLength > 1) { |
|
|
|
|
const lastX = flatCoordinates[flatCoordinatesLength - 2]; |
|
|
|
|
const lastY = flatCoordinates[flatCoordinatesLength - 1]; |
|
|
|
|
return [lastX, lastY, lastX, lastY]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return []; |
|
|
|
|
} |
|
|
|
|
return l.getSource().getExtent() ?? []; |
|
|
|
|
} else { |
|
|
|
|
return []; |
|
|
|
|