Tuesday, September 25, 2007

WMS basemap layer

You can subclass BaseMapLayer to create a WMS basemap layer:

package com.esri.aws.awx.map.layers
import com.esri.aws.awx.geom.Extent;

import flash.geom.Point;
import flash.utils.getTimer;

public class WMSGroupLayer extends BaseMapLayer
public var service : String = "WMS";
public var version : String = "1.1.1";
public var request : String = "GetMap";
public var format : String = "image/png";
public var wmsLayers : String;
public var serviceName : String;
public var wmtVersion : String;
public var styles : String;
public var srs : String;
public var dataSource:String;
public var proxyURL : String;

public function WMSGroupLayer()
mapOversizeBuffer = 0;

override protected function getMap():void
m_lastMap = buildGeoLoader();

var scalarPt:Point = getScalar();
var width:Number = Math.floor(map.rotatedWidth * scalarPt.x);
var height:Number = Math.floor(map.rotatedHeight * scalarPt.y);

m_lastMap.startTime = getTimer();
m_lastMap.mapHeight = height;
m_lastMap.mapWidth = width;
m_lastMap.center = map.center;
m_lastMap.mapRotation = map.mapRotation;
m_lastMap.scale = map.scale;
m_lastMap.projectionID = map.projectionID;

var extent : Extent = map.extent;

var index : int = dataSource.indexOf( "?");
var prefix : String = index == -1 ? "?" : "&";

var url : String = dataSource;
url += prefix + "SERVICE="+service;
url += "&VERSION="+version;
url += "&REQUEST="+request;
if( serviceName != null)
url += "&SERVICENAME="+serviceName;
if( wmtVersion != null)
url += "&WMTVER="+wmtVersion;
if( wmsLayers != null)
url += "&LAYERS="+wmsLayers;
if( styles != null)
url += "&STYLES="+styles;
if( srs != null)
url += "&SRS="+srs;
url += "&FORMAT="+format;
url += "&WIDTH="+width;
url += "&HEIGHT="+height;
url += "&BBOX="+extent.minX+","+extent.minY+","+extent.maxX+","+extent.maxY;

if( proxyURL != null)
url = proxyURL + "?" + escape( url);

// trace( url );


m_lastMap.load( url);

Here is how you use it in MXML:

<?xml version="1.0" encoding="utf-8"?>
<framework:Framework apiKey="XXXXXX"/>
<map:Map id="map" centerLat="40.708512143644064" centerLon="-74.01304349200724" scale="200000">


Scott said...

That is a very useful class to have.

How would this work with awx and a getmap request for an SRS other than EPSG:4326?

i.e. is it possible to work with a map using a wms baselayer in a projection other than Geographic?

I haven't been able to find much in the way of documentation other than the reference guide regarding projection in the awx flex api.

Great blog by the way, very informative.

buy wow gold said...

When the Wow Gold wolf finally found the Buy Wow Goldhole in the chimney he crawled wow gold cheap down and KERSPLASH right into that kettle of water and that was cheap wow gold the end of his troubles with the big bad wolf.
The next day the cheapest wow gold little pig invited his mother over . She said "You see it is just as mygamegoldI told you. The way to get along in the world is to do world of warcraft gold things as well as you can." Fortunately for that little pig, he buy cheap wow gold learned that lesson. And he just lived happily ever after! wow gold .