From 949693250ef5492352986ecd7cbc151ea5acf3e6 Mon Sep 17 00:00:00 2001 From: fdesj Date: Wed, 7 Aug 2013 11:09:40 -0400 Subject: [PATCH 01/18] added utfgridwms support --- lib/OpenLayers/Layer/UTFGridWMS.js | 276 +++++++++++++++++++++++++++++ 1 file changed, 276 insertions(+) create mode 100644 lib/OpenLayers/Layer/UTFGridWMS.js diff --git a/lib/OpenLayers/Layer/UTFGridWMS.js b/lib/OpenLayers/Layer/UTFGridWMS.js new file mode 100644 index 0000000000..5206ad4b03 --- /dev/null +++ b/lib/OpenLayers/Layer/UTFGridWMS.js @@ -0,0 +1,276 @@ +/* Copyright (c) 2006-2012 by OpenLayers Contributors (see authors.txt for + * full list of contributors). Published under the 2-clause BSD license. + * See license.txt in the OpenLayers distribution or repository for the + * full text of the license. */ + + +/** + * @requires OpenLayers/Layer/WMS.js + * @requires OpenLayers/Tile/UTFGrid.js + * @requires OpenLayers/Control/UTFGrid.js + */ + +/** + * Class: OpenLayers.Layer.UTFGridWMS + * This Layer reads from UTFGrid tiled data sources. Since UTFGrids are + * essentially JSON-based ASCII art with attached attributes, they are not + * visibly rendered. In order to use them in the map, you must add a + * control as well. This version use a WMS + * instead of a tiled map. + * + * Inherits from: + * - + */ +OpenLayers.Layer.UTFGridWMS = OpenLayers.Class(OpenLayers.Layer.WMS, { + + /** + * Constant: DEFAULT_PARAMS + * {Object} Hashtable of default parameter key/value pairs + */ + DEFAULT_PARAMS: { service: "WMS", + version: "1.1.1", + request: "GetMap", + styles: "", + format: "application/json" + }, + + /** + * APIProperty: isBaseLayer + * {Boolean} Default is false for UTFGridWMS layer + */ + isBaseLayer: false, + + /** + * APIProperty: encodeBBOX + * {Boolean} Should the BBOX commas be encoded? The WMS spec says 'no', + * but some services want it that way. Default false. + */ + encodeBBOX: false, + + /** + * Property: useJSONP + * {Boolean} + * Should we use a JSONP script approach instead of a standard AJAX call? + * + * Set to true for using utfgrids from another server. + * Avoids same-domain policy restrictions. + * Note that this only works if the server accepts + * the callback GET parameter and dynamically + * wraps the returned json in a function call. + * + * Default is false + */ + useJSONP: false, + + /** + * Property: yx + * {Object} Keys in this object are EPSG codes for which the axis order + * is to be reversed (yx instead of xy, LatLon instead of LonLat), with + * true as value. This is only relevant for WMS versions >= 1.3.0, and + * only if yx is not set in for the + * used projection. + */ + yx: {}, + + /** + * Property: tileClass + * {} The tile class to use for this layer. + * Defaults is . + */ + tileClass: OpenLayers.Tile.UTFGrid, + + /** + * Constructor: OpenLayers.Layer.UTFGridWMS + * Create a new UTFGridWMS layer object + * + * Parameters: + * name - {String} A name for the layer + * url - {String} Base url for the WMS + * (e.g. http://wms.jpl.nasa.gov/wms.cgi) + * params - {Object} An object with key/value pairs representing the + * GetMap query string parameters and parameter values. + * options - {Object} Hashtable of extra options to tag onto the layer. + * These options include all properties listed above, plus the ones + * inherited from superclasses. + */ + initialize: function(name, url, params, options) { + var newArguments = []; + //uppercase params + params = OpenLayers.Util.upperCaseObject(params); + if (parseFloat(params.VERSION) >= 1.3 && !params.EXCEPTIONS) { + params.EXCEPTIONS = "INIMAGE"; + } + newArguments.push(name, url, params, options); + OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments); + OpenLayers.Util.applyDefaults(this.params, OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS)); + + this.tileOptions = OpenLayers.Util.extend({ + utfgridResolution: this.utfgridResolution + }, this.tileOptions); + }, + + /** + * Method: clone + * Create a clone of this layer + * + * Returns: + * {} An exact clone of this layer + */ + clone: function (obj) { + + if (obj == null) { + obj = new OpenLayers.Layer.WMS(this.name, + this.url, + this.params, + this.getOptions()); + } + + //get all additions from superclasses + obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); + + // copy/set any non-init, non-simple values here + + return obj; + }, + + /** + * APIMethod: reverseAxisOrder + * Returns true if the axis order is reversed for the WMS version and + * projection of the layer. + * + * Returns: + * {Boolean} true if the axis order is reversed, false otherwise. + */ + reverseAxisOrder: function() { + var projCode = this.projection.getCode(); + return parseFloat(this.params.VERSION) >= 1.3 && + !!(this.yx[projCode] || OpenLayers.Projection.defaults[projCode].yx); + }, + + /** + * Method: getURL + * Return a GetMap query string for this layer + * + * Parameters: + * bounds - {} A bounds representing the bbox for the + * request. + * + * Returns: + * {String} A string with the layer's url and parameters and also the + * passed-in bounds and appropriate tile size specified as + * parameters. + */ + getURL: function (bounds) { + bounds = this.adjustBounds(bounds); + + var imageSize = this.getImageSize(); + var newParams = {}; + // WMS 1.3 introduced axis order + var reverseAxisOrder = this.reverseAxisOrder(); + newParams.BBOX = this.encodeBBOX ? + bounds.toBBOX(null, reverseAxisOrder) : + bounds.toArray(reverseAxisOrder); + newParams.WIDTH = imageSize.w; + newParams.HEIGHT = imageSize.h; + var requestString = this.getFullRequestString(newParams); + return requestString; + }, + + /** + * APIMethod: mergeNewParams + * Catch changeParams and uppercase the new params to be merged in + * before calling changeParams on the super class. + * + * Once params have been changed, the tiles will be reloaded with + * the new parameters. + * + * Parameters: + * newParams - {Object} Hashtable of new params to use + */ + mergeNewParams:function(newParams) { + var upperParams = OpenLayers.Util.upperCaseObject(newParams); + var newArguments = [upperParams]; + return OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this, + newArguments); + }, + + /** + * APIMethod: getFullRequestString + * Combine the layer's url with its params and these newParams. + * + * Add the SRS parameter from projection -- this is probably + * more eloquently done via a setProjection() method, but this + * works for now and always. + * + * Parameters: + * newParams - {Object} + * altUrl - {String} Use this as the url instead of the layer's url + * + * Returns: + * {String} + */ + getFullRequestString:function(newParams, altUrl) { + var mapProjection = this.map.getProjectionObject(); + var projectionCode = this.projection && this.projection.equals(mapProjection) ? + this.projection.getCode() : + mapProjection.getCode(); + var value = (projectionCode == "none") ? null : projectionCode; + if (parseFloat(this.params.VERSION) >= 1.3) { + this.params.CRS = value; + } else { + this.params.SRS = value; + } + + if (typeof this.params.TRANSPARENT == "boolean") { + newParams.TRANSPARENT = this.params.TRANSPARENT ? "TRUE" : "FALSE"; + } + + return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply( + this, arguments); + }, + + /** + * APIProperty: getFeatureInfo + * Get details about a feature associated with a map location. The object + * returned will have id and data properties. If the given location + * doesn't correspond to a feature, null will be returned. + * + * Parameters: + * location - {} map location + * + * Returns: + * {Object} Object representing the feature id and UTFGrid data + * corresponding to the given map location. Returns null if the given + * location doesn't hit a feature. + */ + getFeatureInfo: function(location) { + var info = null; + var tileInfo = this.getTileData(location); + if (tileInfo.tile) { + info = tileInfo.tile.getFeatureInfo(tileInfo.i, tileInfo.j); + } + return info; + }, + + /** + * APIMethod: getFeatureId + * Get the identifier for the feature associated with a map location. + * + * Parameters: + * location - {} map location + * + * Returns: + * {String} The feature identifier corresponding to the given map location. + * Returns null if the location doesn't hit a feature. + */ + getFeatureId: function(location) { + var id = null; + var info = this.getTileData(location); + if (info.tile) { + id = info.tile.getFeatureId(info.i, info.j); + } + return id; + }, + + CLASS_NAME: "OpenLayers.Layer.UTFGridWMS" +}); From 5a885f19734437d8cfd3a490a5cd3d9ffe865e31 Mon Sep 17 00:00:00 2001 From: fdesj Date: Wed, 7 Aug 2013 11:43:34 -0400 Subject: [PATCH 02/18] added example --- examples/utfgridwms.html | 114 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 examples/utfgridwms.html diff --git a/examples/utfgridwms.html b/examples/utfgridwms.html new file mode 100644 index 0000000000..bfe1504fcb --- /dev/null +++ b/examples/utfgridwms.html @@ -0,0 +1,114 @@ + + + + + + + + + + + + +

WMS UTFGrid with MapServer

+ +
+ wms, layer, singletile +
+

+ Mapserver and UTFGrid in WMS mode. +

+ +
+
    +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
+
+

 

+

Completly working and fully functional version of the UTFGrid renderer with MapServer. It allows request with WMS and getMap. This is the version that will come with MapServer. If you want to test it, you can get the MapServer version of it on my Git in the utfgridgsoc branch (github.com/fdesj/mapserver). It isn't on the official release yet. It uses a modified version of OpenLayers 2 because I had to create a support for UTFGrid and WMSrequests.

+
+ + \ No newline at end of file From 1f92cbdc67437e1534b55cd2eb883d49c750ea3d Mon Sep 17 00:00:00 2001 From: fdesj Date: Wed, 7 Aug 2013 11:55:44 -0400 Subject: [PATCH 03/18] changed map path --- examples/utfgridwms.html | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/utfgridwms.html b/examples/utfgridwms.html index bfe1504fcb..9d2c48e61b 100644 --- a/examples/utfgridwms.html +++ b/examples/utfgridwms.html @@ -16,20 +16,19 @@ function init(){ var map = new OpenLayers.Map( 'map' ); var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", - "http://localhost/cgi-bin/mapserv-dev?map=/Users/Frank/nemapfile/nemapfile.map&", {layers: 'basic,points'}, {isBaseLayer:true, singleTile:false} ); + "http://msgsoc.mapgears.com/cgi-bin/mapserv.cgi?map=/home/fdesjarlais/nemapfile/nemapfile.map&", {layers: 'basic,points'}, {isBaseLayer:true, singleTile:false} ); map.addLayer(layer); var layer2 = new OpenLayers.Layer.UTFGridWMS( "Utfgrid", - "http://localhost/cgi-bin/mapserv-dev?map=/Users/Frank/nemapfile/nemapfile.map&", {layers: 'basic'}, {utfgridResolution: 4, singleTile:false} ); + "http://msgsoc.mapgears.com/cgi-bin/mapserv.cgi?map=/home/fdesjarlais/nemapfile/nemapfile.map&", {layers: 'basic'}, {utfgridResolution: 4, singleTile:false} ); map.addLayer(layer2); var layer3 = new OpenLayers.Layer.UTFGridWMS( "Utfgrid", - "http://localhost/cgi-bin/mapserv-dev?map=/Users/Frank/nemapfile/nemapfile.map&", {layers: 'points'}, {utfgridResolution: 4, singleTile:false} ); + "http://msgsoc.mapgears.com/cgi-bin/mapserv.cgi?map=/home/fdesjarlais/nemapfile/nemapfile.map&", {layers: 'points'}, {utfgridResolution: 4, singleTile:false} ); map.addLayer(layer3); map.setCenter(new OpenLayers.LonLat(lon, lat), zoom); map.addControls([new OpenLayers.Control.LayerSwitcher(),new OpenLayers.Control.Scale(), new OpenLayers.Control.MousePosition()]); callback = function(infoLookup) { var msg = ""; - // console.log(infoLookup); if (infoLookup) { var layer, info; for (var idx in infoLookup) { From 334f3fe8147a6c66bc0ec8a83ea4a836006b13f2 Mon Sep 17 00:00:00 2001 From: fdesj Date: Wed, 7 Aug 2013 11:58:44 -0400 Subject: [PATCH 04/18] changed lib path and text --- examples/utfgridwms.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/utfgridwms.html b/examples/utfgridwms.html index 9d2c48e61b..c5bbffe5f1 100644 --- a/examples/utfgridwms.html +++ b/examples/utfgridwms.html @@ -6,7 +6,7 @@ - + -

WMS UTFGrid with MapServer

+

OpenLayers UTFGridWMS Demo

wms, layer, singletile

- Mapserver and UTFGrid in WMS mode. + This page demonstrates the use of the OpenLayers UTFGridWMS.

@@ -108,7 +108,7 @@

WMS UTFGrid with MapServer

 

-

UTFGridWMS generated with MapServer. If you want to test it, you can get the MapServer version of it on my Git in the utfgridgsoc branch (github.com/fdesj/mapserver). It isn't on the official release yet.

+

This exemple demostrates the use of UTFGridWMS. It allows high interaction maps with WMS. It can be used with the same functionalities that UTFGrid has.

\ No newline at end of file From 38714bceaa88cb66e2a072645379097af420a325 Mon Sep 17 00:00:00 2001 From: fdesj Date: Mon, 12 Aug 2013 18:39:45 +0400 Subject: [PATCH 18/18] removed console.log --- examples/utfgridwms.html | 9 ++++----- lib/OpenLayers/Layer/UTFGridWMS.js | 1 - 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/examples/utfgridwms.html b/examples/utfgridwms.html index 2055e4082c..23781c43a6 100644 --- a/examples/utfgridwms.html +++ b/examples/utfgridwms.html @@ -17,20 +17,19 @@ init = function(){ var map = new OpenLayers.Map( 'map' ); var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", - "http://msgsoc.mapgears.com/cgi-bin/mapserv.cgi?map=/home/fdesjarlais/nemapfile/nemapfile.map&", {layers: 'basic,points'}, {isBaseLayer:true, singleTile:false} ); + "http://msgsoc.mapgears.com/cgi-bin/mapserv.cgi?map=/home/fdesjarlais/nemapfile/nemapfile.map&", {layers: 'basic,points'}, {isBaseLayer:true, singleTile:true} ); map.addLayer(layer); var layer2 = new OpenLayers.Layer.UTFGridWMS( "Utfgrid", - "http://msgsoc.mapgears.com/cgi-bin/mapserv.cgi?map=/home/fdesjarlais/nemapfile/nemapfile.map&", {layers: 'basic'}, {utfgridResolution: 4, singleTile:false} ); + "http://msgsoc.mapgears.com/cgi-bin/mapserv.cgi?map=/home/fdesjarlais/nemapfile/nemapfile.map&", {layers: 'basic'}, {utfgridResolution: 4, singleTile:true} ); map.addLayer(layer2); var layer3 = new OpenLayers.Layer.UTFGridWMS( "Utfgrid", - "http://msgsoc.mapgears.com/cgi-bin/mapserv.cgi?map=/home/fdesjarlais/nemapfile/nemapfile.map&", {layers: 'points'}, {utfgridResolution: 4, singleTile:false} ); + "http://msgsoc.mapgears.com/cgi-bin/mapserv.cgi?map=/home/fdesjarlais/nemapfile/nemapfile.map&", {layers: 'points'}, {utfgridResolution: 4, singleTile:true} ); map.addLayer(layer3); map.setCenter(new OpenLayers.LonLat(lon, lat), zoom); map.addControls([new OpenLayers.Control.Scale(), new OpenLayers.Control.MousePosition()]); callback = function(infoLookup) { var msg = ""; - console.log(infoLookup) if (infoLookup) { var layer, info; for (var idx in infoLookup) { @@ -111,4 +110,4 @@

OpenLayers UTFGridWMS Demo

This exemple demostrates the use of UTFGridWMS. It allows high interaction maps with WMS. It can be used with the same functionalities that UTFGrid has.

- \ No newline at end of file + diff --git a/lib/OpenLayers/Layer/UTFGridWMS.js b/lib/OpenLayers/Layer/UTFGridWMS.js index 438956f294..85418af09e 100644 --- a/lib/OpenLayers/Layer/UTFGridWMS.js +++ b/lib/OpenLayers/Layer/UTFGridWMS.js @@ -166,7 +166,6 @@ OpenLayers.Layer.UTFGridWMS = OpenLayers.Class(OpenLayers.Layer.WMS, { getURL: function (bounds) { bounds = this.adjustBounds(bounds); var imageSize = this.getImageSize(bounds); - console.log(imageSize); var newParams = {}; // WMS 1.3 introduced axis order var reverseAxisOrder = this.reverseAxisOrder();