Ajax Updates |
Interactive Map Script using jQuery Posted: 24 Sep 2009 09:35 AM PDT At the end of last year, we launched a website for Coastal & Marine Sciences in North Carolina with one of our Agency Partners, Liaison Design Group. As a part of the project, the website was supposed to have an interactive map that showed some information and the location of the various Marine Science outposts across the state. The locations would be represented by dots and upon clicking one an info box would pop up and display information about the location. To make the map as engaging as possible, there needed to be smooth animations and crisp graphics. Traditionally such a project would require the use of Flash. We try to avoid Flash whenever possible, so I began to consider how the project could be accomplished in jQuery. There were a number of advantages of using jQuery over Flash for the project: 1. Updates were Easy: Since the map was going to be a visual representation of html, it would be easy to update the data with our Content Management Software. Each location would be a ‘page’ in the system with contents and attributes like pixel coordinates that would be simple to update. My biggest concern using jQuery was performance. An important requirement of the project was that the map should zoom when switching between coastal areas. In Flash this would not be a problem, since transformations like these would be executed at a very low level on computer hardware. This is not the case with jQuery, instead the DOM would need to be manipulated and then displayed. I knew that this could be a struggle for less efficient browers like IE6. Fortunately this turned out not to be a problem in the end. The Five Locations In total, there were five maps that needed to be displayed and roughly 70 location dots. The artwork for these maps was beautifully done by Liaison. The first map would show the entire NC coast and some of the location dots that were not highly concentrated. It would also show 4 highlighted areas that could be clicked to zoom in to the other 4 maps where there were more highly concentrated location dots. In order to simplify the code I had to write, I came up with the following rough procedure to run when one of the five maps was shown: 1. Load the background image With this decided, I just need to come up with the markup for each bullet and a couple of jQuery functions to make it all work. The bullets and info-boxes for each map would follow a convention that allowed some simple jQuery to link the two together:
var coords = $(this).attr('rel').split('-'); The code simply relies on the convention between the bullet link id and the info-box id to select and display the box. At the same time it is sure to close any other infobox popup that may be open. When the NC Coast map is displayed, in addition to the location bullets, there are also four zoomable regions. Like the bullets and infoboxes I settled on a naming convention that made the code much simpler. The id of all of the related elements as well as map images would be derivable from rules. Since it was important not to load all of the images at once for concern about loading time, I placed and sized a simple blank gif over each of the regions: width: width + 'px', cursor: 'pointer' left: '0px' }); You’ll notice that when clicked, the blank image is swapped for the real one and it is resized to match the map and placed in the top left corner. jQuery’s animate function handles these linear transforms with no problem and the map is smoothly scaled into place. It results in a simple yet nifty effect. In this case, jQuery was a great alternative to Flash. Because of the beautiful artwork, the interactive map looks great with the jQuery animations. The potential performance problem was not an issue and the client is able to have control of the maps content without having to bother a web developer. It is great to have the opportunity to work on such a fun project in partnership with a talented designer and a client that is as excited about technology as we are. Be sure to head over to the site to check out the final map and learn more about Marine Science in North Carolina. Related Listings:
|
You are subscribed to email updates from Ajax Updates To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.