map
Size: 5289
Comment:
|
Size: 5621
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 11: | Line 11: |
There are 3 methods to add/move a marker on the map | |
Line 13: | Line 12: |
There are 3 methods to add/move a marker on the map: | |
Line 20: | Line 20: |
=== html_lat (html_lng) === ''The HTML <input> element that represents the longitude of the marker e.g.'' |
=== html_lat and html_lng === ''The HTML <input> element that represents the latitude and longitude of the marker e.g.'' |
Line 34: | Line 34: |
<input type="text" id="id_lng" name="lng" /> | <input type="text" id="id_lat" name="lat" value="0.353452" /> <input type="text" id="id_lng" name="lng" value="0.435323" /> |
Line 38: | Line 39: |
$('map-element').selectLocation({ html_lng: $('#id_lng') }); | $('map-element').selectLocation({ html_lat: $('#id_lat'), html_lng: $('#id_lng') }); |
Line 42: | Line 44: |
* When the input 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'' |
* When the input already contains data on init, place the marker on the map * When the data in the inputs is changed, move the marker to that position and center the map at the marker * When the marker is moved, change the values in the input elements to the coordinates of the marker * When the inputs are emptied, remove the marker from the map |
Line 55: | Line 53: |
'''Default''' {{{ /media.icons/marker.png }}} |
|
Line 56: | Line 59: |
/media/icons/marker.png |
{{{ $('map-element').selectLocation({ marker_icon: '/media/icons/my_marker.png' }); }}} |
Line 60: | Line 64: |
* If no marker is specified, use the Google default | * If no marker is specified, use the default marker (supplied by this module) * If the default marker is not found, use the google default |
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:
- By clinking an empty space on the map
By changing the <input> elements that represents the latitude and longitude
By changing the <input> elements that is a representation of the address
Possible parameters
html_lat and html_lng
The HTML <input> element that represents the latitude and longitude of the marker e.g.
Default
null
maybe change this to #id_lng
Example
HTML
<input type="text" id="id_lat" name="lat" value="0.353452" /> <input type="text" id="id_lng" name="lng" value="0.435323" />
Javascript
$('map-element').selectLocation({ html_lat: $('#id_lat'), html_lng: $('#id_lng') });
Specification
- When the input already contains data on init, place the marker on the map
- When the data in the inputs is changed, move the marker to that position and center the map at the marker
- When the marker is moved, change the values in the input elements to the coordinates of the marker
- When the inputs are emptied, remove the marker from the map
marker_icon
The url of the icon that is displayed as marker.
Default
/media.icons/marker.png
Example
$('map-element').selectLocation({ marker_icon: '/media/icons/my_marker.png' });
Specification
- If no marker is specified, use the default marker (supplied by this module)
- If the default marker is not found, 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
ubuntu-django-foundations/map (last edited 2011-04-11 11:40:40 by 41)