[OpenLayers-Users] Map won't center

Eric Lemoine eric.lemoine at camptocamp.com
Mon Feb 13 00:29:53 EST 2012


On Friday, February 10, 2012, Lawrence Miller <lawrence.miller at noaa.gov>
wrote:
> I am trying to load a basemap and layers into a 696x425 frame. The map
won't appear in the center of the frame, it appears centered low and to the
left. I can drag the map into the correct location, but I would prefer it
just appear there. Any suggestions?
>
> my script:
>       <div style="width:696px; height: 425px; border: 1px solid;"
id="map"></div>
>       <script defer="defer" type="text/javascript">

What if you create the map in an onload callback function as in the
OpenLayers examples?


>         var options = {
>             maxExtent: new OpenLayers.Bounds(0,0,1410,913),
>             maxResolution: "auto"
>         };
>         var map = new OpenLayers.Map('map',options);
>         var base = new OpenLayers.Layer.Image("Basemap",
>              "newestbasemap.gif",
>              new OpenLayers.Bounds(0,0,1410,913),
>              new OpenLayers.Size(1410,913),
>              {isBaseLayer: true}
>              );
>         var ice = new OpenLayers.Layer.Image("Freezing Level",
>              "pt3.gif",
>              new OpenLayers.Bounds(0,0,1410,913),
>              new OpenLayers.Size(1410,913),
>               {isBaseLayer: false,
>                visibility: false,
>                opacity: 0.80}
>              );
>         var wind = new OpenLayers.Layer.Image("Wind Speed",
>              "pt3windspd.gif",
>              new OpenLayers.Bounds(0,0,1410,913),
>              new OpenLayers.Size(1410,913),
>               {isBaseLayer: false,
>                visibility: false,
>                opacity: 0.60}
>              );
>         var turb = new OpenLayers.Layer.Image("Turbulence",
>              "pt3turb.gif",
>              new OpenLayers.Bounds(0,0,1410,913),
>              new OpenLayers.Size(1410,913),
>               {isBaseLayer: false,
>                visibility: false,
>                opacity: 0.60}
>              );
>         map.addLayers([base, ice, wind, turb]);
>         map.setCenter(new OpenLayers.LonLat(705,456));
>         map.zoomToMaxExtent();
>         map.addControl(new OpenLayers.Control.LayerSwitcher());
>       </script>

-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120213/e4433b0f/attachment-0001.html


More information about the Users mailing list