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:
crschmidt
2009-03-11 06:15:30 +00:00
parent 612e95793c
commit 718495bcec
2 changed files with 131 additions and 20 deletions

View File

@@ -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