Combining ACTransitMapProvider.as overlay with Yahoo etc.
I'm trying to figure out how to add a tiled image (similar to Zoomify, but created using my own image tiler) and overlay it on another map (such as Yahoo).
As a test, I adapted the HelloLayers example to use ACTransitMapProvider.as
I expected the maps to line up, but they don't.
Here's the code, but there's not much modification! I just replaced MicrosoftAerialMapProvider with ACTransitMapProvider
package {
import com.modestmaps.geo.Location;
import com.modestmaps.Map;
import com.modestmaps.mapproviders.ACTransitMapProvider;
import com.modestmaps.TweenMap;
import com.modestmaps.events.MapEvent;
import com.modestmaps.extras.MapControls;
import com.modestmaps.extras.MapCopyright;
import com.modestmaps.extras.ZoomSlider;
import com.modestmaps.mapproviders.microsoft.MicrosoftAerialMapProvider;
import com.modestmaps.mapproviders.yahoo.YahooAerialMapProvider;
import flash.display.BlendMode;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
[SWF(backgroundColor="#000000")]
public class TestZoomify extends Sprite
{
public var map:Map;
public var overlay:Map;
public function TestZoomify()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
map = new TweenMap(stage.stageWidth, stage.stageHeight, true, new ACTransitMapProvider());
map.addEventListener(MouseEvent.DOUBLE_CLICK, map.onDoubleClick);
addChild(map);
overlay = new TweenMap(stage.stageWidth, stage.stageHeight, false, new YahooAerialMapProvider());
overlay.mouseChildren = overlay.mouseEnabled = false; // pass thru to map
addChild(overlay);
// you could adjust the alpha of your overlay here:
//overlay.alpha = 1;
// but I want to see how Microsoft and Yahoo's aerial imagery differs, so:
overlay.blendMode = BlendMode.DIFFERENCE;
// these *should* be all the events you need to watch out for
// fingers crossed!
map.addEventListener(MapEvent.EXTENT_CHANGED, syncMaps);
map.addEventListener(MapEvent.PANNED, syncMaps);
map.addEventListener(MapEvent.ZOOMED_BY, syncMaps);
map.addEventListener(MapEvent.STOP_ZOOMING, syncMaps);
map.addEventListener(MapEvent.STOP_PANNING, syncMaps);
// add these to the stage so they're on top of our overlay too
addChild(new MapControls(map));
// make sure the map fills the screen:
stage.addEventListener(Event.RESIZE, onStageResize);
map.setCenter(new Location(37.810665, -122.262297));
}
private function syncMaps(event:MapEvent=null):void
{
// if you're using TweenMap then you need to
// do this to get the animations synced:
overlay.grid.setMatrix(map.grid.getMatrix());
// if you're using 'Map' you can just do
// overlay.setCenterZoom(map.getCenter(), map.getZoom());
}
private function onStageResize(event:Event):void
{
map.setSize(stage.stageWidth, stage.stageHeight);
overlay.setSize(stage.stageWidth, stage.stageHeight);
syncMaps(); // just to be sure
}
}
}
As a test, I adapted the HelloLayers example to use ACTransitMapProvider.as
I expected the maps to line up, but they don't.
Here's the code, but there's not much modification! I just replaced MicrosoftAerialMapProvider with ACTransitMapProvider
package {
import com.modestmaps.geo.Location;
import com.modestmaps.Map;
import com.modestmaps.mapproviders.ACTransitMapProvider;
import com.modestmaps.TweenMap;
import com.modestmaps.events.MapEvent;
import com.modestmaps.extras.MapControls;
import com.modestmaps.extras.MapCopyright;
import com.modestmaps.extras.ZoomSlider;
import com.modestmaps.mapproviders.microsoft.MicrosoftAerialMapProvider;
import com.modestmaps.mapproviders.yahoo.YahooAerialMapProvider;
import flash.display.BlendMode;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
[SWF(backgroundColor="#000000")]
public class TestZoomify extends Sprite
{
public var map:Map;
public var overlay:Map;
public function TestZoomify()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
map = new TweenMap(stage.stageWidth, stage.stageHeight, true, new ACTransitMapProvider());
map.addEventListener(MouseEvent.DOUBLE_CLICK, map.onDoubleClick);
addChild(map);
overlay = new TweenMap(stage.stageWidth, stage.stageHeight, false, new YahooAerialMapProvider());
overlay.mouseChildren = overlay.mouseEnabled = false; // pass thru to map
addChild(overlay);
// you could adjust the alpha of your overlay here:
//overlay.alpha = 1;
// but I want to see how Microsoft and Yahoo's aerial imagery differs, so:
overlay.blendMode = BlendMode.DIFFERENCE;
// these *should* be all the events you need to watch out for
// fingers crossed!
map.addEventListener(MapEvent.EXTENT_CHANGED, syncMaps);
map.addEventListener(MapEvent.PANNED, syncMaps);
map.addEventListener(MapEvent.ZOOMED_BY, syncMaps);
map.addEventListener(MapEvent.STOP_ZOOMING, syncMaps);
map.addEventListener(MapEvent.STOP_PANNING, syncMaps);
// add these to the stage so they're on top of our overlay too
addChild(new MapControls(map));
// make sure the map fills the screen:
stage.addEventListener(Event.RESIZE, onStageResize);
map.setCenter(new Location(37.810665, -122.262297));
}
private function syncMaps(event:MapEvent=null):void
{
// if you're using TweenMap then you need to
// do this to get the animations synced:
overlay.grid.setMatrix(map.grid.getMatrix());
// if you're using 'Map' you can just do
// overlay.setCenterZoom(map.getCenter(), map.getZoom());
}
private function onStageResize(event:Event):void
{
map.setSize(stage.stageWidth, stage.stageHeight);
overlay.setSize(stage.stageWidth, stage.stageHeight);
syncMaps(); // just to be sure
}
}
}
1
person has this question
I have this question, too!
Tell me when someone answers.
The more people who ask this question, the more it gets noticed.
The more people who ask this question, the more it gets noticed.
Create a customer community for your own organization
Plans starting at $19/month
-
Inappropriate?Hi,
For this to work your two maps will need to have the same projection and zoom levels. Otherwise it's just too much work to expect Flash to do and Modest Maps doesn't support it. The ACTransit map is a different projection and tiling scheme from Yahoo/Microsoft, for example, so the two won't line up no matter how hard you tweak the providers.
Have a look at the Yahoo hybrid provider too for an example of simple overlays - two images are loaded on top of each other on the same tile. However, this method doesn't allow control over blending or alpha as the HelloLayers example does.
Loading Profile...



EMPLOYEE