If I use a single WMS layer as map base layer it loads the map, but adding different layers like (Google, Yahoo) to map it won't work. Can anyone tell me how to overcome this... please check this:

    <script src="http://maps.google.com/maps/api/js?sensor=false&v=3.3" type="text/javascript"></script>
    <script src="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=abcdefg1234" type="text/javascript"></script>
    <script src="http://openlayers.org/api/OpenLayers.js" type="text/javascript"></script>   
    <script type="text/javascript">
        var map;  
        function init() {
           map = new OpenLayers.Map('map');
           var googleLayer = new OpenLayers.Layer.Google("Google", { 'sphericalMercator': true,
           'maxExtent': new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34)});
           var wmsLayer = new OpenLayers.Layer.WMS("OpenLayers WMS",                             "http://vmap0.tiles.osgeo.org/wms/vmap0", { layers: 'basic' });
           var yahooLayer = new OpenLayers.Layer.Yahoo("Yahoo");
           map.addLayers([googleLayer, wmsLayer, yahooLayer]);
           map.setCenter(new OpenLayers.LonLat(75.5, 8.5), 5);
           map.addControl(new OpenLayers.Control.LayerSwitcher());
           map.addControl(new OpenLayers.Control.MousePosition());
  • can you clarify "doesn't work"? – Ian Turton Aug 9 '12 at 9:56
  • it doesn't load the map. I've fiddle the code please check : jsfiddle.net/4psyk – bios Aug 9 '12 at 10:01
  • I've found that it is because of the yahoo layer, and i removed it. But there is other problems. first one: map center in google and wms layers are different. second: longitude and latitude values of google layer is higher. how to solve this please help me to learn. I've fiddle my code here please check : jsfiddle.net/8bMHS – bios Aug 9 '12 at 10:03

i think this is the problem of projection or resolution.

try to use OSM instead of "http://vmap0.tiles.osgeo.org/wms/vmap0".

map.addLayer(new OpenLayers.Layer.OSM());

i hope it helps you...

  • in fact that server does handle 900913 so it should work - vmap0.tiles.osgeo.org/wms/… – Ian Turton Aug 9 '12 at 9:57
  • try to use this example codes instead of yours. – Aragon Aug 9 '12 at 9:59
  • That example is only for google layer, but i'm trying to combine two or more different layers – bios Aug 9 '12 at 10:07
  • @bios add this line map.addLayer(new OpenLayers.Layer.OSM()); to google map example which i have given above. i have tested, it was working... – Aragon Aug 9 '12 at 10:24
  • @Aragon :can you please update that fiddle with that code, and please post that link – bios Aug 9 '12 at 10:30

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.