EOX-A / EOxElements

A Web Component collection of geospatial UI elements, crafted by EOX.
https://eox-a.github.io/EOxElements/
MIT License
13 stars 2 forks source link

Add view animation convenience functionality #570

Closed silvester-pari closed 1 month ago

silvester-pari commented 7 months ago

E.g.

santilland commented 4 months ago

Please also consider zoom to extent

silvester-pari commented 4 months ago

This could be an animateView property / animate-view attribute (I'd say default to true). If this is set, setting the center and/or setting the zoom would animate instead of "just" setting it. It would need to check in the _changedProperties' (updated` hook) if both of them changed at the same time and do the animation only once.

A basic showcase would be to have a map and then set:

We could pass some more options to the animateView property, such as:

Regarding features, extent etc. I don't have a clear idea yet...

silvester-pari commented 4 months ago

Following scenarios are thought of:

lubojr commented 4 months ago

Just a minor consideration of setting layer property fitView: true - how would it behave if more layers have this property? First found or the one which was freshly updated?

santilland commented 4 months ago

The last option is once a feature is already loaded in a vector layer, it is possible to zoom to the available features? I guess at least for stac we usually will have a bbox for the collection or item, so the extent should be ok for those cases. I can't think of any more options right now, not sure if being able to pass a feature would make sense.

StefanBrand commented 3 months ago

zoom to rendered feature via vector/vector tile layer

I have a snippet for getting the extent of a feature of a vector tile layer, even if split across multiple tiles:

import { createEmpty as createEmptyExtent, extend } from "ol/extent";

function getFeaturesInMapExtent(eoxMap, layerName) {
  const olMap = eoxMap.map;

  const view = olMap.getView();
  const mapExtent = view.calculateExtent(olMap.getSize());
  const layer = eoxMap.getLayerById(layerName);

  return layer.getSource().getFeaturesInExtent(mapExtent);
}

function mergeExtents(featureParts) {
  return featureParts.reduce((extent, featurePart) => {
    return extend(extent, featurePart.getExtent());
  }, createEmptyExtent());
}

export default function getFeatureExtent(eoxMap, layerName, parcelId) {
  const featureParts = getFeaturesInMapExtent(eoxMap, layerName).filter(
    (f) => f.get("id") == parcelId
  );
  return mergeExtents(featureParts);
}
RobertOrthofer commented 3 months ago

keep in mind that this only works in features in loaded tiles. If you can't guarantee that all tiles of the feature are already loaded, a simple pre-calculated extent is the safer option.

RobertOrthofer commented 3 months ago

Two things are not fully implemented yet:

1.) selectById we do have the method to highlightById, which basically is selectById, and we also have the panIntoFeature option on the select interaction. However, we don't have both together yet.

2.) fitView layer property I'm not sure if we really want this option on the layer, as multiple layers will interfere with this and having an extent on the eoxMap and an overruling extent on the layer seems counter-intuitive. I think it would be best if the application could just control the zoomExtent property

silvester-pari commented 1 month ago

Closed in favor of the two newly created issues.