Permalink
Browse files

include OSM code just once

  • Loading branch information...
1 parent e31335d commit 7495faeff6927e948492fec078c0912fd907274a @fcurella committed Nov 20, 2012
View
@@ -1 +1 @@
-__version__ = (0, 0, 3)
+__version__ = (0, 0, 4)
@@ -1,3 +1,15 @@
<script type="text/javascript"
src="//maps.googleapis.com/maps/api/js?key={{ GMAPS_API_KEY }}&sensor={{ sensor|yesno:"true,false"}}">
-</script>
+</script>
+{% if osm %}
+<script>
+var osmMapType = new google.maps.ImageMapType({
+ getTileUrl: function(coord, zoom) {
+ return "http://tile.openstreetmap.org/" + zoom + "/" + coord.x + "/" + coord.y + ".png";
+ },
+ tileSize: new google.maps.Size(256, 256),
+ name: "OpenStreetMap",
+ maxZoom: 18
+})
+</script>
+{% endif %}
@@ -8,12 +8,5 @@ var {{ map_var }} = new google.maps.Map(document.getElementById('{{ element_id }
{% include "gmaps/templatetags/gmaps/kwargs.js" %}
});
{% if map_type == '"OSM"' %}
- {{ map_var }}.mapTypes.set("OSM", new google.maps.ImageMapType({
- getTileUrl: function(coord, zoom) {
- return "http://tile.openstreetmap.org/" + zoom + "/" + coord.x + "/" + coord.y + ".png";
- },
- tileSize: new google.maps.Size(256, 256),
- name: "OpenStreetMap",
- maxZoom: 18
- }));
+ {{ map_var }}.mapTypes.set("OSM", osmMapType);
{% endif %}
@@ -1,7 +1,7 @@
"""
{% load gmaps %}
-{% gmap_js [<sensor>] %}
+{% gmap_js ["sensor"] ["osm"] %}
{% map <element_id> <center_location> ["zoom" <zoom>] ["map_type" <type>] %}
{% marker <location> ["title" <title>] %}
@@ -87,13 +87,14 @@ def ensure_geometry(geomtry_or_wkt):
@register.inclusion_tag(TEMPLATE_ROOT + 'gmap_js.html')
-def gmap_js(sensor=False):
+def gmap_js(*args, **kwargs):
api_key = getattr(settings, 'GOOGLE_API_KEY', None)
if api_key is None:
raise ImproperlyConfigured(u'You must define GOOGLE_API_KEY in your settings.')
return {
- 'sensor': sensor,
+ 'sensor': 'sensor' in args,
+ 'osm': 'osm' in args,
'GMAPS_API_KEY': api_key,
}

0 comments on commit 7495fae

Please sign in to comment.