[OpenLayers-Users] Newbie needs help zoomingToExtent

Al Vigil albert.vigil at gmail.com
Mon Oct 15 16:49:30 PDT 2012


I am new to OpenLayers and to GeoServer and am having trouble zooming to the extent of my map.  Instead my map displays at the World zoom level (or appears to).  I am able to manually zoom in but would rather do the zooming programatically.

I have a simple html page, below, and have tried every conceivable combination of options without any luck.  The one variable that I am uncertain of is tileOrigin.  I obtained this from the GeoServer demo link, but do know if this is correct.  However leaving it out has no effect.

Does anyone out there have any insight as to what I am doing wrong?

Thanks in advance.  Any help would be appreciated.

Al Vigil
albert.vigil at gmail.com

<!DOCTYPE html> 

<html lang='en'> 

<head> 

    <meta charset='utf-8' /> 

      <title>My OpenLayers Map</title>    

    <script type='text/javascript' src='OpenLayers.js'></script>

    <script type='text/javascript'>

 

    var map;

    var bounds = new OpenLayers.Bound(-88, 11, -84, 15);

    function init() {

 

        // Setup our map object

        map = new OpenLayers.Map('map_element', {});

        

        // Setup our two layer objects

        var wms_layer_map = new OpenLayers.Layer.WMS(

                'base layer',

                  'http://localhost:8088/geoserver/wms',

                  {                    

                     layers: 'Nicaragua:nicbase,Nicaragua:l4Roads',

                     styles: 'nicbase,l4Roads',

                     //bbox: '-88,11,-84,15' ,

                     srs: 'EPSG:4326',

                     //width: '800'

                     format: 'image/png',

               tiled: 'true',

               tilesOrigin : "143.60260815000004,-43.851764249999995"

                     //tiled: true ,

                     //tilesorigin: '-88,11'

                     //tilesorigin: '-130,24'

                  }

                  //{isBaseLayer: true},

                  //{buffer: 0}

            );

 

          var nicBounds = new OpenLayers.Bounds(

           -8800000, 1500000, -8400000, 1500000

        );        

        // Add layer to the map

        map.addLayers([wms_layer_map]);//,roadsl4_layer]);

        

        // Add a layer switcher control

        map.addControl(new OpenLayers.Control.LayerSwitcher({}));

        // Zoom the map to the extent

        //map.zoomToExtent(bounds);

            if(!map.getCenter()){

                //map.zoomToMaxExtent();

                //map.zoomTo(10);  //does not work

                map.zoomToExtent(nicBounds); //does not work

            }

            //map.zoomToExtent(nicBounds);  // does not work

    }

 

    </script>

</head>

 

<body onload='init();'>

    <div id='map_element' style='width: 800px; height: 600px;'>

      </div>

</body>

</html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20121015/2fd09006/attachment-0001.html>


More information about the Users mailing list