Get your own customer support community
 

[Tutorial] - Using WMS Map Provider with ModestMaps (epsg:4236 and epsg:900913).

There has been many people here trying to implement a WMS provider (including me ^^) and i finally worked it out using MM map providers so i thought i would share it.
First of all, download the Modest Map library from SVN, not the SWC from the home page, its much much better :).
Then create a new class exactly like OpenStreetMapProvider (same signatures, same imports, same methods) and add two member variables:
private var serverUrl:String = "http://maps.geog.umd.edu/wmsconnector/com.esri.wms.Esrimap";
private var wms:String = "?LAYERS=0,1&FORMAT=image%2Fpng&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&SRS=EPSG:4326&WIDTH=256&HEIGHT=256&PORT=1200&BBOX=";
if you are using a 4236 projection, add a different projection to your constructor:
var t:Transformation = new Transformation(166886.05360752725, 0, 524288,
0, -166886.05360752725, 524288);
__projection = new LinearProjection(20, t);
If you are using a 900913 projection, don't change anything it should be working fine as google mercator is the basic projection in MM.
For the getTileUrls method, write:

public function getTileUrls(coord:Coordinate):Array
{
var boundingBox:String = "";
var sourceCoord:Coordinate = sourceCoordinate(coord);
var leftBottomCoord:Location = coordinateLocation(coord.down());
var topRightCoord:Location = coordinateLocation(coord.right());
boundingBox = leftBottomCoord.toWMSString()+ "," + topRightCoord.toWMSString();
trace ("boundingBox: "+serverUrl + wms + boundingBox);

return [serverUrl + wms + boundingBox];
}

And in Location.as, add the following method (its just to invert lat/lon in a clean way):

public function toWMSString(precision:int=5):String
{
return [lon.toFixed(precision), lat.toFixed(precision)].join(',');
}

I work with Flex Builder but you can easily adapt this. Create an ActionScript Project, copy the library and add your provider (i called it TestWMSProvider).
In your main application file, just put:

package {
import com.modestmaps.Map;
import com.modestmaps.TweenMap;
import com.modestmaps.extras.MapControls;
import com.modestmaps.mapproviders.TestWMSProvider;

import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;

public class TutorialWMSModestMap extends Sprite
{
public var map:Map;

public function TutorialWMSModestMap()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
map = new TweenMap(stage.stageWidth, stage.stageHeight, true, new TestWMSProvider());
addChild(map);
addChild(new MapControls(map));
}
}
}


And this is what you will get !


I also worked out how to load some TileCache (local profile) with any projection (inc. not 4236 and 900913) but it's very specific and still a bit bugged ^^

Hope this helps!
 
happy I’m happy
Inappropriate?
3 people like this idea

The company implemented this idea.


User_default_medium