Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented support for UTFGrid using the WMS protocol. #1486

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/proxy.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ allowedHosts = ['www.openlayers.org', 'openlayers.org',
'www.openstreetmap.org', 'sample.azavea.com',
'v2.suite.opengeo.org', 'v-swe.uni-muenster.de:8080',
'vmap0.tiles.osgeo.org', 'www.openrouteservice.org',
'maps.wien.gv.at']
'maps.wien.gv.at','demo.geo-solutions.it']

method = os.environ["REQUEST_METHOD"]

Expand Down
114 changes: 114 additions & 0 deletions examples/utfgridwms.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="stylesheet" href="../theme/default/style.css" type="text/css">
<link rel="stylesheet" href="style.css" type="text/css">
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
var control, callback;
// UTF grid use httprequest you could need a proxy or other fix for CORS
//OpenLayers.ProxyHost = "./proxy.cgi?url=";

init = function() {
var world = new OpenLayers.Bounds(
-20037508.34, -20037508.34, 20037508.34, 20037508.34
);
var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://demo.geo-solutions.it/geoserver/topp/wms?", {layers: 'topp:states'}, {isBaseLayer:true, singleTile:true} );
var utfGridWMSLayer = new OpenLayers.Layer.UTFGridWMS( "Utfgrid",
"http://demo.geo-solutions.it/geoserver/topp/wms?", {format:"application/json;type=utfgrid",layers: 'topp:states'}, {utfgridResolution: 4, singleTile:true} );
var utfGridWMTSLayer = new OpenLayers.Layer.UTFGrid({
url: "http://demo.geo-solutions.it/geoserver/gwc/service/wmts/?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=topp:states&STYLE=_null&TILEMATRIXSET=EPSG:900913&TILEMATRIX=EPSG:900913:${z}&TILEROW=${y}&TILECOL=${x}&FORMAT=application/json;type=utfgrid",
utfgridResolution: 4
});

var map = new OpenLayers.Map({
div: "map",
projection: "EPSG:900913",
numZoomLevels: 18,
maxResolution: world.getWidth() / 256, // world two tiles wide
//maxExtent: world,
//restrictedExtent: world,
controls: [new OpenLayers.Control.Navigation(),new OpenLayers.Control.Zoom(),new OpenLayers.Control.Scale(), new OpenLayers.Control.MousePosition()],
layers: [layer,utfGridWMSLayer,utfGridWMTSLayer],
center: new OpenLayers.LonLat(-11500000, 4700000),
zoom: 0

});

callback = function(infoLookup) {
var msg = "";
if (infoLookup) {
var layer, info;
for (var idx in infoLookup) {
layer = map.layers[idx];
info = infoLookup[idx];
if (info && info.data) {
msg += "Feature ID: " + info.id + "<br>";
for (var key in info.data) {
msg += key + ": " + info.data[key] + "<br>";
}
}
}
}
document.getElementById("attrs").innerHTML = msg;
};

var controls = {
utf_wms: new OpenLayers.Control.UTFGrid({
callback: callback,
layers: [utfGridWMSLayer],
handlerMode: "move"
}),
utf_wmts: new OpenLayers.Control.UTFGrid({
callback: callback,
layers: [utfGridWMTSLayer],
handlerMode: "move"
})
};
for (var key in controls) {
map.addControl(controls[key]);
}

toggleControl = function(el) {
for (var c in controls) {
controls[c].deactivate();
}
controls[el.value].activate();
}
toggleControl({value: "utf_wms"});
}
</script>
</head>
<body onload="init()">
<h1 id="title">OpenLayers UTFGridWMS Demo</h1>

<div id="tags">
wms, layer, singletile
</div>
<p id="shortdesc">
This page demonstrates the use of the OpenLayers UTFGridWMS.
</p>

<div id="map" class="smallmap"></div>
<ul id="controlToggle">
<li>
<input type="radio" name="type" value="utf_wms" id="wmsHandler"
onclick="toggleControl(this);" checked="checked" />
<label for="wmsHandler">UTF GRID WMS</label>
</li>
<li>
<input type="radio" name="type" value="utf_wmts" id="wmtsHandler"
onclick="toggleControl(this);" />
<label for="wmtsHandler">UTF GRID using WMTS</label>
</li>
</ul>
<div id="docs">
<p><strong id="attrs">&nbsp;</strong></p>
<p> 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.</p>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions lib/OpenLayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
"OpenLayers/Layer/Boxes.js",
"OpenLayers/Layer/XYZ.js",
"OpenLayers/Layer/UTFGrid.js",
"OpenLayers/Layer/UTFGridWMS.js",
"OpenLayers/Layer/OSM.js",
"OpenLayers/Layer/Bing.js",
"OpenLayers/Layer/TMS.js",
Expand Down
3 changes: 2 additions & 1 deletion lib/OpenLayers/Control/UTFGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ OpenLayers.Control.UTFGrid = OpenLayers.Class(OpenLayers.Control, {
var layer;
for (var i=candidates.length-1; i>=0; --i) {
layer = candidates[i];
if (layer instanceof OpenLayers.Layer.UTFGrid ) {
if (layer instanceof OpenLayers.Layer.UTFGrid
|| layer instanceof OpenLayers.Layer.UTFGridWMS ) {
layers.push(layer);
}
}
Expand Down
129 changes: 129 additions & 0 deletions lib/OpenLayers/Layer/UTFGridWMS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/* 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 WMS 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
* <OpenLayers.Control.UTFGrid> control as well
*
* Inherits from:
* - <OpenLayers.Layer.WMS>
*/
OpenLayers.Layer.UTFGridWMS = OpenLayers.Class(OpenLayers.Layer.WMS, {

/**
* APIProperty: isBaseLayer
* {Boolean} Default is false for UTFGridWMS layer
*/
isBaseLayer: 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: tileClass
* {<OpenLayers.Tile>} The tile class to use for this layer.
* Defaults is <OpenLayers.Tile.UTFGrid>.
*/
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) {

this.DEFAULT_PARAMS.format= "application/json";

OpenLayers.Layer.WMS.prototype.initialize.apply(this, arguments);


this.tileOptions = OpenLayers.Util.extend({
utfgridResolution: this.utfgridResolution
}, this.tileOptions);
},

/**
* Method: createBackBuffer
* The UTFGrid cannot create a back buffer, so this method is overriden.
*/
createBackBuffer: function() {},

/**
* 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 - {<OpenLayers.LonLat>} 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 && 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 - {<OpenLayers.LonLat>} 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"
});