DreamingWell Logo

Displaying a Shapefile (.shp) on a Map in Flex

Posted by Travis Collins on June 18, 2008

Using some of my previously covered material, I have created a Flex appication that displays Shapefile (.shp) polygons on a map. This demo includes three different shapefiles that give some information about Brazos County, TX. You'll notice that you can interact with the polygons, change the 'Tile Provider' (yahoo, google, microsoft, etc) and change the dataset (shapefile). The demo also includes a DBF parser to display associated text data with each polygon.

Running Demo

Source Code

ModestMaps Project (Required)

This project makes use of ModestMaps and Vanrijkom's Flashlibs to parse the shapefile and DBF file into objects.

This demo is the beginning of an alternative to ILOG Elixr Maps. However, ILOG's maps come with a wonderful tool that simplifies and converts mapping data to an action-script class. As an alternative, you could use MapShaper.org to simplify your shapefiles into a reasonable dataset for parsing in Flex.

You can find tons of Shapefile data sets at ESRI's Arc Data Repository or GeographyNetwork.com.

I look forward to seeing how the community puts this to use.



hello great job thx a lot :)
im writing a aplication based on Yours.
But I must place all Your xmlm code to as file.
I have done this, the shp file load propertly, the modest map provider centers the map, but.. the shapes doesent draw.
While debuging a I have a this kind of error:
Error #1009: Cannot access a property or method of a null object reference.
at com.modestmaps.flex::Map/addMarker()[C:\Documents and Settings\Travis Collins\My Documents\Flex Builder 3\ModestMap\com\modestmaps\flex\Map.as:353]
at ShapefileExplore/shapefileURLLoaderComplete()[C:\Documents and Settings\KChmie01\My Documents\Flex Builder 3\Projekt\src\ShapefileExplore.as:203]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()

Can You help me??
best Regards Kriss :)

Comment by Kriss at July 25, 2008 4:40 AM

Hi its me again :)
this error I've mantioned befor is dysplaying when program gose to:
modestMap.addMarker(new Location(polygon.box.y,polygon.box.x),newMapPolygon);

in shapefileURLLoaderComplete(event:Event) function.

Comment by Kriss at July 25, 2008 4:59 AM

This is the example is so cool! Wonder if it possible to post an example using just google map for flex?

Thanks for your help.

Comment by EJ at September 24, 2008 9:10 PM

I would be eternally grateful if there were some instructions on how to take ones own shapefile and apply it to this method. I work in the international community and there is a huge disconnect between programmers and geographers that i am tackling. Please let me know if this is possible. Kind regards.

Comment by trekker007 at December 30, 2008 9:17 PM


I am new to flex.

is it possible to remove the modestmp and just use the shapefile and dbf file to show that map and information so that it can be run offline too.


This example requires the modestmap implementation to draw the shapefile. You can use the routines in the example source code to create your own version of the shapefile drawing.

Comment by Anonymous at November 29, 2009 11:59 PM

Post a comment

Remember Me?

(you may use HTML tags for style)

Twitter Status


Last Seen in

Privacy Policy

Copyright DreamingWell.com 1998 - 2011