Posts Tagged ‘Instance_setMcName’

Instance_setMcName Flash Script + MaPublisher = Flash Interactive Thematic Mapping (Kelso)

Wednesday, April 29th, 2009

charlestonelectionresults

[Editor's note: Making the GIS > Illustrator > Flash workflow a 30 minute process instead of a 30 hour slog. Thanks Sebastian!]

Ken Hawkins, formerly of The Post and Courier newspaper (Charleston, SC) helped me figure out how to take GIS shapefile data (point, line, and polygon) prepped in ArcMap or similar, process it in Illustrator using the Avenza MaPublisher plugin, and then copy-paste import into Flash CS3+ and apply the Instance_setMcName script. I first saw his handywork in the http://www.charleston.net/graphics/200802_primary/ map which is illustrated at the top of this post. I first learned of this technique last year but I think it is still relevant so am posting it now.

Ken had help from Len De Groot over at newsartists.orghttp://www.newsartists.org/forums/showthread.php?p=41780, registration required). I have reformatted and edited Ken and Len’s instructions below.

Requirements:
  • A shapefile,
  • Illustrator CS3,
  • MaPublisher (Illustrator plugin),
  • Flash CS3, and
  • Free command script called “Instance_setMcName”. Before you start, download the script from Adobe, registration required (alternate download, no registration required) and double click file icon to install the script into Flash. Relaunch Flash to enable the script.

Overview:

  • Shapefile prep work in ArcMap GIS as needed.
  • Import the shapefile (.shp) in Illustrator using MaPublisher. Each geographic feature imports as it’s own path object in illustrator, visible in the Layers panel when it is set to not just show top level layers.
  • Use MaPublisher to name each map object’s GIS database attribute to name itself.
  • Import the Illustrator file to Flash .
  • Run the script to take the movieclip names and apply them to instances.

Detailed Workflow:

  1. Shapefile prep work in ArcMap as needed.
  2. Open your GIS shapefile in Illustrator via the MaPublisher plugin (File > Import Map Data).
  3. Edit > Select All the imported map path objects.
  4. Open the MapAttributes panel by going to View > MaPublisher > MapAttributes.
  5. In your MapAttributes panel, use the flyout menu to select Edit Schema.
  6. Select the #Name (usually selected by default) in the list of columns.
  7. Check the box marked “Derive value from expression”
  8. Click the “…” button.
  9. In the resulting dialog’s text entry field, type in the name of the field you want to use to name the individual polygons (county, precinct, etc.). This is case sensitive.
  10. Hit OK twice.
  11. Watch as your individual path objects are named in the Layers panel then save the file.
  12. Open Flash and import the AI file to the stage (File > Import).
  13. In the Import dialog box, select all the sublayers and check the box named “Create movie clip” and hit OK. The map will be imported both onto the stage and each map object will be added to the document’s Library.
  14. In the Library panel, select all the MovieClips in the Illustrator Import sub-folder and drag them up and out of the folders to the top level.
  15. Use Edit > Select All to select all your map object symbols on the stage.
  16. Under “Commands” in the top menu, select “Instance_setMcName.”
  17. All you symbol instances will be named the same as their parent movieClip libary item. Use the Properties panel to verify this.

Both Ken and I have used this process on multiple shapefiles with hundreds of objects and it’s worked like a dream.

Caution on Numeric Names:

Some GIS shapefiles have category names that begin with numbers, which Flash doesn’t like. Flash is picky about some other characters starting off the name, too, so when in doubt, use the following solution.

You can edit the schema to add a letter in front of each name and then use actionscript to do the same to each item in your XML file. A little cloogy but better than the alternative.

  1. Click the Add button in the Edit Schema window in MaPublisher’s Illustrator panel
  2. Name the new column “a”. Make sure the Type is string and enter “a” for the value (the derive value button must be unchecked to see this option).
  3. Press enter.
  4. Select #Name column.
  5. Find the expression field in the same dialog and type out “a&PRECINCT” (where “a” is the “a” attribute column name and PRECINCT is the attribute column name). Note: the & symbol is used to concatenate (add together) the string values in each attribute column.
  6. Press enter.
  7. Verify the name changes in the Layers panel.

Seperate Stroke and Fill Workflow:

To have a seperate stroke layer on polygons so the fills can be color coded seperately from the strokes (which would always maintain the same stroke color) you’ll need to make a 2nd copy of the symbols:

  1. In Illustrator after you’ve used MaPublisher to name all your polygons appropriately, duplicate the layer and hide/lock the original layer.
  2. Give the new polygons a stoke and no fill, and rename them using Steps 3-6 except append the naming scheme with “Stroke”
  3. Import the Illustrator file to Flash. Two groups of symbols are imported.One group’s symbols will be named something like “precinct234″ and the other group’s corresponding symbols will be named “precinct234Stroke”
  4. Flash can now be instructed via ActionScript coding to independently control a symbols fill and whether or not it is “highlighted” with a stroke.

Bonus Feature!

Use MaPublisher to import other GIS layers (roads, polling locations, etc.) and they will land directly on top of the thematic symbols. I recommend doing this in the same import session, or before you rescale the maps. Best results when all GIS shapefiles are already in the same projection.

To set up your XML which is used to import your map data values (essentially an XML version of your DBF file associated with the shapefile), check out Layne’s thread.