Flash

More Fun with Maps

By Niall Kader1 min read

This article is from the original REM DEV blog (2008–2010). Some of the technologies it covers (Flex, Flash, AIR, JavaFX 1.x) have since been retired.

Runs the original helperMap.swf in your browser with the open-source Ruffle emulator.

Here's a sample that uses the UMap component from www.afcomponents.com.  You'll be impressed when you start digging into the functionality of the UMap.  You can do some really cool stuff with it.

Here's the code...

import com.afcomponents.umap.core.UMap;
import com.afcomponents.umap.styles.MarkerStyle;
import com.afcomponents.umap.overlays.Marker;
import com.afcomponents.umap.types.LatLng;
import com.afcomponents.umap.events.*;
import com.afcomponents.umap.gui.*;
import fl.controls.TextInput;

//starting point is somewhere over Kansas
var inLat:Number = 37.98528600251014;
var inLng:Number = -97.5090485;
var pos:LatLng = new LatLng(inLat,inLng);

//create and initialize the map
var umap:UMap = new UMap();
umap.setSize(stage.stageWidth,stage.stageHeight);
umap.setCenter(pos,4);

var positionControl:PositionControl = new PositionControl();
var zoomControl:ZoomControl = new ZoomControl();

umap.addControl(positionControl);
umap.addControl(zoomControl);

umap.addEventListener(MapEvent.CLICK,getLatLon)
addChild(umap);

//create info box
var markerPosition:TextInput = new TextInput();
markerPosition.height = 20;
markerPosition.width = 400;
markerPosition.move(70,25);
addChild(markerPosition);


// create new MarkerStyle
var style:MarkerStyle = new MarkerStyle();
style.fill = "rgb";
style.fillAlpha = 0.9;
style.strokeRGB = 0x0;
style.strokeAlpha = 1.0;

//create the marker and set it to center of the map
var param:Object = new Object();
param.position = pos;
var myMarker:Marker = new Marker(param,style);
umap.addOverlay(myMarker);

function getLatLon(event:MapEvent)
{
    //remove the previous marker
    umap.removeOverlay(myMarker);
    //get the new lat, lng
    var newPos:LatLng = new LatLng(event.latlng.lat,event.latlng.lng);
    //set the new lat, lng
    param.position = newPos;
    //create the new marker
    myMarker = new Marker(param, style);
    //add it to the map
    umap.addOverlay(myMarker);
    //show the new lat, lng
    markerPosition.text = newPos.lat + ", " + newPos.lng;
}