map

Revision 1 as of 2011-01-17 13:59:40

Clear message

Google Maps implementation for Ubuntu-django-foundations

The plugin consists of 2 commands e.g.

  • $('map-element').selectLocation({params})
  • $('map-element').showLocations({params})

Both commands with their parameters and uses will be exmplained below

selectLocation

Allows the user to add a marker to the map. There are 3 methods to add/move a marker on the map

  1. By clinking an empty space on the map
  2. By changing the <input> elements that represents the latitude and longitude

  3. By changing the <input> elements that is a representation of the address

Possible parameters


html_lng

The HTML <input> element that represents the longitude of the marker e.g.

Examples

  • $('#id_lng')
  • $('#id_longitude')

Default

null (maybe change this to '#id_lng')

Specification

  • If the inputs already contains data, put the marker on the map at init
  • In the data in the inputs is changed, move the marker and center the map at the marker
  • If the marker is moved, change the values in these input elements accourdingly
  • If the inputs are made empty, remove the marker


html_lat

Same as html_lng but this one is for the latitude


marker_icon

The url of the icon that is displayed as marker.

Example

/media/icons/marker.png

Specification

  • If no marker is specified, use the Google default


html_addr

The HTML <input> elements where the adress is specified (can be multiple) See google.maps.Geocoder() for more information

Example:

  • $('#id_country, #id_city, #id_address')

Specification

  • If one of the input elements is changed, lookup the address in the google database, and move the marker to that location, and center the map at the marker
  • If multiple locations are returned, use the first one
  • If the marker is moved, do nothing

showLocations

Shows multiple markers on the map. The markers cannot be changed position. When clicked on the marker, it can (if specified) show some HTML content with information about that marker. If there are many markers and zoomed out, the markers are clustered to save some CPU power. When zoomed in, the cluster is separated into single markers. Clicking on a cluster shows the markers in it (max 10).


marker_icon

The url of the icon that is displayed as marker.

Example

/media/icons/marker.png

Specification

  • If no marker is specified, use the Google default


data_url

The url where the locations can be loaded from in JSON form

Example

/map/locations/all/

Specification The URL should return at minimal: [{fields: {lng:<float>, lat:<float>}},

  • {fields: {lng:<float>, lat:<float>}},

  • ..]

Additional information can be added to fields.

The JSON can be easily created by the django function:

Example models.py class MyModel(models.Model): <tab>lat = models.FloatField() <tab>lng = models.FloatField()

views.py from django.core import serializers data = serializers.serialize('json', MyModel.objects.all(), ensure_ascii=False) return HttpResponse(data, mimetype="application/json")


geo_location

Uses the HTML5 geolocation to determine the location of the user.

Examples {use=True, zoom=7}

Default {use=True, zoom=7}

Specifications

  • If use=True, use the HTML5 to determine the location of the user, then set the map's center to that location
  • Adapt the zoomlevel to the specified zoomlevel


marker_content_url

The url of content that is showed when clicked on the marker. $id will be replaced by the id of the marker.

Example

/markers/users/$id/

Specification

  • If the url is not specified, dont allow clicking on markers
  • if the url is specified, replace the %id in url by the marker id, and load the HTML
  • While the html is loaded, show a infowindows with a loading text (Retrieving data from server)
  • Possible make this more regex in the future to replace each /$xxx/ by some variable of the marker


locations

A list of predefined locations (if the data_url is not used)

Example

[{lng: 1.5555, lat: 1.2345},

  • {lng: 3.4563, lat: 23.2345},
  • ..]

Specification

  • If the locations is defined, direcly show the locations on the map

Full Example 1

HTML

    <section id="mymap">
    </section>

CSS

#mymap { height: 400px; width: 500px; }

Javascript

$(function(){
    $('#mymap').showLocations({ locations: [{55.5522, 45.3222},
                                            {23.2345, -65.8742},
                                            {-25.5322, 0.5235}],
                                geo_location: {use: True, geo_location_zoom: 8},
                                marker_icon: '/media/icons/marker.png'});
});

TODO

  • Allow Cluster options
  • Multiple different clusters
  • Reloading markers
  • Filter markers on attribute