Add Mapguide Layer http served tile support. Patch from madair, positive
comments on usage from community members, r=me. (Closes #1622) git-svn-id: http://svn.openlayers.org/trunk/openlayers@9004 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -39,19 +39,17 @@
|
||||
//tiled version
|
||||
function initTiled(){
|
||||
|
||||
var extent = new OpenLayers.Bounds(-3631568.75,-1293815.5,4491139.5833333321,4937122);
|
||||
var tempScales = [50000000,23207944.16806,10772173.45016,5000000,2320794.41681,1077217.34502,500000,232079.44168,107721.7345,50000];
|
||||
var extent = new OpenLayers.Bounds(-87.764987,43.691398,-87.695522,43.797520);
|
||||
var tempScales = [100000,51794.74679,26826.95795,13894.95494,7196.85673,3727.59372,1930.69773,1000];
|
||||
var mapOptions = {
|
||||
maxExtent: extent,
|
||||
scales: tempScales,
|
||||
units: 'm',
|
||||
projection: 'EPSG:42304'
|
||||
scales: tempScales
|
||||
};
|
||||
map = new OpenLayers.Map( 'map', mapOptions );
|
||||
|
||||
var params = {
|
||||
mapdefinition: 'Library://Samples/Gmap/Maps/gmapTiled.MapDefinition',
|
||||
basemaplayergroupname: "BaseLayerGroup"
|
||||
mapdefinition: 'Library://Samples/Sheboygan/MapsTiled/Sheboygan.MapDefinition',
|
||||
basemaplayergroupname: "Base Layer Group"
|
||||
}
|
||||
var options = {
|
||||
singleTile: false
|
||||
@@ -59,6 +57,18 @@
|
||||
var layer = new OpenLayers.Layer.MapGuide( "MapGuide OS tiled layer", url, params, options );
|
||||
map.addLayer(layer);
|
||||
|
||||
/**
|
||||
The following example shows how to access an MG tile cache directly
|
||||
through HTTP bypassing the MG mapagent. This depends on having a
|
||||
pre-populated tile cache
|
||||
*/
|
||||
/*
|
||||
options.useHttpTile = true;
|
||||
var cacheUrl = "http://localhost:8008/sheboygan";
|
||||
var httpLayer = new OpenLayers.Layer.MapGuide( "MapGuide HTTP cache tiled layer", cacheUrl, params, options );
|
||||
map.addLayer(httpLayer);
|
||||
*/
|
||||
|
||||
map.zoomToMaxExtent();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,16 @@ OpenLayers.Layer.MapGuide = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
||||
**/
|
||||
isBaseLayer: true,
|
||||
|
||||
/**
|
||||
* APIProperty: useHttpTile
|
||||
* {Boolean} use a tile cache exposed directly via a webserver rather than the
|
||||
* via mapguide server. This does require extra configuration on the Mapguide Server,
|
||||
* and will only work when singleTile is false. The url for the layer must be set to the
|
||||
* webserver path rather than the Mapguide mapagent.
|
||||
* See http://trac.osgeo.org/mapguide/wiki/CodeSamples/Tiles/ServingTilesViaHttp
|
||||
**/
|
||||
useHttpTile: false,
|
||||
|
||||
/**
|
||||
* APIProperty: singleTile
|
||||
* {Boolean} use tile server or request single tile image. Note that using
|
||||
@@ -53,6 +63,19 @@ OpenLayers.Layer.MapGuide = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
||||
version: '1.0.0'
|
||||
},
|
||||
|
||||
/**
|
||||
* Constant: FOLDER_PARAMS
|
||||
* {Object} Hashtable of parameter key/value pairs which describe
|
||||
* the folder structure for tiles as configured in the mapguide
|
||||
* serverconfig.ini section [TileServiceProperties]
|
||||
*/
|
||||
FOLDER_PARAMS: {
|
||||
tileColumnsPerFolder: 30,
|
||||
tileRowsPerFolder: 30,
|
||||
format: 'png',
|
||||
querystring: null
|
||||
},
|
||||
|
||||
/**
|
||||
* Property: defaultSize
|
||||
* {<OpenLayers.Size>} Tile size as produced by MapGuide server
|
||||
@@ -130,10 +153,17 @@ OpenLayers.Layer.MapGuide = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
||||
|
||||
} else {
|
||||
//initialize for tiled layers
|
||||
OpenLayers.Util.applyDefaults(
|
||||
this.params,
|
||||
this.TILE_PARAMS
|
||||
);
|
||||
if (this.useHttpTile) {
|
||||
OpenLayers.Util.applyDefaults(
|
||||
this.params,
|
||||
this.FOLDER_PARAMS
|
||||
);
|
||||
} else {
|
||||
OpenLayers.Util.applyDefaults(
|
||||
this.params,
|
||||
this.TILE_PARAMS
|
||||
);
|
||||
}
|
||||
this.setTileSize(this.defaultSize);
|
||||
}
|
||||
},
|
||||
@@ -230,15 +260,24 @@ OpenLayers.Layer.MapGuide = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
||||
var rowidx = Math.floor((this.maxExtent.top-bounds.top)/currentRes);
|
||||
rowidx = Math.round(rowidx/this.tileSize.h);
|
||||
|
||||
url = this.getFullRequestString(
|
||||
{
|
||||
tilecol: colidx,
|
||||
tilerow: rowidx,
|
||||
scaleindex: this.resolutions.length - this.map.zoom - 1
|
||||
});
|
||||
}
|
||||
|
||||
return url;
|
||||
if (this.useHttpTile){
|
||||
url = this.getImageFilePath(
|
||||
{
|
||||
tilecol: colidx,
|
||||
tilerow: rowidx,
|
||||
scaleindex: this.resolutions.length - this.map.zoom - 1
|
||||
});
|
||||
|
||||
} else {
|
||||
url = this.getFullRequestString(
|
||||
{
|
||||
tilecol: colidx,
|
||||
tilerow: rowidx,
|
||||
scaleindex: this.resolutions.length - this.map.zoom - 1
|
||||
});
|
||||
}
|
||||
}
|
||||
return url;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -305,6 +344,68 @@ OpenLayers.Layer.MapGuide = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
||||
return requestString;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: getImageFilePath
|
||||
* special handler to request mapguide tiles from an http exposed tilecache
|
||||
*
|
||||
* Parameters:
|
||||
* altUrl - {String} Alternative base URL to use.
|
||||
*
|
||||
* Returns:
|
||||
* {String} A string with the url for the tile image
|
||||
*/
|
||||
getImageFilePath:function(newParams, altUrl) {
|
||||
// use layer's url unless altUrl passed in
|
||||
var url = (altUrl == null) ? this.url : altUrl;
|
||||
|
||||
// if url is not a string, it should be an array of strings,
|
||||
// in which case we will randomly select one of them in order
|
||||
// to evenly distribute requests to different urls.
|
||||
if (typeof url == "object") {
|
||||
url = url[Math.floor(Math.random()*url.length)];
|
||||
}
|
||||
// requestString always starts with url
|
||||
var requestString = url;
|
||||
|
||||
var tileRowGroup = "";
|
||||
var tileColGroup = "";
|
||||
|
||||
if (newParams.tilerow < 0) {
|
||||
tileRowGroup = '-';
|
||||
}
|
||||
|
||||
if (newParams.tilerow == 0 ) {
|
||||
tileRowGroup += '0';
|
||||
} else {
|
||||
tileRowGroup += Math.floor(Math.abs(newParams.tilerow/this.params.tileRowsPerFolder)) * this.params.tileRowsPerFolder;
|
||||
}
|
||||
|
||||
if (newParams.tilecol < 0) {
|
||||
tileColGroup = '-';
|
||||
}
|
||||
|
||||
if (newParams.tilecol == 0) {
|
||||
tileColGroup += '0';
|
||||
} else {
|
||||
tileColGroup += Math.floor(Math.abs(newParams.tilecol/this.params.tileColumnsPerFolder)) * this.params.tileColumnsPerFolder;
|
||||
}
|
||||
|
||||
var tilePath = '/S' + Math.floor(newParams.scaleindex)
|
||||
+ '/' + this.params.basemaplayergroupname
|
||||
+ '/R' + tileRowGroup
|
||||
+ '/C' + tileColGroup
|
||||
+ '/' + (newParams.tilerow % this.params.tileRowsPerFolder)
|
||||
+ '_' + (newParams.tilecol % this.params.tileColumnsPerFolder)
|
||||
+ '.' + this.params.format;
|
||||
|
||||
if (this.params.querystring) {
|
||||
tilePath += "?" + this.params.querystring;
|
||||
}
|
||||
|
||||
requestString += tilePath;
|
||||
return requestString;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: calculateGridLayout
|
||||
* Generate parameters for the grid layout. This
|
||||
|
||||
Reference in New Issue
Block a user