0

I'm using draw/modify/translate interactions to allow users to draw features. But when the user drags a point outside the map, I want the map to move along.

At the moment I'm using version 6.15, but can't find any build-in way to allow this. Is it possible?

2
  • how would a user drag a point outside the map view? Commented Jan 6, 2024 at 17:58
  • Maybe poor choice of words. The user cliks and drags a point, and moves the mouse outside the map control. Commented Jan 6, 2024 at 21:20

1 Answer 1

0

You could do it like this:

const dragInteraction = new Translate();

dragInteraction.on('translating', (event) => {
    const features = event.features.getArray();

    const featureExtents = features.map(x => x.getGeometry()?.getExtent());

    let boundingFeatureExtent = createEmpty();

    for (const extent of featureExtents) {
        if (!extent) {
            continue;
        }
        extend(boundingFeatureExtent, extent)
    }

    const mapView = map.getView();
    const viewExtent = mapView.calculateExtent();

    if (!containsExtent(viewExtent, boundingFeatureExtent)) {
        mapView.fit(extend(viewExtent, boundingFeatureExtent));
    }

})

https://jsfiddle.net/komarara/zheuncb3/29/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.