[OpenLayers-Users] Problems with IE8 and GeoJSON
Eric Lemoine
eric.lemoine at camptocamp.com
Sun Aug 16 13:03:59 EDT 2009
On Sunday, August 16, 2009, Gerhard Dünnebeil
<Gerhard.Duennebeil at chello.at> wrote:
> ok, finally found it myself.
> When working with JSON the Internet Explorer is more critical than firefox.
> Within the array brackets [] for the "features" array my JSON contained
> an extra "," at the end.
> Firefox ignores it, IE obviously does not.
> Fixing this problem made my code work
Hi. I'm not sure extra comas are accepted by the JSON standard anyway.
On a side note, I noticed that IE8 isn't sensitive to extra comas in
JS objects and arrays as IE<8 is.
Cheers,
> Best regards
> Gerhard
>
>
> Gerhard Dünnebeil wrote:
>> 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
>
--
Eric Lemoine
Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex
Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com
More information about the Users
mailing list