-3

I am trying to overlay my India roads vector as a WMS layer using OpenLayers. I can overlay the data on vmap (http://vmap0.tiles.osgeo.org/wms/vmap0), but I want to do the same task over OpenStreetMap (OSM).

I am trying many different ways but the png image is not created successfully. I think problem is with the projection EPSG:900913 or EPSG:4326 it is using. I have tried with both projections but neither work.

It is very urgent for me. I am new to OpenLayers, I have put all my code below:

My working file(vmap)

    var map, ia_wms;
    function init(){
        map = new OpenLayers.Map('map');
        var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
            "http://vmap0.tiles.osgeo.org/wms/vmap0?", {layers: 'basic'} );          
       var ia_wms = new OpenLayers.Layer.WMS("India_road","http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w3/ms4w/apps/openlayers-2.12/examples/india_wms6.map",{layers:"India_road",transparent:true,format:'image/png'},
           {
           isBaseLayer: false
           }
           );

        map.addLayers([ol_wms, ia_wms]);
        map.addControl(new OpenLayers.Control.LayerSwitcher());
        map.zoomToExtent(new OpenLayers.Bounds(68.5654, 8.08419, 96.5365, 36.9335));
    }

My mapfile : http://pastebin.com/FgrF48xr


My WMS overlay over OSM (please check the projections) not working why?

    var map, ia_wms;
    function init(){
    var WGS84 = new OpenLayers.Projection("EPSG:4326");
    var WGS84_google_mercator = new OpenLayers.Projection("EPSG:900913");
    map = new OpenLayers.Map('map',{
    controls:[
    new OpenLayers.Control.Navigation(),
    new OpenLayers.Control.PanZoom(),
    new OpenLayers.Control.MousePosition({
    div:document.getElementById("coordinates")
    })
    ],
   });

        mapnik = new OpenLayers.Layer.OSM.Mapnik("OpenStreetMap (Mapnik)");
        var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
            "http://vmap0.tiles.osgeo.org/wms/vmap0?", {layers: 'basic'} );
        var ia_wms = new OpenLayers.Layer.WMS("India_road","http://localhost/cgi-bin/mapserv.exe?map=C:/ms4w3/ms4w/apps/openlayers-2.12/examples/india_wms6.map",{layers:"India_road",transparent:true,format:'image/png'},
        {
        isBaseLayer: false
        }
        );
        map.addLayers([ia_wms,ol_wms,mapnik]);
        map.addControl(new OpenLayers.Control.LayerSwitcher());
        var mapextent = new OpenLayers.Bounds(68.5654 ,8.08419 ,96.5365 ,36.9335).transform(WGS84, map.getProjectionObject());  
        map.zoomToExtent(mapextent);

}

result image:

enter image description here

I am using the same map file:

**** in HTML page

//projection: WGS84_google_mercator,
//displayProjection: WGS84

both are commented but if we uncomment them, image is not created but vmap and OSM India area are in the correct position


image seen:

enter image description here

Any one in expert in OpenLayers WMS please debug my error... I am trying for two weeks to overlay on OSM.

  • 1
    Please don't open multiple questions for the same issue. And Where does ArcGIS fit into all of this? – Devdatta Tengshe Dec 5 '13 at 6:54
  • ok sir first one is for google street so.. – S S Anand GIS Engineer Dec 5 '13 at 7:00
  • i think arcgis developers use openlayer also so put it sir – S S Anand GIS Engineer Dec 5 '13 at 7:02
1

A lot usually depends on your wms service, and the actual projection of data.

I usually use some code which is similar to this:

var map;

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

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

    var states=new OpenLayers.Layer.WMS(
                    "States", "http://demo.opengeo.org/geoserver/topp/wms",
                    {
                        LAYERS: 'topp:states',
                        transparent: true
                    },
                    {
                         isBaseLayer: false
                    });
    map.addLayers([
            new OpenLayers.Layer.Google(
                "Google Streets", // the default
                { numZoomLevels:20, sphericalMercator: true}
            ), states]);

    map.addControl(new OpenLayers.Control.LayerSwitcher());

 // if you want to use Geographic coords, transform to ESPG:900913
    var ddBounds = new OpenLayers.Bounds(-120,20,-60,60);
    map.zoomToExtent(
        ddBounds.transform(geographic, mercator)
    );

}
  • i use to change my code with above but india layer(png) is not rendering i think problem in my .map file ,can you please verify my .map file's projection and wms request are correct or not (this map file successfully plot on vmap).my map file projection may change?? – S S Anand GIS Engineer Dec 5 '13 at 8:09
  • localhost/cgi-bin/mapserv.exe?map=C:/ms4w3/ms4w/apps/… : put in browser it plot india map correctly – S S Anand GIS Engineer Dec 5 '13 at 8:11
  • I don't have mapserver installed on this system, nor do I have your data so I can't check. I'll recommend that you check that the service runs properly by viewing it from a client like Qgis, or ArcMap, and then changing projection in the client. – Devdatta Tengshe Dec 5 '13 at 8:26
  • can u access this file : pastebin.com/FgrF48xr – S S Anand GIS Engineer Dec 5 '13 at 8:34
  • if u can accessible please check anything extra add for wms metadata ? this map work on normal browser and correclly overlay opelayer default map, var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", "vmap0.tiles.osgeo.org/wms/vmap0?", {layers: 'basic'} ); so i think its work on google street or osm layer also right ?? – S S Anand GIS Engineer Dec 5 '13 at 8:44

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.