1

I need to create a map with two layers. The first layer (basemap) is the OSM layer, and the second layer is my custom GeoServer WMS layer. This layer is in EPSG:4326 projection. Is this possible?

I have read many posts but I didn't solve my problem. I don't find this GeoServer layer in my map.

map = new OpenLayers.Map('map'{projection:"EPSG:900913",
                               maxResolution:2319.89824519781,
                               units:'m' }); 

osm = new OpenLayers.Layer.OSM( "Simple OSM Map"); 
wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", "95.172.21.2:8080/geoserver/wms";,
                                 {layers: 'asl.caserta:distretti_4326',trasparent: true},
                                 {isBaseLayer: false}); 
map.addLayers([osm, wms]); 
map.setCenter( new OpenLayers.LonLat(14.22231, 41.26700).transform( new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject() ), 12 ); –
  • Welcome to the forum. As first suggestion I would like to tell you that you need to add your code to see what is going wrong there. With that people can suggest you solutions to circumvent the problems you encountered. – Gery Jun 11 '13 at 18:42
  • map = new OpenLayers.Map('map',{projection : "EPSG:900913",maxResolution:2319.89824519781,units:'m' }); osm = new OpenLayers.Layer.OSM( "Simple OSM Map"); wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", "95.172.21.2:8080/geoserver/wms", {layers: 'asl.caserta:distretti_4326', trasparent: true},{isBaseLayer: false}); map.addLayers([osm, wms]); map.setCenter( new OpenLayers.LonLat(14.22231, 41.26700).transform( new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject() ), 12 ); – Luca Santaniello Jun 11 '13 at 18:47
  • I don't use geoserver, so not sure if your problem is the ip you're using. But the code needs displayProjection below projection. There you need to use EPSG:4326 – Gery Jun 11 '13 at 19:37
  • 1
    try adding http:// to "95.172.21.2:8080/geoserver/wms – Ian Turton Jun 12 '13 at 11:41
2

There are a couple of issues with your code. Firstly, the map was not properly initialized. The Url of WMS service, as well as the transparent paramter was incorrect.

I have corrected the code. The following works for me:

var map, layer;
function init(){
    var geographic = new OpenLayers.Projection("EPSG:4326");
    var mercator = new OpenLayers.Projection("EPSG:900913");

    map = new OpenLayers.Map( 'map',{projection: mercator} );


    var osm = new OpenLayers.Layer.OSM( "Simple OSM Map"); 
    map.addLayer(osm);
    layer = new OpenLayers.Layer.WMS("WMS", "http://95.172.21.2:8080/geoserver/wms",
                         {layers: 'asl.caserta:distretti_4326',transparent: true},
                         {isBaseLayer: false}); 
    map.addLayer(layer);
    map.setCenter(new OpenLayers.LonLat(14.22231, 41.26700).transform(geographic,mercator), 10); 
}

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.