[OpenLayers-Users] Problems with IE8 and GeoJSON
Gerhard Dünnebeil
Gerhard.Duennebeil at chello.at
Wed Aug 12 01:44:38 EDT 2009
Hi everybody.
Not sure this problem already got discussed, if yes.....please give me a
pointer to it. Otherwise .....
I try to display a vector layer using a fixed strategy and GeoJSON.
Things work fine under Firefox.
When I test things with IE8, things fail. I run IE8 in default mode, no
special headers or anything set on the web page that holds the map or
elsewhere.
I digged deeper into it and found the following strange behaviour:
When the Layer is about to be drawn, data is fetched from the net and
converted from JSON to java script. This happens in the read method
(GEOjson.js/Line 64, see code excerpt below)
A bit below (line 69) the conversion is done into the variable "obj".
When you look at the "obj" variable at this point it holds an array
named features *but* the feature array has *no* length property.
Otherwise the array is correct with respect to the input data.
In line 108 this feature array is iterated with a reference to the
length property. When IE8 interprets this statement the feature array
suddenly *has* a length property but it is wrong (too big, 3 instead of 2).
As a follow-up error this causes the loop to break via the catch block
when features[2] is accessed and gives back an empty result instead of
the expected.
Is this a known problem?
How to work around it?
thanks for any help and
best regards
Gerhard
------------------------------------------
Appendix 1, the code mentioned above)
read: function(json, type, filter) {
type = (type) ? type : "FeatureCollection";
var results = null;
var obj = null;
if (typeof json == "string") {
line 69: obj = OpenLayers.Format.JSON.prototype.read.apply(this,
[json,
filter]);
} else {
obj = json;
}
if(!obj) {
OpenLayers.Console.error("Bad JSON: " + json);
} else if(typeof(obj.type) != "string") {
OpenLayers.Console.error("Bad GeoJSON - no type: " + json);
} else if(this.isValidType(obj, type)) {
switch(type) {
case "Geometry":
try {
results = this.parseGeometry(obj);
} catch(err) {
OpenLayers.Console.error(err);
}
break;
case "Feature":
try {
results = this.parseFeature(obj);
results.type = "Feature";
} catch(err) {
OpenLayers.Console.error(err);
}
break;
case "FeatureCollection":
// for type FeatureCollection, we allow input to be
any type
results = [];
switch(obj.type) {
case "Feature":
try {
results.push(this.parseFeature(obj));
} catch(err) {
results = null;
OpenLayers.Console.error(err);
}
break;
case "FeatureCollection":
line 108: for(var i=0,
len=obj.features.length; i<len; ++i) {
try {
results.push(this.parseFeature(obj.features[i]));
} catch(err) {
results = null;
OpenLayers.Console.error(err);
}
}
break;
default:
try {
var geom = this.parseGeometry(obj);
results.push(new
OpenLayers.Feature.Vector(geom));
} catch(err) {
results = null;
OpenLayers.Console.error(err);
}
}
break;
}
}
return results;
------------------------------------------------
Appendix 2, the JSON data
{ "type" : "FeatureCollection", "features" : [ { "type" : "Feature"
,"geometry": { "type": "Point", "coordinates": [291068,270013] }
,"properties": { "img_url": "icons/green_dot.gif" } }, { "type" :
"Feature" ,"geometry": { "type": "Point", "coordinates": [291069,269967]
} ,"properties": { "img_url": "icons/red_dot.gif" } }, ] }
More information about the Users
mailing list