2

I am really new to Web GIS and currently I am trying to develop a web map using FOSS software. This is my code of OpenLayers and it is not working.

GeoServer URL

http://localhost:8080/geoserver/sac/wms?service=WMS&version=1.1.0&request=GetMap&layers=sac:Luse&styles=&bbox=105097.8879663402,181965.81598811893,107146.57910105384,183739.10929816443&width=512&height=443&srs=EPSG:5235&format=application/openlayers&

OpenLayers code:

<script type='text/javascript' src='OpenLayers.js'>
</script><script type='text/javascript'> 
var map; function init() 
{ 
   map = new OpenLayers.Map('map_element', {}); 
   var wms = new OpenLayers.Layer.WMS( 'OpenLayers WMS', 'http://localhost:8080/geoserver/sac/wms', 
   {layers: 'sac:Luse'}, 
   {} 
); 
map.addLayer(wms); 
if(!map.getCenter()){ map.zoomToMaxExtent(); } } 
</script>
</head>
<body onload='init();'>
    <div id='map_element' style='width: 500px; height: 500px;'>
</div>
</body>
</html>

What is the problem?

  • 1
    I don't know how you first put your example together, but if you didn't know GeoServer Admin can generate an OpenLayers example of any layer for you through the Layer Preview page (v2.1.3 and possibly earlier, I've only used one version). You can then take what you want from the preview's source. By default the preview will only contain one layer (can be a layer group) but by playing with the URL you can view multiple layers – tomfumb Apr 21 '12 at 20:18
3

It is better if you explain what do you mean by "it not working" but my guess would be : By default openlayers support EPSG:4326 projection. Here as I see you are requesting a layer in EPSG:5235 so you have to set projection explicitly to EPSG:5235.

It should be similar to this code :

var mapoptions = {
      maxExtent: new OpenLayers.Bounds(...),
      units: 'm',
      projection: "EPSG:5235",
    };
    map = new OpenLayers.Map( 'map',mapoptions );

There should be several documentation about the basics of openlayers (particularly about projections and bounds that might be tricky from time to time)

  • Thanks.Really help full. "it not working" means map is not showing browser.I will try according to your answer – sacprasanna Apr 22 '12 at 5:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.