Posts Tagged ‘as3’

Shapefiles, Actionscript 3.0, and Google Maps (Box Shaped World)

Monday, June 8th, 2009

[Editor's note: Tutorial for using the vanrikom classes to read in shapefiles in Flash and Flex AS3 and display them on a Google Maps mashup.]

Republished from the Box Shaped World blog. 28 April 2009.

I’m working an Adobe AIR application and I wanted to be able to have the user select a shapefile, and then parse it to create a KML file.  I didn’t want to have the user be responsible for creating a KML file.  I thought I might try and crack the shapefile enigma since it is a well documented format, but that would have taken time and I suddenly realized I’m not actually a developer :).  Instead, I found this set of Actionscript Classes to parse a shapefile in Flash.  Unfortunately, I didn’t find a very good tutorial on how to work with the classes.  The example is a little confusing (at least for me) and also uses a far file.  I’d never heard of far compressed files.  So I took the classes and created my own parser.  I thought I would post a tutorial on how to use these shapefile classes in conjunction with AIR and the Google Maps API for flash.  This technique would work with flex as well, I just didn’t want to have to write the code to upload a file.  I presume a few things with this.  The shapefile you are using for this should already have a geographic projection (e.g. latitude and longitude Geographic NAD 83).  In order to use the Google Maps API with AIR, you need a URL with a key associated with it.  Below are two zipfiles available for download.  The is the shapefile I was using.  The is the downloaded actionscript classes from the Google Code repository.  I had trouble downloading the using an svn so I did it manually.  I’ll save you the time by making it available here…unless the original author asks me to remove them.  There are parts that I find confusing with the way the reader was set up.  For some reason polyline inherits from polygon.  Intuitively to me it should be the other way around…but like I said, I’m not a developer.

This was all done using FlashDevelop and the Flex SDK 3.  There are 4 custom classes in addition to the mxml file.  Each are shown here.

Continue reading at Box Shaped World . . .

Mapping Foreclosures in the New York Region (NY Times)

Wednesday, June 3rd, 2009

[Editor's note: The interactive Google Maps mashup in Flash AS3 from the New  York times shows vector overlay of choropleth mapping by census tract and at the street level via dot distribution. As the user zooms in, the dots are revealed, as is a street map. At all levels the census tract summary statistics are available with a mouse over. Zooms are preset for some areas, and the user can type in their own address to zoom to that area. Multiple years add time dimension. Spatial brushing on the map is accomplished by outlining the geography's stroke, not changing the fill color. Thanks Laris!]

Republished from the New York Times. May 15, 2009

A New York Times analysis found that foreclosure rates in the region were highest in areas with high minority populations. Zoom in to see foreclosures at the street level. Screenshot below.

Interact with the original at New York Times . . .




INTERACTIVE GRAPHIC: The Post 200 Database (Kelso via Wash Post)

Wednesday, May 13th, 2009


[Editor's note: Uses the Flare visualization API in Flash ActionScript 3 to display data about the Post 200 companies in a treemap format. A vexing and il-documented API, but powerful. We considered showing the data with a graduated circle map but the company locations were too clustered for that to be effective.]

Republished from The Washington Post.
13 May 2009. By Nathaniel Vaughn Kelso and Terri Rupar – The Washington Post

Use our interactive graphic to explore data — including revenue and employment — for the top companies in the Washington area.

Boxes represent individual companies grouped together by sector, size based on data.

View the interactive version at The Washington Post . . .


ESRI’s ArcGIS Server Provides Foundation for Maryland’s MD iMap (ESRI)

Tuesday, April 28th, 2009


[Editor's note: One of the more useful + powerful sites to leverage new Flash / Flex mashup capabilities of new ArcGIS 9.3 release. The site is designed both for state residents and government policy makers. Thanks Mary Kate!]

Republished from ESRI and State of Maryland. Original Feb. 11, 2009.

Authoritative Statewide Basemap and Performance Measurement Tool Serves Government and Citizens

Redlands, California—Maryland Governor Martin O’Malley recently launched the ArcGIS Server software-based MD iMap, an authoritative online basemap of Maryland that allows government and citizens to assess state, local, and municipal performance. As the portal into the state’s enterprise geographic information system (GIS), MD iMap also provides data to governments throughout the state including seamless, geocoded statewide centerlines and six-inch imagery. MD iMap embodies O’Malley’s vision of “one Maryland, one map.”

“In Maryland, GIS is vital to setting goals, tracking performance, and creating transparency,” said O’Malley. “We have been using GIS for years to increase government accountability and efficiency and to enhance transparency. With one comprehensive and interactive map for Maryland, our citizens will have access to unprecedented information online. From land conservation to public safety, the possibilities are endless when government becomes transparent and accountable to the citizens it serves.”

GreenPrint is the first GIS-based performance measurement application that is accessible via MD iMap. It is a planning tool designed to help government staff, conservation organizations, and individual citizens make good decisions about land conservation and growth. The state’s other performance measurement applications, including StateStat and BayStat, will be added soon.

To support government staff in Maryland, a secure agency login on the MD iMap Web site home page connects users to Maryland GIS Online, which is built with ArcGIS Online. On that site, staff can download data and Web services from other government entities in the state. In addition to significantly enhancing data sharing and coordination, the portal is innovative in its delivery of real-time, up-to-date statistics in one sleek, user-friendly interface.

“Governor O’Malley’s vision of one Maryland, one map, speaks to the best in government including accountability, unity, and service to citizens. It is also an outstanding example of a public and private partnership driving government forward,” said ESRI president Jack Dangermond.

Interact with the original at MDiMap . . .

ActionScript Bezier Curves (Cartogrammar)

Friday, March 20th, 2009

[Editor's note: For those programmers in AS3 wanting to draw pretty curves ala Postscript, PDF, or Illustrator.]

Republished from Cartogrammer. View comments there for updates.
January 5, 2009. Andy Woodruff.

[Andy] finally opened [his] CubicBezier AS3 class, the only reason anyone ever finds this site at all, for the first time in many months to attempt to address some of the various comments and reported problems from the original. It’s not perfected, but [he's] done three things:

  1. Added a “moveTo” argument to the curveThroughPoints method, following the idea in one comment on my blog post. Ignore it if you wish, but if you set it to false, the curves will connect to wherever graphics drawing left off rather than moving to the beginning of the curve and starting anew.
  2. Hooray trigonometry! Messed with some of the angle calculations to fix problems with zero angles and division by zero. I hope it worked.
  3. Provided a line of code that can be altered to use lineTo for straight segments of 3 or more points rather than curving.

Straight lines were raised as an issue in several comments. While I think I have fixed the crazy behavior of straight horizontal and vertical lines, I suspect the result for three points in a line may be surprising at first glance. For instance, the three middle points in the image below are all aligned horizontally.

Straight line with S-curve

The S-curve through those points may look odd at first, but it’s actually to be expected with these cubic Bézier curves. Of those three points, only the middle one has curve control points that are also aligned horizontally. The outer two have control points that are also based on the points outside the line. Here’s an approximate example from Illustrator of what they look like

S-curve in Illustrator

I’ve left that as the default behavior, but I did insert some code that can be modified so that the curve essentially stops curving when it reaches several points in a line, draws a straight line through them, and then continues curving as normal after that. Here’s what the same example looks like with that option enabled.

Straight line with lineTo

It’s probably often fine, but I caution that it can result in sharp corners. Here’s the same with those dots removed:

Straight line with lineTo and sharp corners

I’m uncertain what’s best, so I’ve made that a line of code that has to be changed rather than a more accessible option. I’d be glad to hear ideas on how best to handle it. Feel free to change it however you like, of course. That and other modifications are identified in the comments.

Download the class here:
The previous version is here, in case I screwed something up. Forgive my lack of version control.

Interactive: Obama’s Appointments (Kelso via Wash Post)

Wednesday, March 18th, 2009

[Editor's note: I did the Flash ActionScript 3 programming behind Head Count: Tracking Obama's Appointments. This ambitious, collaborative database-driven project tracks the Obama administration’s senior political appointments and will be kept up-to-date with the latest happenings. A look at some of the interactive features you can find at]

Interactive graphic and database by Sarah Cohen, Karen Yourish, Nathaniel Vaughn Kelso, Ryan O’Neil, Paul Volpe, Sarah Sampsel and Laura Stanton.

This project draws on concepts from these two blog posts in particular: It Ain’t Easy To Get A Newspaper To Provide Useful Data (TechDirt) and The New Journalism: Goosing the Gray Lady (NY Times).

Republished from The Washington Post

Heads Pop Up and Heads Roll: Let’s Keep Track.
By Al Kamen; Wednesday, March 18, 2009; Page A11

Today we launch Head Count, The Washington Post’s interactive database to help you keep a sharp eye on the people President Obama is appointing to the nearly 500 top positions in the federal government that require Senate confirmation. The new feature will not only tell you who they are but also help you count all the demographic beans — age, sex, ethnicity, education (elite schools or not), home states and so on.

At, you can search agency by agency to determine which jobs are still open, should your private-sector job be looking a little shaky these days. You can also search by individual to determine how many officials in this “change” administration are merely retreads from the Clinton days.

And Head Count will give some clues to help answer everyone’s perennial question: How did that fool get that great job? It will also tell you who paid good, hard money or bundled huge sums for Obama/Biden, who worked on the campaign, who had the coveted Harvard Law connection, hailed from Chicago or was a pal of Michelle Obama, Tom Daschle or Ted Kennedy.

The appointments that are tracked by Head Count do not include judges, ambassadors, U.S. attorneys or U.S. marshals. We’ll monitor those separately. Nor does the database include the many important officials who are not confirmed by the Senate. We’ll be tweaking the database as we go, adding new categories, such as veterans, and making other additions.

Loop Fans can help! If you’ve got information we could use or suggestions about how to improve the site, please submit comments and updates at the link provided on the Head Count Web site.


The White House personnel logjam — also known as the Great Daschle Debacle — appears to have been broken. Team Obama’s nominations operation began at a record pace. But IRS problems sparked Health and Human Services nominee Tom Daschle‘s withdrawal on Feb. 3, leading to a general revetting of nominees that stalled everything.

The numbers are startling. Obama, by the end of his first week in office, had announced 47 nominees for senior-most jobs. He’d officially nominated 37 of them, according to data compiled by New York University’s Wagner School of Public Service Presidential Transition Project. (That number includes some holdovers.)

But in the month after Daschle’s withdrawal, the White House announced only 10 candidates for Senate-confirmed positions and formally nominated only six people.

In the next three weeks, however, the pace ramped up sharply, with 42 nominees named. Official nominations have been slower — only 27 during that time. But there were 15 last week, and we’re told there are plenty in the pipeline. As of yesterday, there were 39 Senate-confirmed individuals on the job. (That includes seven holdovers.)

The push now is to get as many nominees up to the Senate — and get confirmation for the three dozen or so already up there — before the Senate slithers out of town on April 3.

View the interactive at The Washington Post . . .

Noncontiguous Area Cartograms (IndieMaps)

Monday, March 2nd, 2009

[Editor's note: Zach Johnson promotes his Actionscript 3 class for producing non-continuous cartograms and gives background on why these are better (and easier to construct) than Gaster-Newman continuous cartograms.]

Excerpted from IndieMaps blog by Zach Johnson.
View full blog post from Dec. 4, 2008.

Fully contiguous cartograms have stretched and distorted borders but perfectly maintained topologies. Like the Gastner-Newman diffusion-based cartograms we see all over the place. Though all sorts of cartogram designs have been produced, those with perfect topology preservation (fully contiguous cartograms) receive the majority of academic and popular press attention.

< snip >

Judy Olson (Wisconsin Geography alum natch) wrote the only academic article to focus specifically on this cartogram symbology in 1976. She believed noncontiguous cartograms held three potential advantages over contiguous cartograms (I’ve three more below):

  1. “the empty areas, or gaps, between observation units are meaningful representations of discrepancies of values, these discrepancies generally being a major reason for constructing a cartogram”
  2. production of noncontiguous cartograms involves “only the discrete units for which information is available and only the lines which can be accurately relocated on the original map appear on the noncontiguous cartogram”
  3. because of perfect shape preservation, “recognition of the units represented is relatively uncomplicated for the reader”

Despite these inherent advantages (along with ease of production), all the early value-by-area cartograms I’ve seen maintain contiguity. Some took the radical step of abstracting features to geometric primitives, like Levasseur’s early French examples (which may not have been cartograms) and Erwin Raisz’s early American “rectangular statistical cartograms”. But in many ways the noncontiguous design is the more radical cartogram, as it actually breaks the basemap apart — rather than skewing shared borders it abandons them.

my [his] AS3 classes

Olson outlines a technique — the projector method — for manually producing such cartograms. A projector capable of precise numeric reduction/enlargement was required, but not much else, and accurate cartograms could be produced in minutes. A scaling factor was calculated for each enumeration unit, the projector was set to this value, and the projected borders were traced, keeping units centered on their original centers.

My [his] AS3 NoncontiguousCartogram class works similarly. It takes an array of objects containing geometry and attribute properties and creates a noncontiguous cartogram. I include methods for creating the input array from a shapefile/dbf combo, but using KML, WKT, or geoJSON representations wouldn’t be too hard. Methods are included for projecting this lat/long linework (to Lambert’s Conformal Conic projection at least). The NoncontiguousCartogram class draws the input geography, figures the area of each feature, and scales figures according to their density in the chosen thematic variable.

It’s all good/in ActionScript 3, so can be used in Flash or Flex. The zip distribution includes the following:

  • the main class
  • two example applications and the data needed to run them
  • utility classes, including some that make creating cartograms from shp/dbf input quite easy
  • Edwin Van Rijkom’s SHP and DBF libraries, which are used to load the shapefiles in both of the included examples
  • Keith Peters’ MinimalComps AS3 component library, for the components used in one of the examples
  • Grant Skinner’s gTween class, which is required by the NoncontiguousCartogram class for tween transitions

Browse all the above or download the zip.


more advantages

In my thesis research last spring, noncontiguous cartograms performed quite well: subjects rated them highly on aesthetics and could locate and estimate the areas of features with relatively high accuracy. I would add the following to Olson’s list of noncontiguous cartogram advantages.

  1. Olson concentrates on the perfect shape preservation of noncontiguous cartograms. The form (well, those with units centered on the original enumeration unit centroids, as in Olson’s projector method) also perfectly preserves the location of the features on the resultant transformed cartogram. Not only are features easier to recognize, but locations within the transformed units can be accurately located as well (cities or mountain ranges from the original geography can be accurately plotted on the transformed cartogram).
  2. Because units are separate on the transformed cartogram, their figure-ground is increased and areas of features can therefore be more accurately estimated.
  3. Many cartogram designs (including most manual cartograms and the Gastner-Newman-produced cartograms) sacrifice some accuracy for shape recognition. This is a defensible tradeoff, especially as area estimation is notoriously inaccurate and nonlinear. Yet it’s a tradeoff that noncontigous cartograms need not make, as they can always perfectly represent the data with relative areas without sacrificing shape preservation.

Thus, noncontiguous cartograms seem to excel at the cartogram’s two main map-reading tasks: shape recognition and area estimation. This is mediated somewhat by the chief advantage of contiguous cartograms: compactness. Because no space is created between enumeration units, contiguous cartogram enumeration units can be larger than those on noncontiguous cartograms, all other things equal. The increased size on contiguous cartograms may improves their legibility.

Read the full entry over at Indie Maps . . .

E00Parser, an ActionScript 3 Parser for the Arc/Info Export Topological GIS Format (IndieMaps)

Monday, March 2nd, 2009

[Editor's note: Zach Johnson promo's his ActionScript 3 class for reading in .e00 GIS files to Flash. Useful for creating cartograms and other graphic representations reliant on topological relationships. Originally posted there Feb. 21, 2009.]

First off, why mess with such a retro format as Arc/Info Export (.e00)?– any code written for this ASCII file type in the last few years has been on how to go from e00 to pretty much anything (especially to the non-topological data format, the shapefile).

Put simply, topological information makes a lot of things possible for the intrepid ActionScripter.

Read more at IndieMaps . . .
Get the code . . .

Mac OS X Mouse Wheel Support for ActionScript 3 Flash Applications (v.2+) (Hasseg)

Thursday, January 8th, 2009

[Editor's note: While Flash is great, sometimes it's omissions are vexing. Notable among them is true mouse wheel support on the Mac version of Flash player. Hasseg introduces a solution.] 

Republished from Hasseg. Originally posted there on April 26, 2008.

In my current job I have been programming user interfaces for applications that display networks of data (as in nodes, links etc.) with the Adobe Flex framework, and the UI paradigm I have been utilizing is a kind of a Zoomable User Interface (ZUI). The idea there is to enable the user to view and manipulate objects on a two-dimensional plane, and navigate around that plane by zooming and panning.

Now, the easiest way (at least for me) to control the zooming is to use the mouse wheel. Mouse wheel support for Flex is implemented by registering an event listener of type MouseEvent.MOUSE_WHEEL with the DisplayObject that would dispatch the event. Sadly, mouse wheel support is not available in the Mac OS X version of Flash Player. This prompted me to create a custom solution, as my main computer is a MacBook and I would like to be able to test the mouse wheel navigation with my development machine. . . .

So I’ve finally updated the solution I’ve made earlier for enabling Mac OS X mouse wheel support in Flex applications to a second version. I didn’t want to continue adding stuff into the original post, so I decided to write a separate post just for this new version. As you can see from the title, this version should work in any Flash project you’re writing in ActionScript 3, as opposed to just in Flex projects. This change was contributed by Pavel Fljot, and all the other stuff I’ve added since have been added on top of that. Deployment should now be a lot easier and some features that were missing in the first version have also been added.

Continue reading at Hasseg blog . . .

Google Earth… in your browser… on your Mac! (Google)

Thursday, December 4th, 2008

[Editor's note: Google Earth web browser plugin finally arrives for Mac, too. See related article about Google Maps for Flash AS3 now working for AIR.]

Republished from Google Geo Developers Blog.

A long time ago, at a conference not too far away, Google launched the Google Earth Browser Plugin, with the Google Earth API. At the time, we promised that we would bring it to the Mac, and now we have.

Today, we’re excited to announce the release of the Google Earth Browser Plugin for Mac OS X 10.4+ (PowerPC and Intel). The Mac plugin is supported on Safari 3.1+ and Firefox 3.0+. The download link should now be available to all users from any Earth API-powered site. We also released a game, Puzzler, in honor of the new Mac plugin. It is, of course, playable on a PC as well. And as usual, it’s open source, so you’re free to adopt the code.

In addition to the Mac release, we’ve also upgraded the Windows version of the plugin. See the release notes for more details.