AW: [OpenLayers-Users] Special Zoom - only zoom out or pan

Arnd Wippermann arnd.wippermann at web.de
Thu Jun 23 10:39:12 EDT 2011


Hi,

This should work

//Zoom to geometries extent or pan to geometries center
function haurein(GeometryArray)
{
    //calculate bounds and center for all geometries
    //I don't know, if there is an easier way to calculate this
    var GeometryCollection = new OpenLayers.Geometry.Collection();

    for(var i=0;i<GeometryArray.length;i++)
    {
        var component = GeometryArray[i];
        GeometryCollection.addComponent(component);
    }
    var bounds = GeometryCollection.getBounds();
    var center = GeometryCollection.getBounds().getCenterLonLat();

    var zoom = map.getZoom();
    if(zoom>3 && zoom<5)
        map.zoomToExtent(bounds);
    else
        //map.panTo(center); //smooth
        map.moveTo(center);
}

var source = map.displayProjection;
var dest   = map.getProjectionObject();

var pt1 = new OpenLayers.Geometry.Point(7, 51).transform(source, dest);
var pt2 = new OpenLayers.Geometry.Point(10, 54).transform(source, dest);

var GeometryArray = [pt1, pt2];

haurein(GeometryArray);

Arnd 

-----Ursprüngliche Nachricht-----
Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von Jan
Tappenbeck
Gesendet: Donnerstag, 23. Juni 2011 10:53
An: users at openlayers.org
Betreff: [OpenLayers-Users] Special Zoom - only zoom out or pan



  hi !

it is possible to zoom to a collection of points by


var bounds = new OpenLayers.Bounds  ();

// for some points
var wpoint;
wpoint = new OpenLayers.LonLat (coord[IdWayPoint][1],
coord[IdWayPoint][0]).transform(map.displayProjection,
map.getProjectionObject());

bounds.extend (wpoint);

but now  i have s special situation.

only if the zoomlevel is smaller (ex. form 13 to 10) this should be chance -
otherwise the pan-part should be use.

did anybody now how to make this if possible ??

regards Jan :-)


_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users



More information about the Users mailing list