Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I need to create a map with 2 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.

Thanks in advance,

Luca

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 ); –
share|improve this question
    
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 –  iant Jun 12 '13 at 11:41
add comment

1 Answer 1

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); 
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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