[OpenLayers-Users] Result of expression 'map' [undefined] is not an object.

Paul Spencer pagameba at gmail.com
Sun Oct 4 18:36:12 EDT 2009


Also note that in IE (6 and 7, not sure about 8), if you have an  
element with an id, any global variables (used without declaring with  
a var) of the same name refers to the element, not what you assign to  
it.  So if you do this:

<html>
<head>
<script src="OpenLayers.js"></script>
<script>
   map = new OpenLayers.Map( 'map' );
   map.addLayer(new OpenLayers.Layer.Vector('vector');
</script>
</head>
<body>
   <div id='map'></div>
</body>
</html>

you will get an error in IE (6 and 7 at least) with the line that  
starts map.addLayer whereas if you change the previous line to:

var map = new OpenLayers.Map( 'map' );

you will not get an error.

Yeay IE

Cheers

Paul

On 2009-10-04, at 1:13 PM, Andreas Hocevar wrote:

> Also make sure that you don't have extra commas at the end of object
> definitions.
>
> Regards,
> Andreas.
>
> Stephen Woodbridge wrote:
>> Nicholas Efremov-Kendall wrote:
>>
>>> Hi all,
>>>
>>> I'm getting the following error in what used to be functional
>>> code Result of expression 'map' [undefined] is not an object.
>>>
>>> It's breaking on the statement map.addLayer(cities). Here's the  
>>> exerpted
>>> code that I've added around this. I can add a stripped down  
>>> version of
>>> the rest, but it's bulky and I've only messed with the following  
>>> bits.
>>> Any suggestions as to what's causing this error?
>>>
>>> var styleMap = new OpenLayers.StyleMap(
>>> {'default':OpenLayers.Util.applyDefaults(
>>> {
>>>      label: '${Name}',
>>>      strokeWidth:1,
>>>      strokeColor:"#CCCCCC",
>>>      fillColor: "green",
>>> })
>>> }
>>>   );
>>> };
>>>
>>> var cities = new OpenLayers.Layer.GML
>>> ("7th Century Cities", "data/cities.gml",
>>> {
>>> styleMap: styleMap,
>>> projection: new OpenLayers.Projection("EPSG:4326"),
>>> format: OpenLayers.Format.GML,
>>> label: "${Name}",
>>> }
>>> );
>>> map.addLayer(cities);
>>>
>>
>> Where is "var map" defined. It sounds like it is not in the visible
>> scope of the above code.
>>
>> -Steve W
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
>
>
> -- 
> Andreas Hocevar
> OpenGeo - http://opengeo.org/
> Expert service straight from the developers.
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users




More information about the Users mailing list