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
+17 -7
View File
@@ -39,19 +39,17 @@
//tiled version //tiled version
function initTiled(){ function initTiled(){
var extent = new OpenLayers.Bounds(-3631568.75,-1293815.5,4491139.5833333321,4937122); var extent = new OpenLayers.Bounds(-87.764987,43.691398,-87.695522,43.797520);
var tempScales = [50000000,23207944.16806,10772173.45016,5000000,2320794.41681,1077217.34502,500000,232079.44168,107721.7345,50000]; var tempScales = [100000,51794.74679,26826.95795,13894.95494,7196.85673,3727.59372,1930.69773,1000];
var mapOptions = { var mapOptions = {
maxExtent: extent, maxExtent: extent,
scales: tempScales, scales: tempScales
units: 'm',
projection: 'EPSG:42304'
}; };
map = new OpenLayers.Map( 'map', mapOptions ); map = new OpenLayers.Map( 'map', mapOptions );
var params = { var params = {
mapdefinition: 'Library://Samples/Gmap/Maps/gmapTiled.MapDefinition', mapdefinition: 'Library://Samples/Sheboygan/MapsTiled/Sheboygan.MapDefinition',
basemaplayergroupname: "BaseLayerGroup" basemaplayergroupname: "Base Layer Group"
} }
var options = { var options = {
singleTile: false singleTile: false
@@ -59,6 +57,18 @@
var layer = new OpenLayers.Layer.MapGuide( "MapGuide OS tiled layer", url, params, options ); var layer = new OpenLayers.Layer.MapGuide( "MapGuide OS tiled layer", url, params, options );
map.addLayer(layer); 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(); map.zoomToMaxExtent();
} }
+114 -13
View File
@@ -23,6 +23,16 @@ OpenLayers.Layer.MapGuide = OpenLayers.Class(OpenLayers.Layer.Grid, {
**/ **/
isBaseLayer: true, 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 * APIProperty: singleTile
* {Boolean} use tile server or request single tile image. Note that using * {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' 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 * Property: defaultSize
* {<OpenLayers.Size>} Tile size as produced by MapGuide server * {<OpenLayers.Size>} Tile size as produced by MapGuide server
@@ -130,10 +153,17 @@ OpenLayers.Layer.MapGuide = OpenLayers.Class(OpenLayers.Layer.Grid, {
} else { } else {
//initialize for tiled layers //initialize for tiled layers
OpenLayers.Util.applyDefaults( if (this.useHttpTile) {
this.params, OpenLayers.Util.applyDefaults(
this.TILE_PARAMS this.params,
); this.FOLDER_PARAMS
);
} else {
OpenLayers.Util.applyDefaults(
this.params,
this.TILE_PARAMS
);
}
this.setTileSize(this.defaultSize); 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); var rowidx = Math.floor((this.maxExtent.top-bounds.top)/currentRes);
rowidx = Math.round(rowidx/this.tileSize.h); rowidx = Math.round(rowidx/this.tileSize.h);
url = this.getFullRequestString( if (this.useHttpTile){
{ url = this.getImageFilePath(
tilecol: colidx, {
tilerow: rowidx, tilecol: colidx,
scaleindex: this.resolutions.length - this.map.zoom - 1 tilerow: rowidx,
}); scaleindex: this.resolutions.length - this.map.zoom - 1
} });
return url; } 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; 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 * Method: calculateGridLayout
* Generate parameters for the grid layout. This * Generate parameters for the grid layout. This