1

I have clustering enabled on an OpenLayers map and have used code from the first answer in: Openlayers zoom in on cluster to zoom in on a cluster.

function onFeatureClick(event) {
    if (event.feature.cluster.length > 1) {
        // *** Change this so that the map zooms on cluster location ***
        map.setCenter(event.feature.geometry.getBounds().getCenterLonLat());
        map.zoomIn();
    } else {
        // popup code
    }
}

Q: Is it possible to zoom on the cluster location so that it stays in the same place? Right now the cluster gets centered on the map. In other words the cluster should not move when zoomed in.

  • It seems my only two options are, zoom in to the center of the map and zoom in while moving the cluster to the center of the map. There is no way to zoom in with the cluster staying in the same location like when you double click or use the mousewheel. – CDavis Feb 6 '14 at 18:14
1

It seems if I use some jQuery like this I an get the page to zoom into the correct location:

var pagepos = [];
var xyloc = [];
function onFeatureClick(event) {
    pagepos = $("#"+event.feature.geometry.id).position();
    xyloc.x = parseFloat(pagepos.left + 9);
    xyloc.y = parseFloat(pagepos.top + 9);
    if (event.feature.cluster.length > 1) {
        map.zoomTo(this.map.zoom + 1, xyloc);
    } else {
        // popup code
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.