Skip to content

Commit

Permalink
POI stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
systemed committed Jun 1, 2009
1 parent b6de890 commit b79c9d0
Show file tree
Hide file tree
Showing 33 changed files with 116 additions and 77 deletions.
13 changes: 13 additions & 0 deletions LICENCE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004

Copyright (C) 2004 Sam Hocevar
14 rue de Plaisance, 75014 Paris, France
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.
11 changes: 8 additions & 3 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Here's some embryonic unfinished stuff to play with.

This is a live OSM renderer written in AS3 which will one day grow into a beautiful map editor.
This is a live OSM renderer written in AS3 which will one day grow into a beautiful map editor. It's rules-based (like, say, Mapnik) and does dotted lines, text on a path, casing, icons for POIs, all of that.

=== What you'll need ===

Expand All @@ -15,10 +15,15 @@ This is a live OSM renderer written in AS3 which will one day grow into a beauti
=== How to compile and run ===

Compiling:
mxmlc -managers=flash.fonts.AFEFontManager -output=/path/to/halcyon.swf /path/to/halcyon.mxml
* fcsh
- launches the Flex Compiler SHell
* mxmlc -managers=flash.fonts.AFEFontManager -output=/path/to/halcyon.swf /path/to/halcyon.mxml
- compile for the first time
* compile 1
- compile each subsequent time (_much_ faster than using mxmlc every time)

Running:
* Make sure test.yaml is in the same directory as halcyon.swf
* Make sure test.yaml and icons/ are in the same directory as halcyon.swf
* Open halcyon.swf in your browser

=== Some other stuff you might need to know ===
Expand Down
6 changes: 3 additions & 3 deletions halcyon.mxml
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@
// add debug field
var t:TextField=new TextField();
//t.width=400; t.height=100; t.border=true;
//t.multiline=true;
//_root.addChild(t);
t.width=400; t.height=100; t.border=true;
t.multiline=true;
_root.addChild(t);
Globals.vars.debug=t;
}
Expand Down
52 changes: 21 additions & 31 deletions halcyon.tmproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,35 @@
<dict>
<key>documents</key>
<array>
<dict>
<key>filename</key>
<string>net/systemeD/halcyon/AMFConnection.as</string>
<key>lastUsed</key>
<date>2009-05-30T13:59:09Z</date>
</dict>
<dict>
<key>filename</key>
<string>net/systemeD/halcyon/Connection.as</string>
<key>lastUsed</key>
<date>2009-05-30T13:59:04Z</date>
</dict>
<dict>
<key>filename</key>
<string>net/systemeD/halcyon/Globals.as</string>
<key>lastUsed</key>
<date>2009-05-30T15:21:19Z</date>
</dict>
<dict>
<key>filename</key>
<string>net/systemeD/halcyon/Map.as</string>
<key>lastUsed</key>
<date>2009-05-30T15:21:19Z</date>
<date>2009-06-01T11:58:41Z</date>
</dict>
<dict>
<key>filename</key>
<string>net/systemeD/halcyon/Node.as</string>
<string>net/systemeD/halcyon/POI.as</string>
<key>lastUsed</key>
<date>2009-05-30T13:59:07Z</date>
<date>2009-06-01T12:11:15Z</date>
<key>selected</key>
<true/>
</dict>
<dict>
<key>filename</key>
<string>net/systemeD/halcyon/POI.as</string>
<string>net/systemeD/halcyon/WayUI.as</string>
<key>lastUsed</key>
<date>2009-05-30T15:09:53Z</date>
<date>2009-06-01T11:58:42Z</date>
</dict>
<dict>
<key>filename</key>
<string>net/systemeD/halcyon/Way.as</string>
<key>lastUsed</key>
<date>2009-05-30T15:16:50Z</date>
<key>expanded</key>
<true/>
<key>name</key>
<string>connection</string>
<key>regexFolderFilter</key>
<string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
<key>sourceDirectory</key>
<string>net/systemeD/halcyon/connection</string>
</dict>
<dict>
<key>expanded</key>
Expand All @@ -56,13 +44,15 @@
<key>sourceDirectory</key>
<string>net/systemeD/halcyon/styleparser</string>
</dict>
<dict>
<key>filename</key>
<string>net/systemeD/halcyon/Globals.as</string>
</dict>
<dict>
<key>filename</key>
<string>halcyon.mxml</string>
<key>lastUsed</key>
<date>2009-05-30T15:21:19Z</date>
<key>selected</key>
<true/>
<date>2009-06-01T11:49:17Z</date>
</dict>
</array>
<key>fileHierarchyDrawerWidth</key>
Expand All @@ -72,6 +62,6 @@
<key>showFileHierarchyDrawer</key>
<true/>
<key>windowFrame</key>
<string>{{272, 182}, {710, 564}}</string>
<string>{{268, 182}, {710, 564}}</string>
</dict>
</plist>
Binary file added icons/airport.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/atm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/bus_stop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/cafe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/convenience.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/fast_food.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/fire_station.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/hospital.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/hotel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/icons_grid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/parking.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/pharmacy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/pharmacy_dispensing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/police.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/post_box.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/pub.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/recycling.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/restaurant.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/school.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/station.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/taxi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/telephone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 8 additions & 10 deletions net/systemeD/halcyon/Map.as
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package net.systemeD.halcyon {
public const MINSCALE:uint=13; // don't zoom out past this
public const MAXSCALE:uint=19; // don't zoom in past this

public var ruleset:RuleSet=new RuleSet(); // rules
public var ruleset:RuleSet=new RuleSet(redrawPOIs); // rules

public var ways:Object=new Object(); // geodata
public var nodes:Object=new Object(); // |
Expand Down Expand Up @@ -84,7 +84,7 @@ package net.systemeD.halcyon {
}

public function gotEnvironment(r:Object):void {
init(51.45889,-0.21476);
init(52.022,-1.2745);
}

// ------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -205,14 +205,12 @@ package net.systemeD.halcyon {
// Redraw all items, zoom in and out

public function redraw():void {
// addDebug("redrawing");
// var s:String='';
for each (var w:WayUI in ways) {
w.redraw();
// s+=w.id+",";
}
// addDebug(s);
// ** do POIs, etc.
for each (var w:WayUI in ways) { w.redraw(); }
for each (var p:POI in pois) { p.redraw(); }
}

public function redrawPOIs():void {
for each (var p:POI in pois) { p.redraw(); }
}

public function zoomIn():void {
Expand Down
53 changes: 33 additions & 20 deletions net/systemeD/halcyon/POI.as
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ package net.systemeD.halcyon {

private var node:Node;
public var map:Map; // reference to parent map
public var icon:Sprite; // instance in display list
public var icon:Bitmap; // instance in display list
public var name:Sprite; // |
private var iconname:String=''; // name of icon

[Embed(source="fonts/DejaVuSans.ttf", fontFamily="DejaVu", fontWeight="normal", mimeType="application/x-font-truetype")]
public static var DejaVu:Class;
Expand All @@ -22,34 +23,46 @@ package net.systemeD.halcyon {
public function POI(node:Node, map:Map) {
this.map = map;
this.node = node;

map.addDebug("POI "+node.id);

// place icon on map
var tags:Object = node.getTagsCopy();
redraw();
}
public function redraw():void {
var tags:Object = node.getTagsCopy();
var styles:Array=map.ruleset.getStyle(true,tags,map.scale);
var ps:PointStyle=styles[1];

if (ps) {
map.addDebug("pointstyle found");
if (ps.icon && ps.icon!='') {
map.addDebug("placing "+ps.icon);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedIcon);
loader.loadBytes(map.ruleset.images[ps.icon]);
if (ps && ps.icon && ps.icon!='') {
if (ps.icon!=iconname) {
// 'load' icon (actually just from library)
if (map.ruleset.images[ps.icon]) {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedIcon);
loader.loadBytes(map.ruleset.images[ps.icon]);
iconname=ps.icon;
}
} else {
// already loaded, so just reposition
updatePosition();
iconname=ps.icon;
}
} else if (iconname!='') {
// not rendered any more, so remove
var l:DisplayObject=map.getChildAt(11);
Sprite(l).removeChild(icon);
iconname='';
}
}

private function loadedIcon(event:Event):void {
map.addDebug("loadedIcon");
var bitmap:Bitmap = Bitmap(event.target.content);
icon = Bitmap(event.target.content);
var l:DisplayObject=map.getChildAt(11);
bitmap.x=map.lon2coord(node.lon);
bitmap.y=map.latp2coord(node.latp);
Sprite(l).addChild(bitmap);
Sprite(l).addChild(icon);
updatePosition();
}

private function updatePosition():void {
icon.x=map.lon2coord(node.lon);
icon.y=map.latp2coord(node.latp);
}

// redraw
}
}
14 changes: 9 additions & 5 deletions net/systemeD/halcyon/connection/AMFConnection.as
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ package net.systemeD.halcyon.connection {
var relationlist:Array=r[2];
var id:Number, version:uint;

// Load ways

for each (var w:Array in waylist) {
id=Number(w[0]);
version=uint(w[1]);
Expand All @@ -63,15 +65,17 @@ package net.systemeD.halcyon.connection {
}
}

// Create POIs

for each (var p:Array in pointlist) {
id = Number(w[0]);
version = uint(w[4]);
id = Number(p[0]);
version = uint(p[4]);

var node:Node = getNode(id);
if ( node == null ) {
var lat:Number = Number(w[2]);
var lon:Number = Number(w[1]);
var tags:Object = w[3];
var lat:Number = Number(p[2]);
var lon:Number = Number(p[1]);
var tags:Object = p[3];
node = new Node(id, version, tags, lat, lon);
setNode(node);
}
Expand Down
2 changes: 1 addition & 1 deletion net/systemeD/halcyon/connection/Connection.as
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ package net.systemeD.halcyon.connection {
}

protected function unregisterPOI(node:Node):void {
var index:uint = pois.indexOf(node)
var index:uint = pois.indexOf(node);
if ( index >= 0 ) {
pois.splice(index,1);
}
Expand Down
8 changes: 8 additions & 0 deletions net/systemeD/halcyon/styleparser/ImageLoader.as
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package net.systemeD.halcyon.styleparser {

/*
=== ImageLoader ===
This simply allows us to store a filename in the URLLoader object,
so that the responder knows which image has just been loaded.
*/

import flash.events.*;
import flash.net.*;

Expand Down
16 changes: 12 additions & 4 deletions net/systemeD/halcyon/styleparser/RuleSet.as
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ package net.systemeD.halcyon.styleparser {

public var rules:Array=new Array(); // list of rules
public var images:Object=new Object(); // loaded images
private var iconCallback:Function=null; // function to call when all icons loaded
private var iconsToLoad:uint=0; // number of icons left to load (fire callback when ==0)

// variables for name, author etc.

public function RuleSet(f:Function=null):void {
iconCallback=f;
}

// returns array of ShapeStyle,PointStyle,TextStyle,ShieldStyle
public function getStyle(isPoint:Boolean,tags:Object,scale:uint):Array {
var ss:ShapeStyle;
Expand All @@ -21,8 +27,8 @@ package net.systemeD.halcyon.styleparser {
for each (var rule:* in rules) {
if ( isPoint && rule is ShapeRule) { continue; }
if (!isPoint && rule is PointRule) { continue; }
if (scale>rule.minScale && !isPoint) { continue; }
if (scale<rule.maxScale && !isPoint) { continue; }
if (scale>rule.minScale) { continue; }
if (scale<rule.maxScale) { continue; }
if (rule.test(tags)) {
if (rule is ShapeRule && rule.shapeStyle) { ss=rule.shapeStyle; }
if (rule is PointRule && rule.pointStyle) { ps=rule.pointStyle; }
Expand Down Expand Up @@ -96,11 +102,13 @@ package net.systemeD.halcyon.styleparser {

public function loadImages():void {
var ps:PointStyle;

for each (var rule:* in rules) {
if (!(rule is PointRule)) { continue; }
if (!(rule.pointStyle)) { continue; }
if (!(rule.pointStyle.icon)) { continue; }

iconsToLoad++;
var request:URLRequest=new URLRequest(rule.pointStyle.icon);
var loader:ImageLoader=new ImageLoader();
loader.dataFormat=URLLoaderDataFormat.BINARY;
Expand All @@ -116,9 +124,9 @@ package net.systemeD.halcyon.styleparser {
// data handler

private function loadedImage(event:Event):void {
Globals.vars.debug.appendText("Target is "+event.target+", name"+event.target.filename+"\n");
images[event.target.filename]=event.target.data;
iconsToLoad--;
if (iconsToLoad==0 && iconCallback!=null) { iconCallback(); }
}

}
}

0 comments on commit b79c9d0

Please sign in to comment.