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.

When I try the following code, OpenLayers returns a zero result. What have I done wrong, here?

var map;

function loadMap () {

    // Based on example code: view-source:
    //     http://openlayers.org/dev/examples/vector-formats.html

    map = new OpenLayers.Map(el);
    var googleStreetMap = new OpenLayers.Layer.Google('Google Street Map', 
                                                      { numZoomLevels: 20 });
    map.addLayers(googleStreetMap);
    var result = map.getNumLayers(); // Result == 0 :sad-panda:            
}

In the code above, I thought that the map.getNumLayers() should return 1 - considering i've asked to add a google street map.

Why is it returning zero, please?

UPDATE: something else to note: there is also no baseLayer :( I thought this would be the base layer???

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

I think it's because addLayers expects an array of layers. If you just want to add a single layer, you should use map.addLayer instead. Or you could give addLayers what it wants:

map.addLayers([googleStreetMap]);

I hope that helps.

share|improve this answer
1  
Also you can write map.addLayers([layer]). –  drnextgis Oct 8 '12 at 7:14
    
Ha damn!!! Originally I had map.addLayers([layer1, layer2]); but removed the layer2 call .. and therefore forgot to remove the last 's'. DOH DOH DOH! Thanks heaps guys. Totally fixed the problem! –  Pure.Krome Oct 8 '12 at 23:54
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.