[OpenLayers-Dev] Allowing zoom to arbitrary extents in OL

Paul Spencer pspencer at dmsolutions.ca
Sat Sep 8 15:29:11 EDT 2007


Hi, apologies for the cross post, but Chris indicated that mapbuilder  
was also looking for a solution to this problem.  And thanks to Chris  
for helping me to solve this one.

My problem: when using OL with singleTile layers, I need to be able  
to allow users to zoom to arbitrary extents.  OL internally keeps a  
list of fixed resolutions and snaps to those, meaning that zooming to  
extents often has the appearance of being 'buffered' somewhat.  In  
some cases, zooming results in panning.

My solution:

assuming that I can track when I am only using singleTile layers, and  
that I always use zoomToExtent:

if (this.bSingleTile) {
      var viewSize = this.oMapOL.getSize();
      var idealResolution = Math.max( extent.getWidth()  / viewSize.w,
                                     extent.getHeight() / viewSize.h );
      this.oMapOL.baseLayer.resolutions = [idealResolution];
      this.oMapOL.zoom = 1;
}
this.oMapOL.zoomToExtent(extent);

Cheers

Paul
+-----------------------------------------------------------------+
|Paul Spencer                          pspencer at dmsolutions.ca    |
+-----------------------------------------------------------------+
|Chief Technology Officer                                         |
|DM Solutions Group Inc                http://www.dmsolutions.ca/ |
+-----------------------------------------------------------------+








More information about the Dev mailing list