[Tilecache] Why is the bounding box/resolution from the original
request not honored?
chris marx
chrismarx at gmail.com
Sun Nov 9 12:36:09 EST 2008
Hi,
I just got tilecache working on xp and win 2003, and with my wms (using
manifold gis) the open layers example works great. However, I configured
tilecache in the hopes of using it in conjunction with google maps. However,
it appears that tilecache is not honoring the wms requests that are being
generated from the script in google maps (see below). The requests are
valid, if I point the script directly at the wms, the tiles come back just
fine. But when i put tilecache in between, I get
An error occurred: Current y value 37.718590 is too far from tile
corner y 37.968750
You can see the working google map with tiles coming back directly from the
wms here:
http://warbler2.cit.cornell.edu/pfw-maps/wms-without-cache.html
the entry in tilecache.cfg looks like this
[google-tiles]
type=WMS
url=http://mycomputer.com/local-wms/wms.asp
layers=Active_Year_2005
tms_type=google
I use the following script to convert the mercator coords to lat lng, which
i modified from here (http://johndeck.blogspot.com/#114071052432996324)
/**
* GoogleMapsWmsOverlays
* @param {Object} opts
* @param {String} myLayers The layers requested from wms
* @param {String} myFormat The image format
* @param {String} myBaseURL The url of the wms server
* @param {Number} myOpacity opacity
* @param {String} myStyles wms styles
* @param {Number} myMercLevel The level at which switch to lat/lng is
made??
*/
function GoogleMapsWmsOverlay(opts){
var me = this;
me.MAGIC_NUMBER=6356752.3142;
me.WGS84_SEMI_MAJOR_AXIS = 6378137.0;
me.WGS84_ECCENTRICITY = 0.0818191913108718138;
me.DEG2RAD=0.0174532922519943;
me.PI=3.14159267;
me.FORMAT_DEFAULT="image/png"; //Default image format, used if none is
specified
me.MERC_ZOOM_DEFAULT = 15; //Google Maps Zoom level at which we switch
from Mercator to Lat/Long.
me.Options = {
myLayers: opts.myLayers || "error",
myFormat: opts.myFormat || me.FORMAT_DEFAULT,
myBaseURL: opts.myBaseURL || "error",
myStyles: opts.myStyles || ""
}
}
GoogleMapsWmsOverlay.prototype.dd2MercMetersLng = function(p_lng) {
var me = this;
return me.WGS84_SEMI_MAJOR_AXIS * (p_lng * me.DEG2RAD);
}
GoogleMapsWmsOverlay.prototype.dd2MercMetersLat = function(p_lat) {
var me = this;
var lat_rad = p_lat * me.DEG2RAD;
return me.WGS84_SEMI_MAJOR_AXIS *
Math.log(Math.tan((lat_rad + me.PI / 2) / 2) *
Math.pow( ((1 - me.WGS84_ECCENTRICITY *
Math.sin(lat_rad)) /
(1 + me.WGS84_ECCENTRICITY *
Math.sin(lat_rad))), (me.WGS84_ECCENTRICITY/2)));
}
/**
* use?
*/
GoogleMapsWmsOverlay.prototype.customOpacity = function() {
return this.myOpacity;
}
GoogleMapsWmsOverlay.prototype.customGetTileUrl = function(a,b,c) {
var opts = this.Options;
/*if (opts.myMercZoomLevel == undefined) {
opts.myMercZoomLevel = MERC_ZOOM_DEFAULT;
}*/
var lULP = new GPoint(a.x*256,(a.y+1)*256);
var lLRP = new GPoint((a.x+1)*256,a.y*256);
var lUL = G_NORMAL_MAP.getProjection().fromPixelToLatLng(lULP,b,c);
var lLR = G_NORMAL_MAP.getProjection().fromPixelToLatLng(lLRP,b,c);
// switch between Mercator and DD if merczoomlevel is set
// NOTE -it is now safe to use Mercator exclusively for all zoom levels
(if your WMS supports it)
// so you can just use the two lines of code below the IF (& delete the
ELSE)
// drg & doq are topozone layers--- they don't work with epsg:54004
/*if (opt.myLayers!="drg" && opt.myLayers!="doq") {
var
lBbox=dd2MercMetersLng(lUL.x)+","+dd2MercMetersLat(lUL.y)+","+dd2MercMetersLng(lLR.x)+","+dd2MercMetersLat(lLR.y);
//Change for GeoServer - 41001 is mercator and installed by default.
var lSRS="EPSG:54004";
} else {*/
//var
lBbox=lUL.x.toFixed(6)+","+lUL.y.toFixed(6)+","+lLR.x.toFixed(6)+","+lLR.y.toFixed(6);
var lBbox=lUL.x+","+lUL.y+","+lLR.x+","+lLR.y;
var lSRS="EPSG:4326";
//}
var lURL=opts.myBaseURL;
lURL+="?REQUEST=GetMap";
lURL+="&SERVICE=WMS";
lURL+="&VERSION=1.1.1";
lURL+="&EXCEPTIONS=application/vnd.ogc.se_inimage";
lURL+="&LAYERS="+opts.myLayers;
lURL+="&STYLES="+opts.myStyles;
lURL+="&FORMAT="+opts.myFormat;
lURL+="&BGCOLOR=0xFFFFFF";
lURL+="&TRANSPARENT=TRUE";
lURL+="&SRS="+lSRS; //use CRS for v1.3.0
lURL+="&BBOX="+lBbox;
lURL+="&WIDTH=256";
lURL+="&HEIGHT=256";
//lURL+="&reaspect=false";
//document.write(lURL + "<br/>")
//alert(" url is " + lURL);
return lURL;
}
GoogleMapsWmsOverlay.prototype.getTileLayer = function(){
var me = this;
var tileLayer = new GTileLayer(new GCopyrightCollection(""), 0, 17);
tileLayer.Options = me.Options;
tileLayer.getTileUrl = me.customGetTileUrl;
return tileLayer;
}
My maps in manifold are in mercator, but it has no problem accpeting the
lat/lng requests, and spitting back the correct mercator tiles. Any help
would be greatly appreciated!
chris-
--
Chris Marx
Programmer/Analyst
Cornell Lab of Ornithology
159 Sapsucker Woods Rd.
Ithaca, NY 14850
t. 1.607.254.1142
http://www.birds.cornell.edu/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/tilecache/attachments/20081109/21883c59/attachment.html
More information about the Tilecache
mailing list