From: Andy Allan Date: Mon, 23 May 2011 17:49:56 +0000 (+0100) Subject: Rework BikeShopLoader/Layer so that it responds to loadBbox calls X-Git-Tag: 2.2~1^2~51 X-Git-Url: https://git.openstreetmap.org/potlatch2.git/commitdiff_plain/0315ebd9eeb0041ddce6ccea451d296386a6a515 Rework BikeShopLoader/Layer so that it responds to loadBbox calls --- diff --git a/net/systemeD/potlatch2/utils/BikeShopConnection.as b/net/systemeD/potlatch2/utils/BikeShopConnection.as new file mode 100644 index 00000000..ff262aee --- /dev/null +++ b/net/systemeD/potlatch2/utils/BikeShopConnection.as @@ -0,0 +1,50 @@ +package net.systemeD.potlatch2.utils { + + import net.systemeD.halcyon.connection.Connection; + import net.systemeD.halcyon.connection.Marker; + import com.adobe.serialization.json.JSON; + import flash.system.Security; + import flash.net.*; + import flash.events.*; + + public class BikeShopConnection extends Connection { + + public function BikeShopConnection(cname:String,api:String,policy:String,initparams:Object=null) { + super(cname,api,policy,initparams); + } + + public override function loadBbox(left:Number, right:Number, top:Number, bottom:Number):void { + + // Should be guarded against multiple calls really. + if (policyURL != "") { Security.loadPolicyFile(policyURL); } + + var loader:URLLoader = new URLLoader(); + loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, balls); + loader.addEventListener(Event.COMPLETE, parseKML); + loader.load(new URLRequest(apiBaseURL+"shop/missing.kml?bbox="+left+","+bottom+","+right+","+top)); + } + + public function balls(event:SecurityErrorEvent):void { + } + + private function parseKML(event:Event):void { + //trace(event.target.data); + default xml namespace = new Namespace("http://www.opengis.net/kml/2.2"); + var kml:XML = new XML(event.target.data); + //trace(kml.attributes()); + //var document:XMLList = kml.Document; + for each (var placemark:XML in kml..Placemark) { + trace("name:"+placemark.name); + var coords:Array = placemark..coordinates.split(","); + var lon:Number = coords[0]; + var lat:Number = coords[1]; + //var ele:Number = coords[2]; + var tags:Object = {}; + tags["name"] = String(placemark.name); + tags["description"] = String(placemark.description); + var marker:Marker = createMarker(tags, lat, lon); + } + default xml namespace = new Namespace(""); + } + } +} \ No newline at end of file diff --git a/net/systemeD/potlatch2/utils/BikeShopLoader.as b/net/systemeD/potlatch2/utils/BikeShopLoader.as index b09946f8..87996f3e 100644 --- a/net/systemeD/potlatch2/utils/BikeShopLoader.as +++ b/net/systemeD/potlatch2/utils/BikeShopLoader.as @@ -33,51 +33,14 @@ package net.systemeD.potlatch2.utils { this.map = map; this.bikeShopBaseURL = url; this.name = name; - this.connection = new Connection(name,url,null,null); + this.connection = new BikeShopConnection(name,url,bikeShopBaseURL+"crossdomain.xml",null); } public function load():void { - // this would be better if the connection did the loading - var loader:URLLoader = new URLLoader(); - loader.load(new URLRequest(bikeShopBaseURL+"shop/missing.kml?bbox="+map.edge_l+","+map.edge_b+","+map.edge_r+","+map.edge_t)); - loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, balls); - loader.addEventListener(Event.COMPLETE, parseKML); - } - - public function balls(event:SecurityErrorEvent):void { - trace(event); - } - - private function parseKML(event:Event):void { - //trace(event.target.data); - default xml namespace = new Namespace("http://www.opengis.net/kml/2.2"); - var kml:XML = new XML(event.target.data); - //trace(kml.attributes()); - //var document:XMLList = kml.Document; - for each (var placemark:XML in kml..Placemark) { - trace("name:"+placemark.name); - var coords:Array = placemark..coordinates.split(","); - var lon:Number = coords[0]; - var lat:Number = coords[1]; - //var ele:Number = coords[2]; - var tags:Object = {}; - tags["name"] = String(placemark.name); - tags["description"] = String(placemark.description); - var marker:Marker = connection.createMarker(tags, lat, lon); - } - default xml namespace = new Namespace(""); - layer.updateEntityUIs(true, false); - } - - private function get layer():MapPaint { if (!_layer) { - // this should be done by the connection, not here. - var policyFile:String = bikeShopBaseURL+"crossdomain.xml"; - Security.loadPolicyFile(policyFile); - - _layer = map.addLayer(connection, STYLESHEET); + _layer = map.addLayer(connection, STYLESHEET); } - return _layer; + connection.loadBbox(map.edge_l, map.edge_r, map.edge_t, map.edge_b); } } } \ No newline at end of file