Skip to content

Commit

Permalink
bing maps in demo
Browse files Browse the repository at this point in the history
  • Loading branch information
jozefchutka committed Aug 8, 2013
1 parent bd8997c commit 6c231fb
Show file tree
Hide file tree
Showing 15 changed files with 296 additions and 10 deletions.
13 changes: 10 additions & 3 deletions ApplicationMap/.actionScriptProperties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<compiler additionalCompilerArguments="-locale en_US" advancedTelemetry="true" autoRSLOrdering="true" copyDependentFiles="true" fteInMXComponents="false" generateAccessible="false" htmlExpressInstall="true" htmlGenerate="true" htmlHistoryManagement="true" htmlPlayerVersionCheck="true" includeNetmonSwc="false" outputFolderPath="bin-debug" removeUnusedRSL="true" sourceFolderPath="src/main/actionscript" strict="true" targetPlayerVersion="0.0.0" useApolloConfig="false" useDebugRSLSwfs="true" useFlashSDK="true" verifyDigests="true" warn="true">
<compilerSourcePath>
<compilerSourcePathEntry kind="1" linkType="1" path="src/main/resources"/>
<compilerSourcePathEntry kind="1" linkType="1" path="src/test/actionscript"/>
</compilerSourcePath>
<libraryPath defaultLinkType="0">
<libraryPathEntry kind="4" path="">
Expand All @@ -19,24 +20,30 @@
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/spark.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/sparkskins.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/rpc.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/videoPlayer.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/qtp_air.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/datavisualization.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/qtp_air.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/videoPlayer.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/spark_dmv.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/flash-integration.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_dmv.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/flash-integration.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_flashflexkit.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_agent.swc" useDefaultLinkType="false"/>
</excludedEntries>
</libraryPathEntry>
<libraryPathEntry kind="1" linkType="1" path="libs"/>
<libraryPathEntry kind="3" linkType="1" path="/YCanvasLibrary/bin/YCanvasLibrary.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="/YCanvasMapLibrary/bin/YCanvasMapLibrary.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="1" linkType="1" path="${FLEXUNIT_LIB_LOCATION}/version4libs/Common"/>
<libraryPathEntry kind="1" linkType="1" path="${FLEXUNIT_LIB_LOCATION}/version4libs/ASProject"/>
<libraryPathEntry kind="1" linkType="1" path="${FLEXUNIT_LIB_LOCATION}/version4libs/ASProject_Extended"/>
<libraryPathEntry kind="1" linkType="1" path="${FLEXUNIT_LOCALE_LOCATION}"/>
</libraryPath>
<sourceAttachmentPath/>
</compiler>
<applications>
<application path="FlexUnitApplication.as"/>
<application path="FlexUnitCompilerApplication.as"/>
<application path="ApplicationMap.as"/>
</applications>
<modules/>
Expand Down
43 changes: 43 additions & 0 deletions ApplicationMap/src/main/actionscript/FlexUnitApplication.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package
{
import Array;

import flash.display.Sprite;

import flexunit.flexui.FlexUnitTestRunnerUIAS;

import sk.yoz.utils.PathSimplifyTest;
import sk.yoz.ycanvas.map.demo.utils.BingMapsUtilsTest;
import sk.yoz.ycanvas.map.utils.PartialBoundsUtilsTest;
import sk.yoz.ycanvas.map.utils.PolygonUtilsTest;
import sk.yoz.ycanvas.map.utils.StrokeUtilsTest;
import sk.yoz.ycanvas.map.utils.VertexDataUtilsTest;

public class FlexUnitApplication extends Sprite
{
public function FlexUnitApplication()
{
onCreationComplete();
}

private function onCreationComplete():void
{
var testRunner:FlexUnitTestRunnerUIAS=new FlexUnitTestRunnerUIAS();
testRunner.portNumber=8765;
this.addChild(testRunner);
testRunner.runWithFlexUnit4Runner(currentRunTestSuite(), "ApplicationMap");
}

public function currentRunTestSuite():Array
{
var testsToRun:Array = new Array();
testsToRun.push(sk.yoz.utils.PathSimplifyTest);
testsToRun.push(sk.yoz.ycanvas.map.utils.PolygonUtilsTest);
testsToRun.push(sk.yoz.ycanvas.map.demo.utils.BingMapsUtilsTest);
testsToRun.push(sk.yoz.ycanvas.map.utils.PartialBoundsUtilsTest);
testsToRun.push(sk.yoz.ycanvas.map.utils.VertexDataUtilsTest);
testsToRun.push(sk.yoz.ycanvas.map.utils.StrokeUtilsTest);
return testsToRun;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
*This file is automatically generated by Flash Builder to compile FlexUnit classes and is not intended for modification.
*Please click on the "Refresh" icon in "FlexUnit Results" view to regenerate this file.
*/

package
{
import flash.display.Sprite;

import sk.yoz.ycanvas.map.demo.utils.BingMapsUtilsTest;

public class FlexUnitCompilerApplication extends Sprite
{

private var sk_yoz_ycanvas_map_demo_utils_BingMapsUtilsTest_obj:sk.yoz.ycanvas.map.demo.utils.BingMapsUtilsTest;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ package sk.yoz.ycanvas.map.demo
tilesPickerList.y = mapPickerList.y + mapPickerList.height + 5;
tilesPickerList.dataProvider = new ListCollection([
{label: "ArcGIS Imagery", data: Maps.ARCGIS_IMAGERY},
{label: "BingMaps Imagery", data: Maps.BINGMAPS_IMAGERY},
{label: "ArcGIS National Geographic", data: Maps.ARCGIS_NATIONAL_GEOGRAPHIC},
{label: "Map Quest", data: Maps.MAPQUEST},
{label: "OSM", data: Maps.OSM},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@ package sk.yoz.ycanvas.map.demo
import feathers.controls.Label;
import feathers.core.PopUpManager;

import sk.yoz.net.URLRequestBuffer;
import sk.yoz.utils.GeoUtils;
import sk.yoz.ycanvas.map.YCanvasMap;
import sk.yoz.ycanvas.map.demo.mock.Maps;
import sk.yoz.ycanvas.map.demo.partition.CustomPartitionFactory;
import sk.yoz.ycanvas.map.display.MapLayer;
import sk.yoz.ycanvas.map.display.MarkerLayer;
import sk.yoz.ycanvas.map.display.StrokeLayer;
import sk.yoz.ycanvas.map.events.CanvasEvent;
import sk.yoz.ycanvas.map.layers.LayerFactory;
import sk.yoz.ycanvas.map.managers.AbstractTransformationManager;
import sk.yoz.ycanvas.map.managers.MouseTransformationManager;
import sk.yoz.ycanvas.map.managers.TouchTransformationManager;
import sk.yoz.ycanvas.map.partitions.PartitionFactory;
import sk.yoz.ycanvas.map.valueObjects.Limit;
import sk.yoz.ycanvas.map.valueObjects.MapConfig;
import sk.yoz.ycanvas.map.valueObjects.Transformation;

import starling.core.Starling;
Expand Down Expand Up @@ -51,7 +56,15 @@ package sk.yoz.ycanvas.map.demo
limit.minCenterY = GeoUtils.lat2y(85);
limit.maxCenterY = GeoUtils.lat2y(-85);

map = new YCanvasMap(Maps.ARCGIS_IMAGERY, transformation, 256);
var config:MapConfig = Maps.ARCGIS_IMAGERY;

map = new YCanvasMap(config, transformation, 256);

//Lets customize partition factory so it creates CustomPartition
// capable of handling bing maps
map.partitionFactory = new CustomPartitionFactory(config, map, new URLRequestBuffer(6, 10000));
map.layerFactory = new LayerFactory(config, map.partitionFactory);

map.addEventListener(CanvasEvent.TRANSFORMATION_FINISHED, onMapTransformationFinished);
transformationManager = Mouse.supportsCursor && !Starling.multitouchEnabled
? new MouseTransformationManager(map, limit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package sk.yoz.ycanvas.map.demo
{
import flash.geom.Point;

import sk.yoz.net.URLRequestBuffer;
import sk.yoz.ycanvas.map.YCanvasMap;
import sk.yoz.ycanvas.map.demo.mock.Maps;
import sk.yoz.ycanvas.map.demo.partition.CustomPartitionFactory;
import sk.yoz.ycanvas.map.display.MapDisplay;
import sk.yoz.ycanvas.map.events.CanvasEvent;
import sk.yoz.ycanvas.map.layers.LayerFactory;
import sk.yoz.ycanvas.map.valueObjects.MapConfig;
import sk.yoz.ycanvas.map.valueObjects.Transformation;

Expand Down Expand Up @@ -37,7 +40,15 @@ package sk.yoz.ycanvas.map.demo
background = new Quad(1, 1, 0xffffff);
background.touchable = false;

map = new YCanvasMap(Maps.OSM, transformation);
var config:MapConfig = Maps.OSM;

map = new YCanvasMap(config, transformation);

//Lets customize partition factory so it creates CustomPartition
// capable of handling bing maps
map.partitionFactory = new CustomPartitionFactory(config, map, new URLRequestBuffer(6, 10000));
map.layerFactory = new LayerFactory(config, map.partitionFactory);

map.display.addChildAt(background, 0);
map.display.addEventListener(TouchEvent.TOUCH, onMapTouch);
map.display.addEventListener(MapDisplay.VIEWPORT_UPDATED, onViewportUpdated);
Expand Down Expand Up @@ -86,6 +97,9 @@ package sk.yoz.ycanvas.map.demo
{
background.width = map.display.width;
background.height = map.display.height;

if(autoSync)
sync();
}

private function onBigMapControllerRendered(event:CanvasEvent):void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package sk.yoz.ycanvas.map.demo.mock
private static var _ARCGIS_IMAGERY:MapConfig;
private static var _ARCGIS_NATIONAL_GEOGRAPHIC:MapConfig;
private static var _ARCGIS_REFERENCE:MapConfig;
private static var _BINGMAPS_IMAGERY:MapConfig;

public static function get MAPQUEST():MapConfig
{
Expand Down Expand Up @@ -85,6 +86,17 @@ package sk.yoz.ycanvas.map.demo.mock
return _ARCGIS_REFERENCE;
}

public static function get BINGMAPS_IMAGERY():MapConfig
{
if(!_BINGMAPS_IMAGERY)
_BINGMAPS_IMAGERY = createMapConfig([
"http://ecn.t0.tiles.virtualearth.net/tiles/a${bingMapsQuadKey}.jpeg?g=1494",
"http://ecn.t1.tiles.virtualearth.net/tiles/a${bingMapsQuadKey}.jpeg?g=1494",
"http://ecn.t2.tiles.virtualearth.net/tiles/a${bingMapsQuadKey}.jpeg?g=1494",
"http://ecn.t3.tiles.virtualearth.net/tiles/a${bingMapsQuadKey}.jpeg?g=1494"]);
return _BINGMAPS_IMAGERY;
}

private static function createMapConfig(templates:Array):MapConfig
{
var result:MapConfig = new MapConfig;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package sk.yoz.ycanvas.map.demo.partition
{
import flash.events.IEventDispatcher;

import sk.yoz.net.URLRequestBuffer;
import sk.yoz.ycanvas.interfaces.ILayer;
import sk.yoz.ycanvas.map.demo.utils.BingMapsUtils;
import sk.yoz.ycanvas.map.partitions.Partition;
import sk.yoz.ycanvas.map.valueObjects.MapConfig;

public class CustomPartition extends Partition
{
public function CustomPartition(x:int, y:int, layer:ILayer,
config:MapConfig, dispatcher:IEventDispatcher,
buffer:URLRequestBuffer)
{
super(x, y, layer, config, dispatcher, buffer);
}

override protected function get url():String
{
var url:String = super.url;
if(url.indexOf("${bingMapsQuadKey}") > 0)
{
var quadKey:String = BingMapsUtils.tileXYToQuadKey(
x / expectedWidth / layer.level,
y / expectedHeight / layer.level,
18 - getLevel(layer.level));
url = url.replace("${bingMapsQuadKey}", quadKey);
}

return url;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package sk.yoz.ycanvas.map.demo.partition
{
import flash.events.IEventDispatcher;

import sk.yoz.net.URLRequestBuffer;
import sk.yoz.ycanvas.interfaces.ILayer;
import sk.yoz.ycanvas.interfaces.IPartition;
import sk.yoz.ycanvas.map.partitions.PartitionFactory;
import sk.yoz.ycanvas.map.valueObjects.MapConfig;

public class CustomPartitionFactory extends PartitionFactory
{
public function CustomPartitionFactory(config:MapConfig,
dispatcher:IEventDispatcher, buffer:URLRequestBuffer)
{
super(config, dispatcher, buffer);
}

override public function create(x:int, y:int, layer:ILayer):IPartition
{
return new CustomPartition(x, y, layer, config, dispatcher, buffer);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* Inspired by:
http://msdn.microsoft.com/en-us/library/bb259689.aspx
*/
package sk.yoz.ycanvas.map.demo.utils
{
import sk.yoz.ycanvas.map.demo.valueObjects.BingMapsTileInfo;

public class BingMapsUtils
{
public static function tileXYToQuadKey(tileX:uint, tileY:uint, levelOfDetail:uint):String
{
var quadKey:String = "";
for(var i:uint = levelOfDetail; i > 0; i--)
{
var digit:uint = 0;
var mask:uint = 1 << (i - 1);
if((tileX & mask) != 0)
{
digit++;
}
if((tileY & mask) != 0)
{
digit++;
digit++;
}
quadKey += digit;
}
return quadKey;
}

public static function quadKeyToTileXY(quadKey:String):BingMapsTileInfo
{
var result:BingMapsTileInfo = new BingMapsTileInfo;
result.tileX = 0;
result.tileY = 0;
result.levelOfDetail = quadKey.length;
for(var i:uint = result.levelOfDetail; i > 0; i--)
{
var mask:uint = 1 << (i - 1);
switch(quadKey.charAt(result.levelOfDetail - i))
{
case '0':
break;

case '1':
result.tileX |= mask;
break;

case '2':
result.tileY |= mask;
break;

case '3':
result.tileX |= mask;
result.tileY |= mask;
break;

default:
throw new Error("Invalid QuadKey digit sequence.");
}
}
return result;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package sk.yoz.ycanvas.map.demo.valueObjects
{
public class BingMapsTileInfo
{
public var tileX:uint
public var tileY:uint;
public var levelOfDetail:uint;
}
}
Loading

0 comments on commit 6c231fb

Please sign in to comment.