Giter Site home page Giter Site logo

jmapping's Introduction

jMapping - Google Maps jQuery Plugin

This plugin is designed for quick development of a page that implements a Google Map with a list of the locations that are specified within the HTML.

Links

Graceful degradation and Semantic Expectations

This plugin tries to allow as much graceful degradation as possible by having the HTML be as semantic as possible. The plugin expect the HTML for the locations to be grouped under a common element. Additionally, it expects the links and Map Info Window content to be grouped under the location elements. It also expects the necessary metadata to be on the location element. This way the HTML semantically reflects that all of those parts and information are associated with the specific location or place.

Basic Usage

Download the necessary dependencies and jMapping.

Make sure you include the necessary scripts in your page:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.3&amp;sensor=false"></script>
<script type="text/javascript" src="markermanager.js"></script>
<script type="text/javascript" src="StyledMarker.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="jquery.metadata.js"></script>
<script type="text/javascript" src="jquery.jmapping.js"></script>

Make sure your HTML has a div element for the Google map, and there is a container element with some locations and their data. The data by default is expected to be on the "data-jmapping" attribute of the location (this can be configured):

<div id="map"></div>

<div id="map-side-bar">
  <div class="map-location" data-jmapping="{id: 5, point: {lat: 35.925, lng: -79.053}, category: 'Gas'}">
    <a href="#" class="map-link">Some Place</a>
    <div class="info-box">
      <p>Some thing for the info box.</p>
    </div>
  </div>
  <div class="map-location" data-jmapping="{id: 8, point: {lat: 35.935, lng: -79.024}, category: 'Food'}">
    <a href="#" class="map-link">Another Place</a>
    <div class="info-box">
      <p>Example Text.</p>
    </div>
  </div>
</div>

Then just call the jMapping function on the map element:

$(document).ready(function(){
  $('#map').jMapping();
});

If you need to change the markers on the map, usually for some type of pagination, this can be done by simply updating the content of the "side-bar" container to contain new location data and then calling the update function:

$('#map-side-bar').load('ajax/path/file.html', nil, function(){
  $('#map').jMapping('update');
});

OR

$('#map-side-bar').load('ajax/path/file.html', nil, function(){
  $('#map').data('jMapping').update();
});

Options

These are options that can be passed to the jMapping function to change specific settings.

  • side_bar_selector:
    • Default: "#map-side-bar:first"
    • This defines the selector where location items will be searched for within.
  • location_selector:
    • Default: ".map-location"
    • This defines the selector for location items. This is the element that the metadata needs to be associated with. The plugin will look for items matching this selector inside of the side bar element.
  • link_selector:
    • Default: a.map-link
    • This selector defines the link that will be used to "activate" a marker on the map. If info window elements are provided the HTML inside of them will be loaded into the pop up window when these links are clicked. You should set this value to false if you do not wish to use this functionality. These links will be searched for inside of the location elements specified in the location_selector.
  • info_window_selector:
    • Default: ".info-box"
    • This selector defines where the content for the Google Maps info window for each location marker is. This element will be searched for inside of the location elements specified in the location_selector. If no element is found no Info Window will be attached to the marker.
  • default_point:
    • Default: {lat: 0.0, lng: 0.0}
    • This point determines the Google Maps location if there are no location elements inside the specified location_selector.
  • metadata_options:
    • Default: {type: "attr", name: "data"}
    • This is the set of options passed to the jQuery metadata function. It defines how the necessary metadata for each location will be searched for. See the metadata plugins docs for more info.
  • info_window_max_width:
    • Default: 425
    • This specifies what the max width of the Google Maps Info Windows can be when a marker is activated. Otherwise it will expand to fit the width of the content.
  • map_config:
    • Default: N/A
    • This can be set to a MapOptions object. Which is just a normal object {} with specific properties that become the settings for the map.
  • category_icon_options:
    • Default: N/A
    • By default the plugin will use the default Google Maps marker icon. But you can use this option to specify what options to pass to the StyledMarker based on category data associated with the location. It accepts 2 types of values: an object or a function.
      If the setting is to an object it will take the category data on the location and look for a key on the object that matches and return that value. If there is no value for the supplied category, it will return the value specified in the "default" key.
      If the setting is set to a function it will call the function and pass the value for the category data to the function, returning the result. This can be used for more complicated logic and for using something other then just string data in the category, such as an object with multiple data attributes it's self. The object values for the associated category key or the function should return one of three data types:
      1. A string, this will be used as the image source for the marker icon.
      2. A google.maps.MarkerImage, this will be used as the icon for the Marker object.
      3. An object that has valid options for a StyledIcon object.
  • default_zoom_level:
    • Default: N/A
    • Use this option to set the default zoom level for your map. Normally, zoom level is set dynamically based on the position of locations being mapped. But, in some cases, like viewing a single mapped location, you may wish to set a default zoom level. Zoom level values should be between 1 and 20. Neighborhood level is approximately 15.
  • force_zoom_level:
    • Default: N/A
    • This will force the map to always be rendered at this zoom level.
  • always_show_markers:
    • Default: false
    • Set this option to true if you wish to display markers on all zoom levels. (Normally, the markers may only be visible on certain zoom levels, depending on the normal bounds and zoom level of the marker data.)

Object API

The jMapping API object is available from the "jMapping" data value on the selector passed to the original $().jMapping function.

For example:

$('#map').jMapping();
$('#map').data('jMapping'); // returns the jMapping API object

The API of that object:

  • gmarkers:
    • The google.maps.Marker objects that have been placed on the map. Stored in an object where the keys are the id's are those provided in the metadata
  • settings:
    • The settings for this jMapping instance.
  • mapped:
    • Did the plugin create the map and markers as expected or not.
  • map:
    • the google.maps.Map Google Map API object.
  • markerManager:
    • The Google Maps MarkerManager object for manipulating groups of markers, has control over all markers on the map.
  • gmarkersArray:
    • Returns an array of all the markers currently on the map.
  • getBounds:
    • The Google Maps google.maps.LatLngBounds bounds object for all the markers on the map.
  • getPlaces:
    • Returns the set of jQuery objects for the place DOM Elements.
  • getPlacesData:
    • Returns an array of all the metadata for each place returned by getPlaces
  • update:
    • Used to update the map if the HTML DOM for the locations has changed.

Event API

There a number of events that fire as jMapping is used.

  • beforeMapping.jMapping
    • This fires immediately before the main functionality of the plugin begins and is passed the settings object. If it returns false the mapping will be canceled.
  • afterMapping.jMapping
    • This fires immediately after the plugins mapping has finished, passes in the jMapping API object.
  • beforeUpdate.jMapping
    • This fires right before the map is updated via the "update" method. The jMapping API object is passed to the callback. If the callback returns false the update will be canceled.
  • afterUpdate.jMapping
    • This fires immediately after the map is updated.
  • markerCreated.jMapping
    • This fires right after a map marker is created, the marker object is passed to the callback.

Dependencies

License

Copyright (c) 2009-2011 Brian Landau (Viget Labs)
MIT License: http://www.opensource.org/licenses/mit-license.php

jmapping's People

Contributors

brianjlandau avatar gsterndale avatar jackdanger avatar mokolabs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jmapping's Issues

using 2 location lists

is there a way to have two location lists on the same page? i want to have two separate locations list on both sides of the map but cant figure out how to make it read a different map-side-bar div.

W3C Validation Error

Hi,

I am getting the following validation error when using Jmapping:

Line 89, Column 59: there is no attribute "data-jmapping"
…iv class="map-location" data-jmapping="{id: 1, point: {lng: 18.408215, lat: -3…

I am using XHTML 1.0 Transitional DTD

default_zoom_level option doesn't seem to work

Using default_zoom_level doesn't seem to affect the map. With 1 or no points it is at the highest zoom level, always. I've also tried force_zoom_level. Options do work, however, as I am able to set the default point and have the map center on it. I know that it's recognizing the option because I see it when I inspect the jmapping object, but it doesn't seem to affect the way the map is rendered.

Customizing info window

Are there any simple ways to customize the info window's look/style? I know some stuff has been added to the Maps V3 api, but was hoping this plugin offered a simple solution.

Thanks

More control over bounds

I have some situations where I'd like only a subset of my markers to contribute to the bounds when the map is displayed. For example, multiple locations of a franchise, but I'd like to zoom to the closest locations and have the further locations on the map for when the user zooms out. I can see a couple ways to solve this. First, you could give me a callback or some way of setting the bounds manually. Second, you could have a way of marking locations as to whether or not they contribute to the bounding calculation. I think I would prefer the latter. What do you think?

API v3 GroundOverlays integration

Hi!
I have a problem with add a bitmap on the map generated by jMapping.
Could you give me a tip for integrate it https://developers.google.com/maps/documentation/javascript/overlays#GroundOverlays with your script?

I added a function like that in jquery.jmapping.js:

  var imageBounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(51.xxx,22.xxx),
    new google.maps.LatLng(51.xxx,22.xxx)
    );

  var createGroundLayer = new google.maps.GroundOverlay(
    "/img/map_lipowa.png",
    imageBounds
    );
  createGroundLayer.setMap(this.map);

But still don't see the .png image.

Could you help mi with the last line? Probably I used bad argument for setMap() function.

Help me, please.

bounds is undefined

Hi --

jMapping is working really well for me with one exception. I have a case where very quickly after page load I have to refresh the data and the map. I find that if update is called too quickly after the initial call to render the map, I receive the error: "bounds is undefined" in markermanager.js, Line 764.

This can easily be reproduced with:

$(function(){

$('#map').jMapping();
// do stuff
$('#map').jMapping('update');

});

...though obviously my situation is more complex than this.

I also tried waiting for the afterMapping event to fire but I have the same problem:

$(function(){

$(document).bind('afterMapping.jMapping', function(event, api) {
// do stuff
api.update();
});

$('#map').jMapping();

});

Can anyone provide a suggestion for how I can ensure the map is ready enough for an update so that I can prevent this error?

If you're curious as to why I have this situation: I'm using the BBQ plugin to provide back-button support for AJAX calls that the user has caused on the page. The plugin uses hash tags on the URL to store state and then allows you to re-fire the AJAX call(s) that caused that state. In my case when the page renders with hashtags, the hashtag event fires, I do an AJAX call that refreshes the data that drives the map which means I'm calling jMapping('update') very quickly.

Thanks in advance.

Troy

Using map_options causes paginate to break

The listings in the side bar paginate, but the map doesn't with the following code...

$(document).bind('init_finished.quickpaginate', function(e){
$('#map').jMapping({
location_selector: '.map-location:visible',
map_config: {
scrollwheel: false,
mapTypeId: google.maps.MapTypeId.ROADMAP,
scaleControl: true
}
});
});

Event example?

I've been trying to get events to work. I want to manipulate the map as soon as the page loads, but the map isn't ready (I get a "bounds is undefined" error) … I was hoping I could add a callback to the "afterMapping.jMapping" event, but I don't receive the event no matter where I try to bind it. I have tried:

$('#map').bind('afterMapping.jMapping', function(event) …
$('#map').bind('afterMapping', function(event) …

$('#map').jMapping().bind('afterMapping.jMapping', function(event) …
$('#map').jMapping().bind('afterMapping', function(event) …

$('#map').data('jMapping').bind('afterMapping.jMapping', function(event) …
$('#map').data('jMapping').bind('afterMapping', function(event) …

window.bind('afterMapping.jMapping', function(event) …
window.bind('afterMapping', function(event) …

The function is never called no matter what I try. Any help?

Thanks,
//Matt Hayes

specifying a custom center via map_config

hi there,
i was trying to give a map with loads of markers a custom center point, "default_point" would not work, as there are location elements in location_selector, so i tried to add a center via map_config: {center: LatLng(lat: 52.539366, lng: 13.387549)} but to no avail ... are there any other ways to achieve that? am i missing sth.?
cheers from germany, and thx for the plugin, great job! -f

Since the metadata method is include in core jQuery past 1.4.3 is it redundent to still use the metadata plugin?

Although it is nice to be able to include the data in a class attribute, the data() method for html5 data- attribute is included in jQuery core now. http://blog.jquery.com/2010/10/16/jquery-143-released/

"To start the primary functionality provided by the jQuery Metadata plugin has been moved into core. HTML 5 data- attributes will be automatically pulled in to jQuery’s data object."

category_icon_options failes

My site, which has been using this JS for the past 6 months, stopped updating the color of the markers. Even the EXAMPLE 5 on the demo site also stopped working. I hope this will get fixed soon.

Thanks

The issue is in this section of the code.

$(document).ready(function(){
$('#map').jMapping({
category_icon_options: {
'restaurant': {color: '#E8413A'},
'museum': {color: '#465AE0'},
'default': {color: '#7CDF65'}
}
});
});

Call javascript onclick from infowindow

This is probably a simple answer to this but its driving me buggy!

Within each window info I have a link "more details" I need it to call a modal window once clicked.
I can't seem to get any onclick events working in the info window? Any ideas? What am I missing!

Callback from map markers

Hi - I'm having a go with jmapping at the moment and it's pretty neat - thank you.

This could be a Google maps rather than jmapping issue so forgive me if this is the wrong place to ask the question:

I have the map set up so that when a location link is clicked, in addition to it being identified on the map, a div with further information also appears on the page, like so:

$("a.map-link").click(function() {
var id = $(this).attr('href');
$("div").siblings(".partner").hide();
$(id).show();
});

So the information div appears if a sidebar link is clicked, but not if the map marker is clicked directly.

I'm a bit of a beginner and I'm wondering how I can get the div to also show when the map marker is clicked? I assume there's some sort of callback involved but I'm not sure where to start.

Many thanks.

map is not showing in full size when called with ajax

I really hope you can help me because, soon I get nuts. I try for a long time now to include jMapping to my contact page. all pages are using a plugin,called smartAjax, to pull in the content. Finally it is working but the map is ignoring the size that is set up for #map (width:100%, height:400px) if I visit the contact page a second or third time. Only a tiny part of the map (about 100px x 50px) is showing up. The map only appears in full when calling the contact page for the first time. Do you have any idea what I can do about it?

This is the code that smartAjax is using
http://jsfiddle.net/X2s2t/

Grid is undefined

Ok after masterfully and flukily getting the map style to work from the JSON settings on the google map creator, I'm running into a JS error cause the map to be unzoomable/dragable.

I'm getting a "grid is undefined" error caused by markermanager.js. It doesn't seem to be playing nicely with map_config in the JS call. I currently have:

    map_config: {
navigationControlOptions: {
            style: google.maps.NavigationControlStyle.ZOOM_PAN
        },
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        styles: [
                  {
                    "featureType": "water",
                    "stylers": [
                      { "color": "#94aea7" }
                    ]
                  },{
                    "featureType": "road.highway",
                    "elementType": "geometry",
                    "stylers": [
                      { "weight": 0.3 },
                      { "color": "#90c67c" },
                      { "saturation": -15 }
                    ]
                  },{
                    "featureType": "road.arterial",
                    "stylers": [
                      { "visibility": "on" },
                      { "saturation": -77 },
                      { "color": "#ffffff" }
                    ]
                  },{
                    "featureType": "landscape",
                    "stylers": [
                      { "color": "#e2e7f1" }
                    ]
                  },{
                    "featureType": "poi",
                    "stylers": [
                      { "visibility": "off" }
                    ]
                  }
                ]

    }
  });

The style is created, it looks lovely, but the map doesn't scroll. I've read somewhere that I have to initiate the grid/marker manager somewhere after the page has loaded but I'm a bit lost. Anyone come across this before?

Many thanks.

default_zoom_level

Could you please explain how I would use default_zoom_level and forced_zoom_level as I cannot get either to work at all.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.