[OpenLayers-Users] URL CENTER VAR

Thomas Wood grand.edgemaster at gmail.com
Fri Apr 25 12:34:08 EDT 2008


Add the OpenLayers.Control.ArgParser control and use the lat and lon
URL parameters to set the centre point on load.

If you want a default centre point without having to pass it in the
URL all the time, this code will work:
if(!map.getCenter()) map.setCenter(new OpenLayers.LonLat(-88.3,36.33))
(assuming that I have correctly interpreted your coordinates in the
example URL you gave)

On Thu, Apr 24, 2008 at 11:31 PM, chris1211 <chris at powerhousetechgrp.com> wrote:
>
>  I am having trouble with geting the url var to center my map here is what im
>  using server/map.htm&center=36.33,-88.3&zoom=10
>  any help would be greatly appreciated
>   here is the code :
>  <?xml version="1.0" encoding="UTF-8"?>
>  <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
>  "DTD/xhtml1-strict.dtd">
>  <html xmlns="http://www.w3.org/1999/xhtml">
>         <head>
>         <title>OpenLayers map preview</title>
>         <style type="text/css">
>             #map {
>                 width: 800px;
>                 height: 400px;
>                 border: 1px solid black;
>             }
>             #wrapper {
>                 width: 800px;
>             }
>             #location {
>                 float: right;
>             }
>         </style>
>         <script
>  src="http://192.168.11.2:8080/geoserver/openlayers/OpenLayers.js"
>  type="text/javascript">
>         </script>
>         <script defer="defer" type="text/javascript">
>         var map;
>         var untiled;
>         var tiled;
>         function setHTML(response) {
>             document.getElementById('nodelist').innerHTML =
>  response.responseText;
>         };
>
>         OpenLayers.IMAGE_RELOAD_ATTEMPTS = 5;
>         OpenLayers.DOTS_PER_INCH = 25.4 / 0.28;
>
>         function init(){
>             var bounds = new OpenLayers.Bounds(
>                 1209252.5526935272, 651041.2129505234,
>                 1381167.9232498403, 809964.932844604
>             );
>             var options = {
>                 controls: [],
>                 maxExtent: bounds,
>                 maxResolution: 671.544416235598,
>                 projection: "EPSG:2274",
>                 units: 'm'
>             };
>             map = new OpenLayers.Map('map', options);
>
>
>             // setup tiled layer
>             tiled = new OpenLayers.Layer.WMS(
>                 "Geoserver layers - Tiled",
>  "http://192.168.11.2:8080/geoserver/wms",
>                 {
>                     width: '800',
>                     layers:
>  'topp:states,topp:county,topp:streets,topp:Buildings,topp:driveway',
>                     styles: '',
>                     srs: 'EPSG:2274',
>                     height: '400',
>                     format: 'image/png',
>                     tiled: 'true',
>                     tilesOrigin : "1209252.5526935272,651041.2129505234"
>                 },
>                 {buffer: 0}
>             );
>
>             // setup single tiled layer
>             untiled = new OpenLayers.Layer.WMS(
>                 "Geoserver layers - Untiled",
>  "http://192.168.11.2:8080/geoserver/wms",
>                 {
>                     width: '800',
>                     layers:
>  'topp:states,topp:county,topp:streets,topp:Buildings,topp:driveway',
>                     styles: '',
>                     srs: 'EPSG:2274',
>                     height: '400',
>                     format: 'image/png'
>                 },
>                 {singleTile: true, ratio: 1}
>             );
>
>             map.addLayers([tiled]);
>
>             // setup controls and initial zooms
>             map.addControl(new OpenLayers.Control.PanZoomBar());
>             map.addControl(new OpenLayers.Control.Navigation());
>             map.addControl(new OpenLayers.Control.Scale($('scale')));
>             map.addControl(new OpenLayers.Control.MousePosition({element:
>  $('location')}));
>             map.addControl(new OpenLayers.Control.LayerSwitcher());
>             //map.addControl(new OpenLayers.Control.OverviewMap());
>             // support GetFeatureInfo
>             map.events.register('click', map, function (e) {
>                 document.getElementById('nodelist').innerHTML = "Loading...
>  please wait...";
>                 var url =  map.layers[0].getFullRequestString(
>                     {
>                         REQUEST: "GetFeatureInfo",
>                         EXCEPTIONS: "application/vnd.ogc.se_xml",
>                         BBOX: map.getExtent().toBBOX(),
>                         X: e.xy.x,
>                         Y: e.xy.y,
>                         INFO_FORMAT: 'text/html',
>                         QUERY_LAYERS: map.layers[0].params.LAYERS,
>                         FEATURE_COUNT: 50,
>                         WIDTH: map.size.w,
>                         HEIGHT: map.size.h
>                     },
>                     "http://192.168.11.2:8080/geoserver/wms"
>                 );
>                 OpenLayers.loadURL(url, '', this, setHTML, setHTML);
>                 OpenLayers.Event.stop(e);
>             });
>         }
>         </script>
>
>     </head>
>     <body onload="init()">
>         <div id="map"></div>
>         <div id="wrapper">
>             <div id="location"></div>
>             <div id="scale"></div>
>         </div>
>         <div id="nodelist">Click on the map to get feature info</div>
>
>     </body>
>  </html>
>
>  --
>  View this message in context: http://www.nabble.com/URL-CENTER-VAR-tp16860148p16860148.html
>  Sent from the OpenLayers Users mailing list archive at Nabble.com.
>
>  _______________________________________________
>  Users mailing list
>  Users at openlayers.org
>  http://openlayers.org/mailman/listinfo/users
>



-- 
Regards,
Thomas Wood
(Edgemaster)



More information about the Users mailing list