Get your own customer support community
 

simple, working WMS overlays (over commerical mapproviders)

hi, i've seen there are a number of questions on how to get WMS working. i've just got a simple means of doing so.

i've posted the code to do this here:
http://pastebin.ca/915930

it just sends an extra argument to YahooHybridMapProvider() that is the url:String of the WMS request except for the BBOX which is added as each tile is requested.
the projection should be in EPSG 54004 or 900913. to use lat/lon, one could just remove the toMercator() calls (but it wont line up perfectly).

right now, it's an ugly hack, but i hope if i post it, someone will clean it up (and share).
there's a live example here:
http://128.32.8.100/SOD/static/Modest...
where the green is a WMS layer of california parks.

the math is copied from john deck
http://johndeck.blogspot.com/2005/09/...

the gist of it is here:

#
private function toMercator(loc:Location):Location {
#

#
var sma:Number = 6378137.0;
#
var ecc:Number = 0.0818191913108718138;
#

#
var x:Number = loc.lon * sma * Math.PI / 180.;
#
var y:Number = loc.lat > 89.5 ? 89.5 :
#
(loc.lat < -89.5 ? -89.5 : loc.lat)
#
y *= Math.PI / 180.;
#
var l:Number = ecc * Math.sin(y);
#

#
y = sma * Math.log(Math.tan((y + Math.PI / 2 ) / 2) * Math.pow( ((1 - l) / (1 + l)) , (ecc/2)));
#
return new Location(y, x);
#

#
}
#

#

#
private function getWMSTileUrl(coord:Coordinate):String
#
{
#
var row:int = coord.row;
#

#
var up_left:Location = toMercator(coordinateLocation(sourceCoordinate(new Coordinate(row, coord.column, coord.zoom))));
#

#
var down_right:Location = toMercator(coordinateLocation(sourceCoordinate(new Coordinate(row + 1, coord.column + 1, coord.zoom))));
#

#
return __url + up_left.lon.toString() + "," + down_right.lat.toString() + ","
#
+ down_right.lon.toString() + "," + up_left.lat.toString();
#

#
}

-brent
Inappropriate?
1 person likes this idea

User_default_medium