README Documentation
Table of Contents
Introduction
This is the README/Documentation for the VGMap library by Eyebeam R&D. Its exists to allow designers, developers, and mapping geeks to create vectorized and/or interactive layers on top of the Google Maps API, using Flash. The VGMap site http://vgmap.eyebeamresearch.org/ gives a more thorough explanation of the reasoning behind the project, so check it out.
Architecture
The very rough architectural layout of VGMap consists of the following (see the Code/Reference section for more detail):
- VGMap Javascript -- Positions transparent Flash layer over Google Map content using DHTML. Instantiates VGMap Flash component with parameters to load user-defined Flash component. Registers for various GMap API event handlers and passes them on to the VGMap Flash component, including parameters of the currently displayed Google Map.
- User Javascript -- Constructs GMap and VGMap objects, calls methods to activate various functionality.
- VGMap Flash (pre-compiled) -- Receives event handlers corresponding to the GMap Javascript API's events, caches current map parameters. Passes events onto user-defined Flash component. Exposes useful utilities for common mathematical functions related to GIS/Mapping and correctly positioning data on the Flash layer to correspond with the underlying Google Map.
- User Flash -- implements GMap API callbacks, does cool Flash-style stuff with data on using Google Maps as base layer.
In the VGMap setup, your custom Flash component that does all the fun drawing/animation/interaction is not actually the root level Flash component. Rather, there is a VGMap Flash component which loads your Flash component as a sub-Movie Clip, and does a bunch of things to allow you to tie into the GMap API. This VGMap Flash component is a 1000px x 1000px Flash component with no visual elements other than your included component.
Please note that the communications between Flash and Javascript are graciously handled by Macromedia's Flash/Javascript Integration Kit. However you will never have to use this kit unless you want to have your own custom communications between Flash and Javascript.
Installation
VGMap functions primarily in the browser/client, so 'installing' it is as simple as downloading the
distribution and unzipping it into your web/development directory. If you want to use the
accompanying ActionScript libraries, you will want to add the vgmap/flash/lib/
directory to your Classpath in the Flash authoring environment.
You will need to sign up for your own Google Maps API Key. Do that here: http://www.google.com/apis/maps/signup.html
Once everything is in place, begin authoring your HTML/JavaScript/Flash content.
The example application provided with this package in the vgmap/example/ directory
should be a good guide to getting started (don't forget to swap in your own GMap API key).
Code/Reference
As described in the Architecture section, The VGMap library consists of Javascript code libraries, a compiled Flash component with utility functions, a set of Flash callback functions to implement.
Javascript VGMap Class
The VGMap Javascript class handles the actual DHTML instantiation of your VGMap
overlay, and the communication between the GMap API and your VGMap Flash component.
-
VGMap (map, mapNodeId, overlayNodeId, vgmPath, debugNodeId)
Constructor, takes the following parameters:-
map: reference to already-createdGMapobject. -
mapNodeId: XHTML DOM Id that was given in the constructor of theGMapobject. -
overlayNodeId: XHTML DOM Id of the<DIV>element that will house your VGMap overlay. -
vgmPath: relative URL path to the directory housing your installation of theVGMaplibrary. Most commonly will be'vgmap/' -
debugNodeId: XHTML DOM Id of the element where debug messages from the Flash components will be printed. This parameter is Optional
-
-
go (offset, flashFile, flashVars)
Method to go ahead and write/run your VGMap overlay. Takes the following parameters:-
offset: size (in pixels) of the area between the border of the GMap and the VGMap overlay. This exists because the VGMap overlay prevents standard mouse events from getting through to the GMap. Typical setting, which is maximally sized but does not overlap any of the GMap controls is 46. -
flashFile: URL path to the flash file that will handle the V/GMap callbacks and do all the fun data-drawing. -
flashVars: URL-encoded parameters to be passed to the above Flash component when it is instantiated.
-
VGMap Flash Component
-
Map State:
The VGMap Flash components give your ActionScript access to the GMap's current state. It maintains a nested data structure that has the same following attributes as the
get*methods of theGMapobject: http://www.google.com/apis/maps/documentation/#State-
centerLatLng
Same values as would be returned by thegetCenterLatLngmethod in the GMap API
An object withxandyattributes representing the longitude and latitude, respectively. -
boundsLatLng
Same values as would be returned by thegetBoundsLatLngmethod in the GMap API
An object with[min|max]Xand[min|max]Yelements representing the minimum and maximum longitude and latitude, respectively. -
spanLatLng
Same values as would be returned by thegetSpanLatLngmethod in the GMap API
An object withwidthandheightelements representing the longitude and latitude spans, respectively. -
zoomLevel
Same value as would be returned by thegetZoomLevelmethod in the GMap API
The currentzoomLevelfrom 0 to 17.
In the VGMap Flash component, all references to a 'map' variable refer to an object with the above structure.
-
-
VGMap GMap API Event Callbacks:
Your custom Flash component that is dynamically loaded by the VGMap Flash component will get callbacks corresponding to (most of) the
Eventcallbacks in the GMAp API: http://www.google.com/apis/maps/documentation/#Events_GMap.
All of the parameters are the same as in the GMap API, except that your callbacks all have an additional 'map' parameter (as described above) as the first argument.-
GMap_click(map, point, overlay) -
GMap_movestart(map) -
GMap_move(map) -
GMap_moveend(map) -
GMap_zoom(map, oldzoomlevel, newzoomlevel)
-
-
VGMap Flash Component Utility Functions:
The VGMap Flash Component has a number of 'methods' that are available to be called directly on the component itself. Typically these will be called on the
_rootor_parentmovie clip.- Math/Mapping:
To do your mapping correctly, there is always some math that has to get done. We have tried to simplify this process by providing utility functions and libraries, but the documentation for how to use them will be woefully inadequate here. Your best bet is just to look at the code in the
vgmap/example/directory, specifically thell.asfile.A note on geographic projections: the VGMap includes libraries for handling 3 geographic projections:
-
merc: converts between lat/long and the Mercator Projection. -
projmerc: converts between lat/long and the Mercator Projection as used in the Proj4 library. -
latlon: the null transformation.
For more on these projections, please see the code in the
vgmap/flash/lib/gis/projections/directory.Michal Migurski of Stamen Design has put together a great presentation that explains a lot of the GIS projection/transformation issues. Highly recommended, it is available at http://clients.stamen.com/talks/ffnyc/.
Enough blabbing, on with the documentation:
-
getCurrentMap()
Get the current 'map' (as described above). -
getGMapImgBounds()
Get the bounds of the underlying Google Map image, in the coordinate system of the Flash component
Returns: object with[min|max]X,[min|max]Yattributes. -
getGMapProjectedBounds(map, proj)
Get the bounds of a map in a specified geographic projection. -
createProjector(proj)
Create an object for a specified geographic projection. This object will implement theILinearProjectioninterface which, as defined invgmap/flash/lib/gis/projections/ILinearProjection.as, consists of two methods:-
GPSToMapCoords(lat, long)
Takes Latitude and Longitude as parameters, and returns an object withxandyattributes. -
MapToGPSCoords(x, y)
Takes X and Y as parameters, and returns an object withlatandlongattributes.
-
-
solve2D(e1, e2)
Solve the 2D linear equation to scale/translate from one linear system to another.
Parameters: 2 objects, each with afromandtoattibute.
Returns: object withscale, translation, andfuncattributes which are the scale, translation, and functional transformation between thefromsystem and thetosystem.
-
- Flash/Javascript Communications:
-
createJavascriptProxy(lcId)
Create a JavascriptProxy object from the Flash/Javascript Integration Kit. Use this if you want to communicate between your Flash Component and Javascript executing in the browser in ways that are separate from the GMap API. Since this requires anlcId, you will want to create that in Javascript and pass it in as part of theflashVarsparameter of thegomethod on theVGMapJavascript object.
-
- Math/Mapping:
- Debugging:
-
debugMsg(msg, clear)
Send a themsgstring out to the XHTML element specified by thedebugIdparameter to the VGMap Javascript Class' constructor. The optionalclearparameter will cause the debug element to be cleared before adding this message. -
traceObject(obj)
Recurse over a nested data structure and trace it out, also return it as a string.
-
Bugs/ToDo
It ain't perfect!!! The following are bugs/issues/todo for the VGMap library. Anyone who wants to help should get in touch with me at mfrumin@eyebeam.org
- Mouse events get gobbled by the VGMap overlay.
- Add in the rest of the GMap API event callbacks.
- Add the ability to make calls to the GMap API from Flash (eg.
centerAtLatLng,zoomTo, etc.). - Can the packaged methods on the VGMap Flash component be put on a namespace, instead of on the _root movie clip?
- Only works for square maps with equal offsets on all four sides, I think!
- Add ability and code/math examples to handle dynamic map-resizing.
- The Flash plugin for Linux does not seem to want to be transparent, so this is not gonna work with linux desktops for now.
Toolbox
- Google Maps API
- Flash
- Flash/Javascript Integration Kit
- Geo::ShapeFile
- SWF::Builder
- geocoder.us
- MGeocoder
- Putting Data on the Map (code)
Credits
This is a project by Eyebeam R&D
It was conceived and executed by Michael Frumin, R&D Technical Director at Eyebeam.
He owes great thanks for unending flash knowledge and support to Michal Migurski and the whole Stamen Design team. In particular, the knowledge and code from Migurski's Putting Data On The Map presentation.
License
As with all Eyebeam R&D projects, this library is released under the GPL, though some of the included code may not be. Please see the LICENSE file in this directory for more details.
