[OpenLayers-Users] cannot call method cotains lonlat of null

Janis Elmeris janis.elmeris at intelligentsystems.lv
Tue Jun 28 05:24:51 EDT 2011


If you're using addLayers(), you must pass it an array of layers, not a 
layer itself, and not each layer in its own parameter.

So, instead of "map.addLayers(mapnik, markers);" try 
"map.addLayers([mapnik, markers]);".

Also, you're adding the same layer several times there.

Janis


On 2011.06.02. 18:01, Nicholas Efremov-Kendall wrote:
> Hi all,
>
> I'm sure there's a something elementary that I'm missing here, but I 
> can't seem to figure this out...
>
> I'm trying to set up a simple map centered on specific lon lat. The 
> error provided by chrome is that it can't call method 'containslatlon' 
> of null. I'm not sure what I'm doing wrong here, but the script gives 
> me the map and control, but no layers. thanks in advance.
>
> <!DOCTYPE html >
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html; />
> <style>
> #map{
> width: 400px;
> height: 400px;
> }
> </style>
>
> <script type="text/javascript" 
> src="http://maps.google.com/maps/api/js?sensor=true"></script>
> <script src="OpenLayers-2.11-rc1/OpenLayers.js" 
> type="text/javascript"></script>
> <script src="modernizr-1.7.min.js" type="text/javascript"></script>
> <script 
> src="http://www.openstreetmap.org/openlayers/OpenStreetMap.js"></script>
> <script type="text/javascript">
>         // <![CDATA[
> function initGIS(){
> //Map
> var map= new OpenLayers.Map('map',
> {
> controls:[
> new OpenLayers.Control.Navigation(),
> new OpenLayers.Control.PanZoomBar(),
> new OpenLayers.Control.LayerSwitcher(),
> new OpenLayers.Control.Attribution(),
> new OpenLayers.Control.ScaleLine()],
> sphericalMercator: true,
> maxExtent: new 
> OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
> maxResolution: 156543.0399,
> numZoomLevels: 19,
> units: 'm',
> // projection: new OpenLayers.Projection("EPSG:900913"),
> // displayProjection: new OpenLayers.Projection("EPSG:4326")
> }
> );
> //Google BaseLayer
> var mapnik = new OpenLayers.Layer.OSM();
>         map.addLayers(mapnik);
> //var google_map = new OpenLayers.Layer.Google('Google Maps',{});
>    var markers=new OpenLayers.Layer.Markers("Markers");
> map.addLayers(mapnik, markers);
>
> map.setCenter(
> new OpenLayers.LonLat(38.65, -90.72).transform(new 
> OpenLayers.Projection("EPSG:4326"),new 
> OpenLayers.Projection("EPSG:900913")
> ), 12
> );
> }
> //]]>
> </script>
> </head>
> <body onLoad="initGIS()">
> <div id="map"></div>
> </body>
> </html>
>
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110628/27e185ea/attachment.html


More information about the Users mailing list