Skip to content
This repository has been archived by the owner on Jan 1, 2021. It is now read-only.

Commit

Permalink
More refactoring in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
systemed committed May 21, 2011
1 parent dde8aae commit 43b2f30
Show file tree
Hide file tree
Showing 28 changed files with 102 additions and 98 deletions.
12 changes: 7 additions & 5 deletions REFACTOR.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ Aims:
- to enable multiple Maps to be shown on-screen (e.g. for junction editor)
- to bring Connection and VectorLayer code together

==== think what to do about controllers ====


Map.as changes:
becomes a collection of MapPaint objects, all with the same lat/long/scale
(plus a backdrop sprite and a background imagery sprite)
√ move listeners to Connection to MapPaint (e.g. new way created in the Connection - MapPaint should know about it, not Map)
- refactor tileset/setbackground stuff?

MapPaint.as changes:
- gains a reference to a Connection - i.e. the source data for this layer
Expand All @@ -29,4 +25,10 @@ Global changes:
- remove all references to getConnection etc. - there can now be more than one Connection
- remove all back-references to Map except where necessary for lat/long/scale
- Controllers are full of references to controller.map and to controller.connection
- move AttentionEvent stuff
- getParam is broken - there needs to be a global equivalent (not in Connection) for stuff sent via flashvars - i.e. loaderInfo.parameters (but that's Flex-only)
- Look for Connection. - lots of static stuff which shouldn't be that any more

Further refactoring probably needed:
- move AttentionEvent stuff (some may be commented out)
- Traces (e.g. in potlatch2.mxml) - seems a bit mixed up
- refactor tileset/setbackground stuff?
2 changes: 1 addition & 1 deletion halcyon_viewer.as
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ package {
}

private function onRefreshCSS(str:String):void {
theMap.setStyle(str);
theMap.editableLayer.setStyle(str);
}
private function onJumpTo(lat:Number,lon:Number):void {
theMap.init(lat,lon);
Expand Down
39 changes: 13 additions & 26 deletions net/systemeD/halcyon/Map.as
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ package net.systemeD.halcyon {
public var tileset:TileSet;
/** background tile URL, name and scheme */
private var tileparams:Object={ url:'' };
/** internal style URL */
private var styleurl:String='';
/** show all objects, even if unstyled? */
public var showall:Boolean=true;

Expand Down Expand Up @@ -228,7 +226,7 @@ package net.systemeD.halcyon {
public function download():void {
this.dispatchEvent(new MapEvent(MapEvent.DOWNLOAD, {minlon:edge_l, maxlon:edge_r, maxlat:edge_t, minlat:edge_b} ));
for (var i:uint=0; i<paintContainer.numChildren; i++)
paintContainer.getChildAt(i).connection.loadBbox(edge_l,edge_r,edge_t,edge_b);
getLayerAt(i).connection.loadBbox(edge_l,edge_r,edge_t,edge_b);
}

// Handle mouse events on ways/nodes
Expand All @@ -248,38 +246,36 @@ package net.systemeD.halcyon {
// Add layers

public function addLayer(connection:Connection, styleurl:String, backgroundlayer:Boolean=true):void {
var paint:MapPaint=new MapPaint(this,connection,-5,5);
var paint:MapPaint=new MapPaint(this, connection, styleurl, -5, 5);
paintContainer.addChild(paint);
paint.isBackground=backgroundlayer;
if (styleurl) {
// if we've only just set up paint, then setStyle won't have created the RuleSet
paint.ruleset=new RuleSet(MINSCALE,MAXSCALE,redraw,redrawPOIs);
paint.ruleset.loadFromCSS(styleurl);
}
}

public function removeLayerByName(name:String):void {
for (var i:uint=0; i<paintContainer.numChildren; i++) {
if (paintContainer.getChildAt(i).connection.name==name)
if (getLayerAt(i).connection.name==name)
paintContainer.removeChildAt(i);
// >>>> REFACTOR: needs to do the equivalent of VectorLayer.blank()
}
}

public function findLayer(name:String):MapPaint {
for (var i:uint=0; i<paintContainer.numChildren; i++)
if (paintContainer.getChildAt(i).connection.name==name) return paintContainer.getChildAt(i);
if (getLayerAt(i).connection.name==name) return getLayerAt(i);
return null;
}

private function getLayerAt(i:uint):MapPaint {
return MapPaint(paintContainer.getChildAt(i));
}

/* Find which layer is editable */
public function get editableLayer():MapPaint {
var editableLayer:MapPaint;
for (var i:uint=0; i<paintContainer.numChildren; i++) {
layer=paintContainer.getChildAt(i);
if (!layer.isBackground) {
if (!getLayerAt(i).isBackground) {
if (editableLayer) trace("Multiple editable layers found");
editableLayer=layer;
editableLayer=getLayerAt(i);
}
}
return editableLayer;
Expand All @@ -290,15 +286,15 @@ package net.systemeD.halcyon {

private function updateAllEntityUIs(redraw:Boolean,remove:Boolean):void {
for (var i:uint=0; i<paintContainer.numChildren; i++)
paintContainer.getChildAt(i).updateEntityUIs(redraw, remove);
getLayerAt(i).updateEntityUIs(redraw, remove);
}
public function redraw():void {
for (var i:uint=0; i<paintContainer.numChildren; i++)
paintContainer.getChildAt(i).redraw();
getLayerAt(i).redraw();
}
public function redrawPOIs():void {
for (var i:uint=0; i<paintContainer.numChildren; i++)
paintContainer.getChildAt(i).redrawPOIs();
getLayerAt(i).redrawPOIs();
}

public function zoomIn():void {
Expand All @@ -319,15 +315,6 @@ package net.systemeD.halcyon {
download();
}

/** Switch to new MapCSS. */
public function setStyle(url:String):void {
styleurl=url;
if (paint) {
paint.ruleset=new RuleSet(MINSCALE,MAXSCALE,redraw,redrawPOIs);
paint.ruleset.loadFromCSS(url);
}
}

/** Select a new background imagery. */
public function setBackground(bg:Object):void {
tileparams=bg;
Expand Down
12 changes: 11 additions & 1 deletion net/systemeD/halcyon/MapPaint.as
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ package net.systemeD.halcyon {
* @param minlayer The lowest OSM layer to display.
* @param maxlayer The highest OSM layer to display.
* */
public function MapPaint(map:Map,connection:Connection,minlayer:int,maxlayer:int) {
public function MapPaint(map:Map, connection:Connection, styleurl:String, minlayer:int, maxlayer:int) {
mouseEnabled=false;

this.map=map;
Expand All @@ -59,6 +59,10 @@ package net.systemeD.halcyon {
sublayerIndex[1]=0;
var s:Sprite, l:int;

// Set up stylesheet
ruleset=new RuleSet(MINSCALE,MAXSCALE,redraw,redrawPOIs);
ruleset.loadFromCSS(styleurl);

// Listen for changes on this Connection
connection.addEventListener(Connection.NEW_WAY, newWayCreatedListener);
connection.addEventListener(Connection.NEW_POI, newPOICreatedListener);
Expand Down Expand Up @@ -335,6 +339,12 @@ package net.systemeD.halcyon {
for each (var m:MarkerUI in markeruis) { m.invalidateStyleList(); m.redraw(); }
}

/** Switch to new MapCSS. */
public function setStyle(url:String):void {
ruleset=new RuleSet(MINSCALE,MAXSCALE,redraw,redrawPOIs);
ruleset.loadFromCSS(url);
}

// >>>> REFACTOR: remove this
public function findSource():VectorLayer {
var v:VectorLayer;
Expand Down
2 changes: 1 addition & 1 deletion net/systemeD/halcyon/VectorLayer.as
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ package net.systemeD.halcyon {
oldNode=Node(entity);
unregisterPOI(oldNode);
var newPoiAction:CreatePOIAction = new CreatePOIAction(
oldNode.getTagsCopy(), oldNode.lat, oldNode.lon);
this, oldNode.getTagsCopy(), oldNode.lat, oldNode.lon);
MainUndoStack.getGlobalStack().addAction(newPoiAction);
paint.deleteNodeUI(oldNode);
delete nodes[oldNode.id];
Expand Down
3 changes: 1 addition & 2 deletions net/systemeD/halcyon/connection/AMFConnection.as
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ package net.systemeD.halcyon.connection {
public function AMFConnection(name:String,api:String,policy:String,initparams:Object) {

super(name,api,policy,initparams);
if (Connection.policyURL!='')
Security.loadPolicyFile(Connection.policyURL);
if (policyURL!='') Security.loadPolicyFile(policyURL);

readConnection=new NetConnection();
readConnection.objectEncoding = flash.net.ObjectEncoding.AMF0;
Expand Down
4 changes: 2 additions & 2 deletions net/systemeD/halcyon/connection/Entity.as
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ package net.systemeD.halcyon.connection {
if (this is Node) {
var n:Node = Node(this);
if (isDeleted) {
Connection.getConnection().removeDupe(n);
connection.removeDupe(n);
} else {
Connection.getConnection().addDupe(n);
connection.addDupe(n);
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions net/systemeD/halcyon/connection/Node.as
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ package net.systemeD.halcyon.connection {
}

private function setLatLonImmediate(lat:Number, lon:Number):void {
var connection:Connection = Connection.getConnection();
connection.removeDupe(this);
this._lat = lat;
this._latproj = lat2latp(lat);
Expand Down Expand Up @@ -89,7 +88,6 @@ package net.systemeD.halcyon.connection {
*/
public function join(ways:Array, performAction:Function):void {
if (this.isDupe() || ways.length > 0) {
var connection:Connection = Connection.getConnection();
var nodes:Array = connection.getNodesAtPosition(lat,lon);
// filter the nodes array to remove any occurances of this.
// Pass "this" as thisObject to get "this" into the callback function
Expand All @@ -111,7 +109,6 @@ package net.systemeD.halcyon.connection {
}

public function isDupe():Boolean {
var connection:Connection = Connection.getConnection();
if (connection.getNode(this.id) == this // node could be part of a vector layer
&& connection.nodesAtPosition(lat, lon) > 1) {
return true;
Expand Down
7 changes: 3 additions & 4 deletions net/systemeD/halcyon/connection/OSMConnection.as
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ package net.systemeD.halcyon.connection {
public function OSMConnection(name:String,api:String,policy:String,initparams:Object) {

super(name,api,policy,initparams);
if (Connection.policyURL!='')
Security.loadPolicyFile(Connection.policyURL);
if (policyURL!='') Security.loadPolicyFile(policyURL);

tileResolution = Number(Connection.getParam("tile_resolution", "0.2"));
tileResolution = Number(getParam("tile_resolution", "0.2"));

var o:Object = new Object();
var files:String = Connection.getParam("files","");
var files:String = getParam("files","");
if (files=="") {
filemode=TILED;
} else {
Expand Down
6 changes: 4 additions & 2 deletions net/systemeD/halcyon/connection/Trace.as
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ package net.systemeD.halcyon.connection {
private var _filename:String;
private var _traceData:String;
private var map:Map;
private var _connection:Connection;
private var _layer:VectorLayer;
private var simplify:Boolean = false;

private static const STYLESHEET:String="stylesheets/gpx.css";

public function Trace() {
public function Trace(connection:Connection) {
_connection = connection;
map = Globals.vars.root;
}

Expand Down Expand Up @@ -61,7 +63,7 @@ package net.systemeD.halcyon.connection {

private function fetchFromServer():void {
// todo - needs proper error handling
Connection.getConnection().fetchTrace(id, saveTraceData);
_connection.fetchTrace(id, saveTraceData);
dispatchEvent(new Event("loading_data"));
}

Expand Down
6 changes: 3 additions & 3 deletions net/systemeD/halcyon/connection/UndoableEntityAction.as
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ package net.systemeD.halcyon.connection {
}

if ( !connectionWasDirty ) {
Connection.getConnection().markDirty();
entity.connection.markDirty();
}
}

Expand All @@ -52,7 +52,7 @@ package net.systemeD.halcyon.connection {
}

if ( !connectionWasDirty ) {
Connection.getConnection().markClean();
entity.connection.markClean();
}
}

Expand All @@ -62,7 +62,7 @@ package net.systemeD.halcyon.connection {
*/
private function init():void {
wasDirty = entity.isDirty;
connectionWasDirty = Connection.getConnection().isDirty;
connectionWasDirty = entity.connection.isDirty;
initialised = true;
}

Expand Down
3 changes: 2 additions & 1 deletion net/systemeD/halcyon/connection/XMLBaseConnection.as
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ package net.systemeD.halcyon.connection {
*/
public class XMLBaseConnection extends Connection {

public function XMLBaseConnection() {
public function XMLBaseConnection(name:String,api:String,policy:String,initparams:Object) {
super(name,api,policy,initparams);
}

protected function loadedMap(event:Event):void {
Expand Down
12 changes: 5 additions & 7 deletions net/systemeD/halcyon/connection/XMLConnection.as
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ package net.systemeD.halcyon.connection {
public function XMLConnection(name:String,api:String,policy:String,initparams:Object) {

super(name,api,policy,initparams);
if (Connection.policyURL!='')
Security.loadPolicyFile(Connection.policyURL);
var oauthPolicy:String = Connection.getParam("oauth_policy", "");
if ( oauthPolicy != "" ) {
Security.loadPolicyFile(oauthPolicy);
}
if (policyURL != "") Security.loadPolicyFile(policyURL);

var oauthPolicy:String = getParam("oauth_policy", "");
if (oauthPolicy != "") Security.loadPolicyFile(oauthPolicy);
}

override public function loadBbox(left:Number,right:Number,
Expand Down Expand Up @@ -441,7 +439,7 @@ package net.systemeD.halcyon.connection {
clearTraces();
var files:XML = new XML(URLLoader(event.target).data);
for each(var traceData:XML in files.gpx_file) {
var t:Trace = new Trace().fromXML(traceData);
var t:Trace = new Trace(this).fromXML(traceData);
addTrace(t);
}
traces_loaded = true;
Expand Down
10 changes: 6 additions & 4 deletions net/systemeD/halcyon/connection/actions/CreatePOIAction.as
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,29 @@ package net.systemeD.halcyon.connection.actions {
private var tags:Object;
private var lat:Number;
private var lon:Number;
private var connection:Connection;

public function CreatePOIAction(tags:Object, lat:Number, lon:Number) {
public function CreatePOIAction(connection:Connection, tags:Object, lat:Number, lon:Number) {
super("Create POI");
this.connection = connection;
this.tags = tags;
this.lat = lat;
this.lon = lon;
}

public override function doAction():uint {
if (newNode == null) {
newNode = Connection.getConnection().createNode(tags,lat,lon,push);
newNode = connection.createNode(tags,lat,lon,push);
}
super.doAction();
Connection.getConnection().registerPOI(newNode);
connection.registerPOI(newNode);

return SUCCESS;
}

public override function undoAction():uint {
super.undoAction();
Connection.getConnection().unregisterPOI(newNode);
connection.unregisterPOI(newNode);

return SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ package net.systemeD.halcyon.connection.actions {
} else {
markClean();
}
Connection.getConnection().dispatchEvent(new EntityEvent(Connection.NEW_NODE, entity));
node.connection.dispatchEvent(new EntityEvent(Connection.NEW_NODE, entity));
if ( effects != null )
effects.undoAction();
return SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion net/systemeD/halcyon/connection/actions/DeleteWayAction.as
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ package net.systemeD.halcyon.connection.actions {
} else {
markClean();
}
Connection.getConnection().dispatchEvent(new EntityEvent(Connection.NEW_WAY, way));
entity.connection.dispatchEvent(new EntityEvent(Connection.NEW_WAY, way));
effects.undoAction();
for each(var node:Node in oldNodeList) {
nodeList.push(node);
Expand Down
2 changes: 1 addition & 1 deletion net/systemeD/halcyon/connection/actions/SplitWayAction.as
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package net.systemeD.halcyon.connection.actions {

public override function doAction():uint {
if (newWay==null) {
newWay = Connection.getConnection().createWay(
newWay = selectedWay.connection.createWay(
selectedWay.getTagsCopy(),
selectedWay.sliceNodes(nodeIndex,selectedWay.length),
push);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ package net.systemeD.halcyon.connection.actions {
way.dispatchEvent(new EntityEvent(Connection.WAY_REORDERED, way)); // no longer a junction, so force redraw
continue;
} else {
var newNode:Node = Connection.getConnection().createNode(node.getTagsCopy(), node.lat, node.lon, push);
var newNode:Node = way.connection.createNode(node.getTagsCopy(), node.lat, node.lon, push);
for (var i:int = 0; i < way.length; i++) {
if(way.getNode(i) == node) {
way.removeNodeByIndex(i, push);
Expand Down
Loading

0 comments on commit 43b2f30

Please sign in to comment.