Reputation: 10808
I'm using openlayers on an image and looking to have it so that if I zoom all the way out and it's off to the side a bit, that it will be automatically centered. I have the following code, but it is not working. It doesn't look like 'zoomEnd' is called on pinch, but what event is fired?
Is there a list of all the possible events to listen for in Openayers? I can't find something like that anywhere in the documentation..
map = new OpenLayers.Map('detailsdiv', {
projection : 'EPSG:3785',
units : 'm',
fractionalZoom : true,
eventListeners: {
"zoomend": recenterMap
},
maxResolution: Math.pow(2, graphic.numberOfTiers - 1),
numZoomLevels : graphic.numberOfTiers,
controls: [
new OpenLayers.Control.TouchNavigation({
dragPanOptions: {
enableKinetic: true
}
})
]
});
==============================
function recenterMap(){
if (!map.centered){
if (map.getZoom() == 0){
map.centered = true;
map.zoomToMaxExtent();
map.zoomTo(0);
} else {
}
}
}
Upvotes: 0
Views: 932
Reputation: 661
I believe you are better off using the moveend event. It gets fired when a drag, pan, or zoom ends...which is better. Also, here is a list of events: http://dev.openlayers.org/releases/OpenLayers-2.12/doc/apidocs/files/OpenLayers/Map-js.html#OpenLayers.Map.events
You also might want to use map.setCenter() in your recenterMap() function
Upvotes: 1