MapQuest Actionscript 3.0 Learning and Blogging

Just another WordPress.com weblog

6 month revist

OK, well i want to spend a little time talking about the project I just finished with making MapQuest Flash Maps in flex.

Project Refresher:

This project was to bring in demographics data and other informational data per zip code from internal systems, and using those choice zip codes to display zip code polygons on the map, somewhere between 50 and 2100 zip codes, effectively.  The zip codes will be colored based on system or demographics data, whichever the user chooses, and displayed to the user like on might see a weather map on TV. 

Project Hardships:

Multiple Polygons:  Some of the hardships that were found early on while i was learning was displaying a large amount of zip codes.  We found out that we were not able to ask for a certain set of zip codes from MapQuest, so we needed a way to get all of the ones that we wanted to see quickly.  We determined that we should cache them on a local server so we can access them faster and more readily.  The only problem was figuring out how to grab the object once it was cached.  We soon found that using the Feature Collection XML for the code would be appropriate for the storage. 

We started development with that in mind, and it worked well, but it still took a lot of time to get the XML across the wire.  So we used gzip and ByteArrays.  I should mention we have a Java Back-end that makes many calls to cache our data, and then we have a flex front end that uses our chached data.  This data is taken and we had to use a XML processor to make the XML in JAVA, GZIP it and cache it until called.  Once the call is made we bring it in flex, unzip it and write it out.  This was fast but still took some time.  To make it use less time we used the Generalize function, which would then remove some points and make the polygon smaller, but we started getting some serious skew through the straight edges where the zips cross tile lines.  We found a cool project with called JTS(Java Topology Suite)and it would make a single polygon where polys share lines with one another (get rid of those pesky tile lines),so we iincorporated some of that idea in our project.  That turned out beatuiful.  We now can generalize with the JTS as well and get really nice results.  We are still tweaking some things but all in all, incorporating their ideas really saved us. 

Working with Multiple Polygons on the screen:  I had to figure out how to manipulate the zip code polygons on the screen by changing their color, and their outline color as well.  I found that instead of putting them just right on the map, if you use a OverLayCollection, you can just sift through that and change the ones you need.  That works well.

Lack of Polygon Info:  There are some things you just need to know about a polygon, like where it’s furthest edge points are.  I needed to find the north-most, south-most, east-most and west-most points of a poly, i wrote a function to do that, you can see it below in the Find Edges of Polygon posting I did.

Silly programming naming:  I do it to, programmers write names for functions that seem to make sense, and you really have to pay attention to the api, but if you want to get the XML for a object in Flex/Flash, you say object.saveXml(), and that will return the XML to you.  If you want to load an object up with some XML just do object.loadXml(myXmlObj).  Thinking back, that is really pretty clear, that is more of my error.

Not incorporating objects soon enough:  I actually wrote object that deal with a POI.  So if you have tons, instead of doing a batch of them, because they are not all the same probably, or if you have just one, you can fill this object up with an address, or something that resembles and address, and icon, and other information that you want the point to have and then let it go.  It will put itself on the map when it is done.  Also did the similar things to deal with the caching calls.  That way i can break them up and I make one return before the system sends the next one out.  Seems to work well. 

Some sort of limiting factor:  We had something that was going on and when we made a call to mapquest it would return partial XML, not sure why, but it would.  We changed some of the specifics of the call(radius call) like the radius and the number of results, but that didn’t help too much.  We were still a an impass with that.  Having a way to handle it would have been great other than it crashing our systems.

Batch Geocoding:  You can only do a hundred at a time, but i don’t really care now, i do them all one at a time.  I can put about 350 on a screen in around a min.  I wouldn’t want to do this with too many more, but 350 is abnormal for us.  But 350 polygons isn’t, kinda funny.

Seriously Easy Tasks

Getting a map up and running is a breeze, just throw on the tilemap component and that is it.

GeoLocation calls are a breeze, getting that setup and working is also really easy.  I would write a object to do it, one for batches that manages a group of the same type of objects too if that is needed.

TIPS

Connecting to their servers:  When you connect to their server make sure you are using the right password and username.  They are both listed in the account managment part of TRC.  But make sure you use the Registry Passwordnot the password to log into TRC. 

Getting the correct x and y position of the click on the map:  myMap.mouseX,myMap.mouseY  others will work, but only in certain situations, these work constantly.

Items under clicked spot:  myMap.getObjectsUnderPoint(myPnt) as Array  Use that to try to find the type of object you are looking for under your click.  You might need to set a key or some sort of identifier to make sure that you can pick the object contents out of the lineup.

My Wishlist:

Mapquest accept a single call for a zip code.  I can live without it now, but that would make life a lot easier.  Especially when some zip codes are very large, like over 100 shape items, and take up a lot of resource power get get two that might be on different sides of the country.

MapQuest data implement JTS solution to get rid of tile lines, but i do that now too.  It save a lot of time.  Also let us pass in how generalized we might want to get the polys back and generalize them for us before return, that would save MapQuest gigs perhaps.

Lables for Polygons, like where you could see it blended into the polygon.

Summary

Spending the last 8 months working with MapQuest and 6 months on a project, i found that working with the product is really good.  The support is out of this world, and they get back with you on a really quick basis.  Also, I find the map to usually render in a relatively quick time.  Getting the program tweaked to display the items quickly was a difficult 2 month task, i mean really, 2100 zip code polygons is a lot.  Lots of exploration on our part, using gzip bringing it in with Java and out into Flex/Flash.  Having the multiple API accessibility was great, we have a talented group in our office and they saved me some work, and i got to learn some Java in the midst of the project.

 

May 16, 2008 - Posted by mqguru | flash mapping, mapquest | | No Comments Yet

No comments yet.

Leave a comment