From c18f6a23be048381a8da8084f2ec49a24d7e496d Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sat, 25 Feb 2012 20:18:23 -0700 Subject: [PATCH] Use JSON format for parsing JSON. To get IE7 support, the OpenLayers.Format.JSON parser should be used. This leverages the native JSON.parse method where available. It does add extra weight to UTFGrid builds. However, as of this commit date, we lose large portions of US govt agencies when we exclude IE7. --- lib/OpenLayers/Tile/UTFGrid.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Tile/UTFGrid.js b/lib/OpenLayers/Tile/UTFGrid.js index ab057e276f..1dc66454d0 100644 --- a/lib/OpenLayers/Tile/UTFGrid.js +++ b/lib/OpenLayers/Tile/UTFGrid.js @@ -6,6 +6,7 @@ /** * @requires OpenLayers/Tile.js + * @requires OpenLayers/Format/JSON.js */ /** @@ -37,6 +38,14 @@ OpenLayers.Tile.UTFGrid = OpenLayers.Class(OpenLayers.Tile, { * Stores the parsed JSON tile data structure. */ json: null, + + /** + * Property: format + * {OpenLayers.Format.JSON} + * Parser instance used to parse JSON for cross browser support. The native + * JSON.parse method will be used where available (all except IE<8). + */ + format: null, /** * Constructor: OpenLayers.Tile.UTFGrid @@ -114,8 +123,10 @@ OpenLayers.Tile.UTFGrid = OpenLayers.Class(OpenLayers.Tile, { */ parseData: function(req) { if (req.status == 200) { - var text = req.responseText; - this.json = JSON.parse(text); + if (!this.format) { + this.format = new OpenLayers.Format.JSON(); + } + this.json = this.format.read(req.responseText); } },