From: Richard Fairhurst Date: Fri, 9 Oct 2009 15:00:05 +0000 (+0000) Subject: some more footling around with POI nodes in ways X-Git-Tag: 0.5~614 X-Git-Url: https://git.openstreetmap.org/potlatch2.git/commitdiff_plain/1628c2d9fd72d3bc42e0182671bb06f0b26410cf some more footling around with POI nodes in ways --- diff --git a/net/systemeD/halcyon/POI.as b/net/systemeD/halcyon/POI.as index be01436d..31ddd536 100644 --- a/net/systemeD/halcyon/POI.as +++ b/net/systemeD/halcyon/POI.as @@ -13,9 +13,10 @@ package net.systemeD.halcyon { private var node:Node; public var map:Map; // reference to parent map - public var icon:Bitmap; // instance in display list + public var icon:Sprite; // instance in display list public var name:Sprite; // | private var iconname:String=''; // name of icon + public var loaded:Boolean=false; public static const DEFAULT_TEXTFIELD_PARAMS:Object = { // embedFonts: true, @@ -25,16 +26,18 @@ package net.systemeD.halcyon { // [Embed(source="fonts/DejaVuSans.ttf", fontFamily="DejaVu", fontWeight="normal", mimeType="application/x-font-truetype")] // public static var DejaVu:Class; - public function POI(node:Node, map:Map) { + public function POI(node:Node, map:Map, sl:StyleList=null) { this.map = map; this.node = node; - redraw(); + redraw(sl); } - public function redraw():void { + public function redraw(sl:StyleList=null):Boolean { var tags:Object = node.getTagsCopy(); // ** apply :hover etc. - var sl:StyleList=map.ruleset.getStyles(this.node,tags); + if (!sl) { sl=map.ruleset.getStyles(this.node,tags); } + if (!sl.hasStyles()) { return false; } + var r:Boolean=false; // ** rendered var l:DisplayObject; for (var sublayer:uint=0; sublayer<10; sublayer++) { @@ -53,7 +56,6 @@ package net.systemeD.halcyon { } else { // already loaded, so just reposition updatePosition(); - iconname=s.icon_image; } } @@ -74,15 +76,27 @@ package net.systemeD.halcyon { Sprite(l).removeChild(icon); iconname=''; } + return true; } private function loadedIcon(event:Event):void { - icon = Bitmap(event.target.content); + icon = new Sprite(); + icon.addChild(Bitmap(event.target.content)); var l:DisplayObject=map.getChildAt(map.POISPRITE); Sprite(l).addChild(icon); updatePosition(); + + icon.addEventListener(MouseEvent.CLICK, mouseEvent); + icon.buttonMode = true; + icon.mouseEnabled = true; + + loaded=true; } + private function mouseEvent(event:MouseEvent):void { + map.entityMouseEvent(event, node); + } + private function updatePosition():void { icon.x=map.lon2coord(node.lon)-icon.width/2; icon.y=map.latp2coord(node.latp)-icon.height/2; diff --git a/net/systemeD/halcyon/TileSet.as b/net/systemeD/halcyon/TileSet.as index d71013d5..0786e08e 100755 --- a/net/systemeD/halcyon/TileSet.as +++ b/net/systemeD/halcyon/TileSet.as @@ -10,7 +10,6 @@ package net.systemeD.halcyon { import flash.net.*; import net.systemeD.halcyon.ImageURLLoader; - import net.systemeD.halcyon.Globals; import flash.system.LoaderContext; public class TileSet extends Sprite { @@ -70,8 +69,10 @@ package net.systemeD.halcyon { r=requests.shift(); tz=r[0]; tx=r[1]; ty=r[2]; if (tx>=tile_l && tx<=tile_r && ty>=tile_t && ty<=tile_b) { // Tile is on-screen, so load + waiting++; var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.INIT, doImgInit); + loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, missingTileError); loader.load(new URLRequest(tileURL(tx,ty)), new LoaderContext(true)); this.addChild(loader); @@ -82,7 +83,12 @@ package net.systemeD.halcyon { } } - protected function doImgInit(evt:Event):void { + private function missingTileError(event:Event):void { + waiting--; + return; + } + + protected function doImgInit(event:Event):void { waiting--; return; } diff --git a/net/systemeD/halcyon/WayUI.as b/net/systemeD/halcyon/WayUI.as index 8ca965cd..929b25c8 100755 --- a/net/systemeD/halcyon/WayUI.as +++ b/net/systemeD/halcyon/WayUI.as @@ -196,17 +196,28 @@ package net.systemeD.halcyon { } } - // ** draw icons - for (var i:uint = 0; i < way.length; i++) { - var node:Node = way.getNode(i); - if (node.hasTags()) { - map.connection.registerPOI(node); + // ** ShieldStyle to do + } + + // ** draw icons + for (var i:uint = 0; i < way.length; i++) { + var node:Node = way.getNode(i); + if (map.pois[node.id]) { + if (map.pois[node.id].loaded) { + map.pois[node.id].redraw(); + } + } else if (node.hasTags()) { + sl=map.ruleset.getStyles(node,node.getTagsHash()); + if (sl.hasStyles()) { + map.pois[node.id]=new POI(node,map,sl); + // ** this should be done via the registerPOI/event listener mechanism, + // but that needs a bit of reworking so we can pass in a styleList + // (otherwise we end up computing the styles twice which is expensive) } } - - - // ** ShieldStyle to do } + + // No styles, so add a thin trace if (!drawn && map.showall) { diff --git a/net/systemeD/halcyon/connection/Entity.as b/net/systemeD/halcyon/connection/Entity.as index de2983a0..57083280 100644 --- a/net/systemeD/halcyon/connection/Entity.as +++ b/net/systemeD/halcyon/connection/Entity.as @@ -43,6 +43,8 @@ package net.systemeD.halcyon.connection { return false; } + // ** we could do with hasInterestingTags - don't bother with source, created_by, any TIGER tags, etc. + public function getTag(key:String):String { return tags[key]; } diff --git a/net/systemeD/halcyon/styleparser/RuleSet.as b/net/systemeD/halcyon/styleparser/RuleSet.as index 517856f3..42d6179e 100644 --- a/net/systemeD/halcyon/styleparser/RuleSet.as +++ b/net/systemeD/halcyon/styleparser/RuleSet.as @@ -88,7 +88,6 @@ package net.systemeD.halcyon.styleparser { // data handler private function loadedImage(event:Event):void { -Globals.vars.root.addDebug("adding image at "+event.target.filename); images[event.target.filename]=event.target.data; iconsToLoad--; if (iconsToLoad==0 && iconCallback!=null) { iconCallback(); } diff --git a/net/systemeD/halcyon/styleparser/Style.as b/net/systemeD/halcyon/styleparser/Style.as index d0708239..cd5b608a 100755 --- a/net/systemeD/halcyon/styleparser/Style.as +++ b/net/systemeD/halcyon/styleparser/Style.as @@ -2,7 +2,6 @@ package net.systemeD.halcyon.styleparser { import flash.utils.ByteArray; import flash.net.*; - import net.systemeD.halcyon.Globals; public class Style { diff --git a/net/systemeD/halcyon/styleparser/StyleList.as b/net/systemeD/halcyon/styleparser/StyleList.as index 5ee42bca..e2496e27 100755 --- a/net/systemeD/halcyon/styleparser/StyleList.as +++ b/net/systemeD/halcyon/styleparser/StyleList.as @@ -16,5 +16,8 @@ package net.systemeD.halcyon.styleparser { public var pointStyles:Array=[]; public var shieldStyles:Array=[]; + public function hasStyles():Boolean { + return ( (shapeStyles.length + textStyles.length + pointStyles.length + shieldStyles.length) > 0 ); + } } } \ No newline at end of file