Development Blog

A jQuery Plugin for Zoomable, Interactive Maps

What is it and why was it built?

A couple of months ago we launched a site about Marine Science in North Carolina with one of our design partners, Liaison Design Group. A key part of the project was an interactive map that allowed visitors to find important Marine Science resources in North Carolina.

Each location on the map would be represented by a bullet. Clicking the bullet would bring up more information on the location. Since the locations of the bullets tended to be highly clustered, zooming into select subregions was possible.

We wanted the experience to be engaging as possible but also easily updatable in the future. We settled on jQuery as the interface technology to use as it made it simple to build, display and animate the map. I did a longer writeup on the detailed mechanics of how this worked two weeks ago in one of our most popular posts. Due to the great feedback we got on it, this is a follow-up with a revised version of the code as a jQuery plugin which should make it easier to integrate into other projects.

Demos

This project is being used in production on a number of sites. Below is a listing of a couple. If you have used this in a project you would like to see listed, let me know.

NC Marine Science Sici.org Raleigh Photonics
interactive map interactive map interactive map
Liaison Design Shadowbox Creative Liaison Design

Documentation

Limitations

This was originally developed for one project with very specific requirements. While I have taken the time to generalize that code into a plugin, I have not made it as generic as I would have liked and will do more in the future to improve it given enough interest. Here is a list of its current biggest limitations:

  • Data Required In Plugin Setup - Ideally all of the required data would be stored in the html pages that drive the bullets. This would allow a CMS to more easily generate additional depth levels without needing to play with the javascript. All that is required in the js now is an array of the sub-regions along with their dimensioning data.
  • Data Accessibility Unaddressed - The plugin currently does nothing on its own to make content available to search engines and those with disabilities. This is left up to the developer to do, though it shouldn't be too challenging since the plugin requires all of the data to be expressed in html.
  • API - Right now it is impossible to programatically interact with the map once it is launched. Eventually it will have a simple API to assist in navigation and other manipulations.

Even with these limitations, this is ready for production and is being used on several sites as seen above in the demos.

Instructions

There are four main components required to make the plugin run: the background images, links to pages that contain html data in the correct format, some CSS for style and finally the plugin call. Below are instructions on each.

1. Background Images

There are very limited requirements on the background images:

  • They must all be the same size. Sub-region background maps grow to fill the entire map area
  • They should line up. Just prior to zooming, a sub-region map is placed over an area of the main map, if this doesn't line up properly, some of the zooms effect will be lost.
  • The main map should highlight the zoomable regions. The plugin does not otherwise make these obvious. (Though the css could be edited to add a border or background image to the zoomable region.)

2. HTML Data

The plugin assumes a certain structure for the html data it loads via AJAX. As long as the basic structure is kept, a developer is free to add any type of content styled however they would like. Aside from the unavoidable requirements imposed by the animation, all style is isolated to CSS.

The HTML format contains information for the location and applied class of the bullets, a convention based link between the bullets and the pop-up content and the content itself. The html returned should just be a listing of the bullets and popups in the following format:

 
 

[POPUP-ID] should be unique for each bullet/popup. The jQuery uses this along with the "-box" convention to open the correct popup when a bullet is clicked.

3. CSS Style

As much as possible, the plugin is designed to operate exclusively on the DOM, leaving styling up to CSS. A basic css file is included with the demo zip. Here is some rough minimal css:

#map { position: relative; width: 700px; height: 470px; overflow: hidden; }
#returnlink { display: block; position: absolute; bottom: 0; right: 0; }
#map a.bullet { display: block; position: absolute; width: 10px; height: 10px; background: yellow; }
#map img.zoomable { }
#map div.popup{ display: none; position: absolute; width: 200px; height: 300px; }
#map div.popup a.close{ display: block; position: absolute; bottom: 0; right: 0; }

The code above will work just fine as a starting point. Obviously a lot of embellishment can be added to make the map look as good as the one's Liaison designed in the examples. Here are some things to note:

  • The main '#map' container must be positioned absolute or relative.
  • Popups must have 'display: none' set to make sure they don't flicker when they are loaded.
  • Popups must be positioned using CSS. The jQuery only shows/hides them.

4. jQuery Plugin Call

The last piece that needs to be put in place is a call to the jQuery zoommap plugin that makes it all happen. In the call, we must pass the in some settings as well as a data structure that sets up the map and its different zoom levels. Here is a call for a simple two level map that contains all of the possible settings:

$('#map').zoommap({
	// Width and Height of the Map
	width: '500px',
	height: '580px',
		
	//Misc Settings
	blankImage: 'images/blank.gif',
	zoomDuration: 1000,
	bulletWidthOffset: '10px',
	bulletHeightOffset: '10px',
	
	//ids and classes
	zoomClass: 'zoomable',
	popupSelector: 'div.popup',
	popupCloseSelector: 'a.close',
	
	//Return to Parent Map Link
	showReturnLink: true,
	returnId: 'returnlink',
	returnText: 'return to previous map',
	
	//Initial map to be shown
	map: {
		id: 'campus',
		image: 'images/campus.jpg',
		data: 'popups/campus.html',
		maps: [
		{
			id: 'quads',
			parent: 'campus',
			image: 'images/quads.png',
			data: 'popups/quads.html',
			width: '200px',
			height: '232px',
			top: '18px',
			left: '176px'
		}
		]
	}
});

Here is a breakdown/description of each of the settings:

  • width/height - The width and height of the map container.
  • blankImage - Path to an (transparent) image that will be used over the zoomable regions until their map is loaded.
  • zoomDuration - Duration in milliseconds of the map zoom effect.
  • bullet(Width/Height)Offset - Offsets that allow the coordinates of the bullets to be placed in the center of the target, rather than the corner.
  • zoomClass - Class that should be applied to the zoomable region imgs.
  • popupSelector - Selector the plugin should use to find the popups in the html
  • showReturnLink - Whether a return link should be shown on child maps
  • returnId - Id to use for the return link.
  • returnText - Text to be placed in the return link.
  • map - The top level map that should be shown.

Additionally each map has the following properties and can infinately nest more maps:

  • id - Id that should be used for the zoomable region.
  • image - Path to the image that should be used for the map. This image should be large enough to fill the entire map space.
  • data - Path to the html data for the maps popups and bullets.
  • width/height - Width and height of the zoomable region.
  • top/left - Absolute position of the zoomable region
  • maps - Children maps.

Here is a minimal call that relies on the default settings:

	
$('#map').zoommap({
	width: '500px',
	height: '580px',
	blankImage: 'images/blank.gif',		
	map: {
		// Map structure
	}
});

And here are the default settings:

	
settings = $.extend({
	zoomDuration: 1000,
	zoomClass: 'zoomable',
	popupSelector: 'div.popup',
	popupCloseSelector: 'a.close',
	bulletWidthOffset: '10px',
	bulletHeightOffset: '10px',
	showReturnLink: true,
	returnId: 'returnlink',
	returnText: 'Return to Previous Map'
}, settings);

Download the Project Zip

View the project Demo or download the project zip.

Questions/Comments?

This project will be revised in the future and is certainly open to suggestions. If there are any suggestions or questions, please leave them in the comments.

Categorized in: ,

About the Author

Joel Sutherland

Joel Sutherland leads operations at NMC where he has launched over 250 sites and served as lead developer on the company's CMS which serves millions of unique visits each year. Joel has an Honors Degree in Computer Science from UNC Chapel Hill where he was a Morehead Scholar. Follow Joel on Twitter.

Thanks for Reading

We appreciate your support. If you liked this article, please share it with others.

Comments

Leave a Comment
  1.  Geof Harries

    Geof Harries

    June 19, 2009 11:34 AM | Permalink

    Thank you for sharing the code and documenting it so thoroughly. I started down the path of reverse engineering what you'd already written, but it was taking way too much time ;)

  2. Joel Sutherland

    Joel Sutherland

    June 19, 2009 11:39 AM | Permalink

    Let me know if you have any trouble with this Geof -- I'm happy to help! Also be sure to share your project once it is up and running.

  3.  Josh

    Josh

    June 19, 2009 12:07 PM | Permalink

    This is an awesome effort, thankyou for making it!

  4.  Kevin

    Kevin

    June 19, 2009 12:22 PM | Permalink

    Plugin is very nice and easy to set up but I've had inconsistent results of using the hash in the url. It seems to work for the first area sporadically and not at all for the other areas.

  5.  Joel Sutherland

    Joel Sutherland

    June 19, 2009 12:36 PM | Permalink

    Kevin,

    Is there any way you could zip your project and send it to joel@newmediacampaigns.com along with a description of the issues you are having? I'll look into it and get back to you.

  6.  Keonne

    Keonne

    June 19, 2009 5:43 PM | Permalink

    Very nice. Can this script be used commercially? If so, please get back to me with licensing terms and conditions.

    Keonne

  7.  Joel Sutherland

    Joel Sutherland

    June 22, 2009 10:20 AM | Permalink

    Kevin,

    I've sent you an updated script that allows for hashs in the url. I've also updated the zip file on this post.

  8.  Steve

    Steve

    July 07, 2009 1:51 PM | Permalink

    I am almost finished implementing the map plugin, I am having a problem with a 3rd level map where the return link does not work.

    See: http://savourmuskoka.com/map

    Click the top right sector and then click on Huntsville on the next map, the return link does nothing?

    Thanks..
    Steve

  9.  Pratik

    Pratik

    July 08, 2009 3:02 AM | Permalink

    Hello everyone,

    Somebody Help me out for problem....
    The given example runs fine on my PC... but when I uploaded it to server (Linux), the bullets did not appear. uploaded examples link is http://www.ushawoods.com/test/u2/example.html

    Thanks

  10. Joel Sutherland

    Joel Sutherland

    July 08, 2009 9:39 AM | Permalink

    @Steve I will take a look at this and let you know what I find.

    @Pratik It looks like the bullet data is not loading. Try checking your paths.

  11.  JPS

    JPS

    July 08, 2009 3:08 PM | Permalink

    @Pratik and @Joel,

    Im having the same problem. Just as a test I simply uploaded the demo, didnt change the file structure at all. No bullets.

    http://eleph.us/zoommap/example.html

    Despite that, great work Joel!

    JPS

  12.  Luther

    Luther

    July 09, 2009 11:41 AM | Permalink

    Hi,
    congratulation for this great work, but... there is a little problem with internet explorer...

    If you click and zoom an area, then return to map and reclick again the area, it doesn't work.
    You must to close and reopen the browser if you want to work on it...

  13.  Steve

    Steve

    July 09, 2009 7:43 PM | Permalink

    @Joel - Just in case my email is: sts at ihosttech.com

  14. Almar

    Almar

    July 10, 2009 4:11 AM | Permalink

    Absolutely love this kind of map. Got it to work fine, however I run into a problem with the Safari browser, similar to what Luther above mentions for Internet Explorer:

    Click and zoom into an area, and the bullet data shows up. Zoom out, click another area, zoom in and bullets show up. Move to another site/page, then return to the map. Click the same zoomable areas again and there are no more bullets.

    It looks like it only happens with Safari, I do not experience problems in other Browsers.

    Keep up the good work!

  15.  Dean

    Dean

    July 10, 2009 5:32 AM | Permalink

    @Pratik and @Joel and @JPS

    first of all a big thanks for making this map

    i'm having the same problem as Pratik and Joel and JPS

    you can change the paths to images no problem but if you change the paths to the bullet html/data they don't show up

    any ideas what can be tweeked to fix this? or am i doing something wrong? i checked the paths carefully

    regards

    dean

  16. Joel

    Joel

    July 10, 2009 9:39 AM | Permalink

    @all I am on the road today through Monday. Ill look at these issues and let you know what I find early next week.

  17.  dean

    dean

    July 14, 2009 8:30 AM | Permalink

    thanks joel - it would be a big help

    also (and i know i'm being super cheeky here) - i can't seem to work out how to add another zoom map region on the main map

    do i just add the code to setup.js file in this bit?

    //Initial Region to be shown
    map: {
    id: 'uk',
    image: 'images/uk.jpg',
    data: 'popups/uk.html',
    maps: [
    {
    id: 'scotland',
    parent: 'uk',
    image: 'images/scotland.jpg',
    data: 'popups/scotland.html',
    /*click/zoom area size and placement*/
    width: '100px',
    height: '100px',
    top: '0px',
    left: '0px'
    /*click/zoom area size and placement ends*/
    /*More maps can be nested
    maps : [ ] */

    }

    if there's any way you could give a bit of guidance (or code) i'd be forever in your debt

    dean

  18.  dean

    dean

    July 14, 2009 10:30 AM | Permalink

    scrap last comment - worked it out - was missing a comma between maps! doh!

  19.  chris

    chris

    July 16, 2009 3:54 PM | Permalink

    Great work.. just wanted to ask about IE6 compatibility?

    I want to incorporate this at my work, and unfortunately we still have a lot of IE6 users.

    When you click into a zoomed map, then click back out, the original map disappears.

    Otherwise this is a great product! Very useful.

  20.  dean

    dean

    July 17, 2009 7:18 AM | Permalink

    unfortunately this map does not work in ie6 ie7 or Opera (mac and pc)

    the linked to project does at the marine science site

    but this demo does not

    shame - just spent 3 days working on it

  21. Joel Sutherland

    Joel Sutherland

    July 20, 2009 9:11 AM | Permalink

    @chris @dean

    The bug with the original map background image disappearing in IE6 has been corrected. The zip has the updated files.

  22.  steve

    steve

    July 20, 2009 12:26 PM | Permalink

    @Joel - Any luck with figuring out why my 3rd level maps won't work with return link?

    Thanks! - Steve

  23. Kyle

    Kyle

    July 21, 2009 9:46 AM | Permalink

    I seem to be having a problem on some of the maps (including my own) in IE 7+, (it behaves as expected in FF3..), where the initial zoom works fine, but after returning to the original map and trying to zoom again, nothing happens, typically.. the zoomable area and bullets disappear..

    Great plugin though, its working out great other than this
    Thanks!

  24.  Kyle

    Kyle

    July 22, 2009 9:36 AM | Permalink

    @all

    For anyone experiencing the problems in my post above, and to notify Joel of my changes/solution, I was able to solve the issue by slightly modifying the plugin.

    jQuery Documentation on element load event:
    Note: load will work only if you set it before the element has completely loaded, if you set it after that nothing will happen. This doesn't happen in $(document).ready(), which jQuery handles it to work as expected, also when setting it after the DOM has loaded.

    Working under this assumption, i modified the plugin to wire up the zoom image load events before applying the the source images on a zoom..

    Original Code:
    $(this).hide()
    .attr('src',region.image);.load(function(){
    $(this).fadeIn('slow').animate({
    ...existing code...
    displayMap(region); }); });

    Modified Code:
    $(this).load(function(){
    ...existing load code...
    });
    $(this).siblings().fadeOut();
    $(this).hide().attr('src', region.image);

    Of course this should be tested a little more thoroughly, but it seems to work for me well so far.. Definitely a relief to get it working reliably in IE! :-)

    Thanks!

  25. Kyle

    Kyle

    July 22, 2009 3:54 PM | Permalink

    I also made a few other minor changes, such as allowing the user the ability to choose what corner the returnLink shows up in, etc... I will send you the new plugin soon for you to consider the changes :-)

  26.  Joel Sutherland

    Joel Sutherland

    July 23, 2009 3:26 PM | Permalink

    @Kyle Send it over and Ill take a look. I am also planning on adding a couple of other changes that could make using the map handier.

  27.  Joel Sutherland

    Joel Sutherland

    July 23, 2009 3:27 PM | Permalink

    @steve Things are testing fine for me here. Could you send over a zip of your project and Ill take a look.

  28.  jbar

    jbar

    July 27, 2009 8:47 AM | Permalink

    hi. i have the basic problem of creating child maps in the setup.js

    Do i replicate the map:{} code or maps : [{}]? Tried the latter but the page turned blank..changed even the maps : [id: field]
    someone pls help!

  29.  jbar

    jbar

    July 27, 2009 8:57 AM | Permalink

    fixed my problem..have a new one..I am able to access only one map outta four though ive changed the map id and image location

  30.  graeme

    graeme

    July 28, 2009 6:50 AM | Permalink

    A strange one here.
    I've created pins for the clickable popup data. They show up fine on my machine and also in localhost. When I upload to webserver the pins don't show and i can't click the areas.
    This is an annoying problem since it seems so simple.
    Help?

  31. Juan

    Juan

    July 29, 2009 2:46 PM | Permalink

    I managed to fix the pins that were not showing up by just renaming the html files inside the popups folder to php

  32.  Pratik

    Pratik

    July 30, 2009 12:55 AM | Permalink

    @Juan
    your solution worked for me .. :) Thanks

    @Joel
    Thanks for your efforts.

  33.  Ben

    Ben

    August 10, 2009 5:31 AM | Permalink

    Top marks for your efforts here, great job Joel! My question is... how can I remove the extra map levels. i.e. I want to have a map that only has clickable bullets with info popups. Cheers.

  34.  Ben

    Ben

    August 10, 2009 6:56 AM | Permalink

    Forget my last comment. Got it! Much respect to ya.

  35. aLI

    aLI

    September 19, 2009 8:55 AM | Permalink

    Hi;
    I want to duplicate Initial map to show 2 place can be zoom.

    I don't know where I should put the codes,

    can you tell me what should I do?

    Regardes

  36. Ragdoll

    Ragdoll

    September 21, 2009 1:31 PM | Permalink

    Ben, I'm trying to do the same thing. If you are still reading this, can you share how you did this?

  37. Joel Sutherland

    Joel Sutherland

    September 21, 2009 1:39 PM | Permalink

    Ben and Ragdoll,

    Just set "maps" to a blank string or empty. That should do the trick.

    Ragdoll -- Nice to see your connection to Arbor Day. I am originally from Nebraska!

  38. sam ambrose

    sam ambrose

    September 21, 2009 4:35 PM | Permalink

    joel-
    I am still getting the IE6 background image bug... I downloaded the zip file listed above (and have read through the comments) but in IE6 the background disappears when you click to return to the main map.

    Any help would be awesome!

  39. Ragdoll

    Ragdoll

    September 22, 2009 2:30 PM | Permalink

    I have two things: one bug and one that may be helpful to others.

    1) Like sam ambrose, above, the background disappears in IE(6&7) when I return to the main map.

    2) I solved my first problem I mentioned earlier in the comments. I'm not sure if Joel's explanation works, but here is what I did. Since none of my maps will ever have bullets, I commented out the "//place bullets" code inside loadRegionData, and then after the "//Create Return Link" code, before the closing load bracket, I added "showPopup($(region).attr('id'));"

    You still need both the <a> and the <div> in the HTML data, though you'll want to use CSS to change the <a>'s visibility to "hidden". You don't have to put all the HTML data in individual files; you can put them all in a single file, as long as everything has its own name.

    Hopefully this helps somebody in the future.

  40. sam ambrose

    sam ambrose

    September 23, 2009 9:39 AM | Permalink

    Does anyone have a solution to the IE6 background 'houdini'?

    I am 90% done with launching a new subsite and the map is essential... but like everyone who designs/develops I fall victim to the IE majority when it comes to our target audience.

  41. Joel Sutherland

    Joel Sutherland

    September 23, 2009 9:42 AM | Permalink

    Sam,

    Could you send me a link to the site you are working on. I will take a look and see what I find. There are a number of deployments out there working great in IE so it is probably something small.

  42. Matt

    Matt

    September 23, 2009 1:30 PM | Permalink

    Joel:

    I just finished an implementation of your plugin, which is really great, as a building map, but IE6 is a problem.

    The map is for a public library.
    http://www.westlakelibrary.org/?q=wpplmap

    My IE6 issues largely have to do with transparencies. I have a hovering transparency for the different regions of the building, and I used blank images linked to popups for rooms and things that weren't suited to the bullets. I'm using transparent pngs. Should I switch to transparent gifs? (maybe not in the scope of your plugin, but thought I'd ask.).

    Thanks for your work. I aim to make another building map for staff as a safety training tool.

    Matt

  43. Joel Sutherland

    Joel Sutherland

    September 23, 2009 1:35 PM | Permalink

    Matt,

    Gifs will be easier. There are complications using 24-bit pngs in IE6 -- especially when they are being created and destroyed.

    You can use them, but if you can get away with gif files I would suggest it.

  44. Sam Ambrose

    Sam Ambrose

    September 23, 2009 4:32 PM | Permalink

    Joel-
    I've downloaded the zipped folder(above), extracted and placed on the server.

    Here is the url- http://lcmsdistricts.org/zoommap/example.html

    thx in advance

  45. sam ambrose

    sam ambrose

    September 23, 2009 4:36 PM | Permalink

    Matt-
    Sorry for the delay...

    My link is- http://www.lcmsdistricts.org/zoommap/example.html

    I also noticed your demo has the same IE6 bg problem-
    http://www.newmediacampaigns.com/files/posts/interactive-map/zoommap/example.html

    thanking you in advance

  46. Ragdoll

    Ragdoll

    September 28, 2009 11:36 AM | Permalink

    Has anybody figured out the IE Houdini Bug, yet? I've got a project that is finished except for this problem. I'd love to hear any possible solutions.

  47. Ragdoll

    Ragdoll

    September 30, 2009 12:03 PM | Permalink

    This might help get closer to the solution, but JavaScript isn't my strong suit, so I don't exactly understand what's going on here.

    In the displayMap function, there is a variable set called "check", which isn't used anywhere else in the code. Check checks the css background-image. If you put "alert(check);" after this, the background will show up along with the alert.

    Why would this happen? Oh IE, why can you never play nice?

  48. Joel Sutherland

    Joel Sutherland

    September 30, 2009 12:31 PM | Permalink

    So does that solve it? If so be sure to send over your changes and I will update the plugin.

  49. Ragdoll

    Ragdoll

    September 30, 2009 5:51 PM | Permalink

    It doesn't really solve the problem, because then you have an alert going off every time a new background is set.

    But I don't know why IE won't set the background otherwise.

    I notice it works fine on Sici.org, but they also have the backgrounds fade in and out, which your plug-in does not. I'm going to try to incorporate this into my own code, but I need some time to figure out how to make it work; Sici's code is a little bit different, and I haven't figured out how to duplicate it with what I have.

  50. Mauko Quiroga

    Mauko Quiroga

    October 03, 2009 3:30 AM | Permalink

    Joel,

    Recently a client contacted me for a web-related job that includes an interactive map, so your post really help me a lot.

    Here goes my question: In order to catch dynamic data, How'd you do it?

    The facts: You have a CMS relational db with "customers" and "events" published by them ("tomorrow 10% disc. on pizza"), and I want the map to grab the customer data AND the events associated.

    Would you mess directly with database, middleware or framework? Or let the CMS to generate the html on load before jQuery grab that data?

    It will be a charm if you can tell me your opinion about that, since the work you've done seems to be the best aprox. to the solution i was thinking.

    Thank you in advance,
    Mauko Quiroga

  51. Joel Sutherland

    Joel Sutherland

    October 05, 2009 8:27 AM | Permalink

    Mauko,

    The data is already being loaded via AJAX. So all you need to do is make sure that your CMS is generating the pages dynamically and you will be good to go!

    Joel

  52. Mina.

    Mina.

    October 06, 2009 10:11 AM | Permalink

    Dear Joel,

    Thank you very much for this great plugin. I am actually building a site and I am trying to use it. Actually, I'm a big novice in java and I only manage to change some elements... I am using the bullets but I also would like to use some bigger "zones" that would have the same effect (same type of popup appearing).
    I tried to create a #map a.zone in the css file but it didn't work... Or is there a way I can do it through the setup.js by changing the 'quads' part? I don't need the zoom, just a popup.

    Thank you for your help!

  53. Joel Sutherland

    Joel Sutherland

    October 06, 2009 11:57 AM | Permalink

    Mina,

    You can control the size of the bullets using CSS. You can even control them individually using their ids.

    Joel

  54. Mina.

    Mina.

    October 06, 2009 6:59 PM | Permalink

    Joel,

    Thank you, I've finally managed to do it! (that was just a simple thing I had to change)
    Now I have another problem - sorry to bother you, I guess this is just a simple thing I have not done correctly again but I've been spending hours without figuring out what it could be : the plugin works fine but my other divs now get crazy. The size of the text is automatically reduced and I don't know why.

    If you have time to take a look, I have given the direct link to the page. Thanks again.

  55. Ragdoll

    Ragdoll

    October 07, 2009 12:32 PM | Permalink

    I figured out the IE Houdini bug!

    It works in all browsers without being noticeable to the user, but boy is it ugly.

    In my previous comment, I said that adding an alert will cause the background to display, which leads me to believe it's some kind of redraw issue for this awful browser. So in order to force a redraw without the nuisance of alerts popping up all the time, just add the following code after the check variable:

    //This mess addresses the IE Houdini Bug.
    map.css('display','none');
    map.css('display','block');
    map.css('display','none');
    map.css('display','block');
    map.css('display','none');
    map.css('display','block');
    map.css('display','none');
    map.css('display','block');
    map.css('display','none');
    map.css('display','block');
    map.css('display','none');
    map.css('display','block');
    map.css('display','none');
    map.css('display','block');
    map.css('display','none');
    map.css('display','block');
    map.css('display','none');
    map.css('display','block');
    map.css('display','none');
    map.css('display','block');
    map.css('display','none');
    map.css('display','block');
    map.css('display','none');
    map.css('display','block');
    map.css('display','none');
    map.css('display','block');
    map.css('display','none');
    map.css('display','block');
    map.css('display','none');
    map.css('display','block');
    map.css('display','none');
    map.css('display','block');
    //Clean-up in aisle 8.

    Yep, 15 display switches in a row, will cause IE6–8 to show the map correctly. I don't know exactly how it works, but fewer than 14 will not fix the bug in 8, somewhere between 2 and 9 will not fix the bug in 7.

    I did not notice any flicker or other problems in my testing, which was: FF3.5, IE6-8, Safari.

    If anybody knows a better way to force a redraw, or finds a better solution, I am more than open to ideas.

    Tangentially, in my extensive searching and troubleshooting, I managed to comment out quite a few lines of code that didn't appear to be doing anything, or were just redundant. Joel may be able to explain why one might need it, but here is what I was able to get rid of without incident:

    * All of the displayMap() function except for:
    -- the background switch: map.css('background-image','url(' + region.image + ')');
    -- the IE Houdini Bug fix (above)
    -- loadRegionData(region);
    * The place bullets function, since I am only using zoomable regions; no bullets at all.
    * The if(region.scan) conditional statement, which doesn't appear to do anything.

    Hopefully you'll find this helpful.

  56. Spec

    Spec

    October 07, 2009 1:39 PM | Permalink

    Really great implementation of jQuery. I was also wondering if this may be used commercially, and if so, what the conditions are.

  57. Joel Sutherland

    Joel Sutherland

    October 07, 2009 2:06 PM | Permalink

    Spec,

    It is under the MIT License so you can do just about anything with it, commercial or otherwise.

  58. Spec

    Spec

    October 07, 2009 6:13 PM | Permalink

    Thanks, I actually just stumbled across the mention of the license in the js file. :) Totally awesome.

    I think the only extra functionality that would be really great to add to this would be the ability to toggle the bullet points so that you could show all of x, or all of y bullet points. Probably just a simple addition when it comes to jQuery, but I haven't looked into it yet.

  59. Joel Sutherland

    Joel Sutherland

    October 08, 2009 9:43 AM | Permalink

    Spec,

    You can toggle the bullets easily. Just give each one a class (you may have done this already to style them). Then you can do something like:

    $("#redtoggle").click(function(){
    $(".red").show().siblings().hide();
    });

  60. E. Russell

    E. Russell

    October 09, 2009 10:05 AM | Permalink

    Hi Joel! First, I would just like to thank you for the great plugin. I was initially building my map in javascript, so I'm really enjoying how much easier this is to work with.

    That being said, I do have a question about something. The problem in my case is that my zoomed regions do not always look proper when resized to the same dimensions as the parent map. I also noticed that if the zoomed region doesn't cover the parent map completely, it is tiled.

    Is there any way to adjust this behavior? Ideally it seems like it should show the parent map underneath if they're not the same size, or perhaps a solid background. Thanks!

  61. Joel Sutherland

    Joel Sutherland

    October 09, 2009 2:42 PM | Permalink

    E.,

    You will need to work on the css and the plugin code itself to make this happen. Ideally you could use zoomed regions of the same aspect ratio.

    If you want to have a zoomed region partially cover the map you will need to edit the js that animates on zoom. You may also need to add options to the plugin that allows you to specify dimensions of the maps. It might be a performance issue to measure this dynamically.

  62. E. Russell

    E. Russell

    October 12, 2009 12:43 PM | Permalink

    Joel,

    I figured out a workaround for the tiling issue. I simply modified the displayMap() function and appended:

    backgroundRepeat: 'no-repeat'

    where it clears the map and sets the background image. Then to fix the return link I simply changed its CSS to display on the top instead of the bottom.

    This makes it so sub-maps will zoom and look correct even if their dimensions are different. Naturally if the sub-map has a shorter width, you'd probably want to position the return link in the upper left or something.

  63. caugust

    caugust

    October 16, 2009 3:10 PM | Permalink

    @samAmbrose on sept. 23 -

    I'm seeing exactly the same thing you are. When I run example.html from my filesystem, it works fine -- the bullets show up (in other words, it's able to find the popup "includes" and read the bullet info like the rel attribute).

    But if I take it and put it on my server with zero modifications and access example.html via http... no dice. The zoomable region zooms, the "return to campus map" link works, but nothing from the popup files is pulled in, and the bullets don't work.

    As far as I can tell it's not a mapping thing. First of all nothing changes, and since it's all relative links with a very basic folder structure, it shouldn't be an issue. But if I hardcode the full URLs, still no dice.

    I'd love to use this, but I'm afraid I'll have to abandon this and keep looking.

  64. macca002

    macca002

    October 26, 2009 1:17 AM | Permalink

    Any news on the IE6 problem? I have the same issue when after returning to the main map.
    Click to return to the 'zoomed' area and no bullet points load.
    Thanks in advance!

  65. geert baven

    geert baven

    October 28, 2009 12:27 PM | Permalink

    @Juan Thanks for pointing this out. Changing the file extensions to php makes the bullets appear

  66. Toby Miller

    Toby Miller

    November 09, 2009 1:41 PM | Permalink

    I like the custom designs that this plugin delivers but I miss the functionality the more complete APIs provide. Did you attempt to apply any custom skinning to one of the existing map api's (i.e. Google, Bing, Yahoo, etc) before going down this path?

  67. Joel Sutherland

    Joel Sutherland

    November 09, 2009 1:45 PM | Permalink

    Toby,

    I have used the Google Maps API before -- this was certainly not intended to replace it!

    It was intended to be simple from the beginning. For anything more I would recommend moving to one of the other APIs. I wrote this pre-Bing, but that seems to have an especially good one.

  68. Toby Miller

    Toby Miller

    November 09, 2009 2:17 PM | Permalink

    I've shared this with some designers and they're in love with what you've done so kudos to you for that. The other map implementation that I've been impressed with lately is this one:

    http://rideoregonride.com/trails/

    I love how attainable map functionality has become over the past few years. Thanks for adding to it.

  69. Joel Sutherland

    Joel Sutherland

    November 09, 2009 2:23 PM | Permalink

    WOW! That map is beautiful. I am originally an Oregon native and a biker so I find it interesting as well!

    Thanks for the kind words!

  70. Biju Subhash

    Biju Subhash

    November 11, 2009 7:16 AM | Permalink

    plugin is verry nice and thankk you for sharing :D

  71. Jonathan Richey

    Jonathan Richey

    November 18, 2009 2:02 PM | Permalink

    I downloaded your project and uploaded it as-is to our testing server and the live server.

    Testing server:
    http://alpineadvertising.com/in2wireless/zoommap/example.html

    Works!

    Live server:
    http://mycellularcenter.com/zoommap/example.html

    Doesnt work : {

    Any ideas why its not working? What sort of server setting would cause it not to work?

    I believe for servers are windows based. I even changed the filenames a bit because I know windows is picky about filenames.

  72. Butch

    Butch

    November 18, 2009 5:16 PM | Permalink

    The inability to create the bullets have to do with script mapping of file extensions on the server. In our case, .html is not allowed for GET and POST.

    The AJAX/load uses GET or POST to retrieve the popup files. So the file extension used has to be what's allowed (.aspx, .php) on your server to accept these requests.

  73. Simone

    Simone

    November 24, 2009 12:50 PM | Permalink

    hi thanks for your plugin really amazin. i have a "newbie" question: i cant add any other subregion. i tried puttin maps : [ bla bla ] under the initial region map, i tried also adding the new subregion beetween { } and nothing, a blank page appear. i tried on safari and firefox latest version, on Leopard. any suggestion? :
    regards

  74. Lou

    Lou

    November 25, 2009 2:50 AM | Permalink

    Hi.
    I 'm leaving a post because I work on the plugin and I meet a difficulty. I use a cms and so I have to implement the plugin dynamically.
    So in the cms I have a page with a list of blocks which represents the future bullets with information. In this page I call two files .js (zoommap.js and the file I developped). So I don't use setup.js as I want to call data in my .js file

    My file.js create dynamically in jQuery the structure HTML by using DOM. Then i call the plugin

    $('#map').zoommap({
    width: '699px',
    height: '503px',
    //Initial map to be shown
    map:{
    id: 'map',
    image: 'here I wrote url and it plays well',
    data: 'here I don't find any solution'
    }
    });

    So I would like to know the url I have to put in data or could it be a variable (as I create the structure dynamically).

    Or is it a wrong way?

    Thanks very much for your help.

  75. John

    John

    November 26, 2009 7:41 AM | Permalink

    Plugin works fine no problems at all! very good job! keep on..

  76. N-Designs

    N-Designs

    December 01, 2009 7:36 AM | Permalink

    great plugin.. 'm going to try it on my next project

  77. Greg

    Greg

    December 02, 2009 7:09 AM | Permalink

    Firstly thanks for the code. I'm pretty poor on coding but would like to use this in a slightly different way by putting an image of a different map in the popup content html rather than using the zoom effect. However when I try to do this the image won't show. It's probably a very basic question I know, but any help would be appreciated.

    Thanks

  78. Joel Sutherland

    Joel Sutherland

    December 02, 2009 10:03 AM | Permalink

    Greg,

    If you visit the url source of the popup that is being pulled via ajax can you see the image?

    Are you using a relative or absolute url as the image source?

  79. Kateva

    Kateva

    December 02, 2009 5:39 PM | Permalink

    For those with the problem of the popup files not loading (the bullets don't appear). If you're running IIS and a .NET server changing the file names to .aspx (instead of .php) solves the problem as well.

    Thanks!

  80. LadynRed

    LadynRed

    December 02, 2009 6:53 PM | Permalink

    "The AJAX/load uses GET or POST to retrieve the popup files. So the file extension used has to be what's allowed (.aspx, .php) on your server to accept these requests."

    There should be a way to enable IIS to handle that type of request so changing file extensions isn't necessary. Off to research!

  81. Greg

    Greg

    December 03, 2009 4:38 AM | Permalink

    "Are you using a relative or absolute url as the image source?"

    DOH!!

    Thanks Joel - I always miss the little things! I'll post a link when it's finished. Thanks again for the code.

  82. apagea

    apagea

    December 14, 2009 2:13 PM | Permalink

    Ragdoll: I tried your solution from october 7th to get the map to refresh in ie6. it will only work with the alert. am i missing something. i placed the

    map.css('display','none');
    map.css('display','block');

    15 plus times after the

    'var check = map.css('background-image');


    my placement may not be right? anyway, is there a way to have the screen refresh from the 'return to full map' link?

    thanx.

  83. mike

    mike

    December 17, 2009 11:00 AM | Permalink

    how to add an additional nested map? please help me posting an example code, i cant find out :(

  84. Ben

    Ben

    January 04, 2010 4:46 PM | Permalink

    Mike, to nest additional maps make sure that you have a comma in between each nested map...

    Example:

    maps: [
    {
    id: 'quads',
    parent: 'campus',
    image: 'images/quads.png',
    data: 'popups/quads.html',
    width: '200px',
    height: '232px',
    top: '18px',
    left: '176px'
    },
    {
    id: 'otherMap',
    parent: 'campus',
    image: 'images/otherMap.png',
    data: 'popups/otherMap.html',
    width: '200px',
    height: '232px',
    top: '40px',
    left: '380px'
    }
    ]

  85. Dooley P.

    Dooley P.

    January 14, 2010 11:05 PM | Permalink

    Hey wow! I was going to reinvent the wheel... Lol!

  86. Yarik

    Yarik

    January 26, 2010 9:30 AM | Permalink

    I downloaded the Project Zip using link above and have trouble with zooming. Plugin working properly only with Firefox (ver. 3.5.7). In Opera (ver. 10.10) and IE 8 zooming works only at first time when html page loaded. What i do:

    1) Open example.html (from Project above)
    2) Click on zoomable region
    3) It zooms with animation
    4) Click "Return to campus map" and it closes
    5) Click again on zoomable region. Bullets fades out, but after it nothing happens. Map becomes inactive (just picture). If i reload page, bullets appears but when i click on zoomable region, bullets fades out and nothing happens. Etc.

    Strange feature in Opera: if you click twice on zoomable region, it zooms and works always, but two zoom maps open.

    I thing something wrong in addZoom function (zoommap.js). In line 135:

    $(this).siblings().fadeOut();

    All right and it works always properly (bullets fade out).

    Line 137:

    $(this).hide()
    .attr('src', region.image).load(function(){
    ...

    Don't work. Maybe something with compatibility of jQuery Load?

  87. Eric

    Eric

    January 28, 2010 10:41 AM | Permalink

    Hi Joel,

    Can your component map a floor plan of a building and do you have any demos for that ? Thanks

    Eric

Leave a Comment

URLs will be converted to links. HTML tags will be converted to entities.