-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ada084f
Showing
20 changed files
with
340 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
*.pyc | |||
.DS_Store | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
django-google-maps is written and maintained by Flavio Curella and | |||
various contributors: | |||
|
|||
Development Lead | |||
~~~~~~~~~~~~~~~~ | |||
|
|||
- Flavio Curella <flavio.curella@gmail.com> | |||
|
|||
|
|||
Patches and Suggestions | |||
~~~~~~~~~~~~~~~~~~~~~~~ | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,19 @@ | |||
Copyright (C) 2012 by Flavio Curella and individual contributors. | |||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
|
|||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
recursive-include tests *.py | |||
|
|||
include AUTHORS | |||
include LICENSE | |||
include README.rst | |||
|
|||
recursive-include templates/gmaps/templatetags/gmaps/ *.js | |||
recursive-include templates/gmaps/templatetags/gmaps/ *.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,27 @@ | |||
Django Google Maps | |||
====================================== | |||
|
|||
This app provides template tags for easily creating Google Maps from GeoDjango models. | |||
|
|||
Installation | |||
~~~~~~~~~~~~ | |||
|
|||
1. Add ``GOOGLE_API_KEY`` to your settings. | |||
2. Add ``gmaps`` to your ``INSTALLED_APPS``. | |||
|
|||
|
|||
Usage | |||
~~~~~ | |||
|
|||
{% load gmaps %} | |||
<div id="mymap"></div> | |||
|
|||
{% gmap_js %} {# prints out the <script> tag calling the Google Maps API #} | |||
|
|||
{% map "mymap" object.location %} | |||
{% marker someobj.location %} | |||
{# all tags accept optional parameters that will be passed to the js constructor #} | |||
{% marker someobj.location ["title" "'Hello, World!'"] %} | |||
{% polygon someobj.mpoly %} | |||
{% polyline someobj.mpoly %} | |||
{% endmap %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
__version__ = (0, 0, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
# Intentionally left blank. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
<script type="text/javascript" | |||
src="//maps.googleapis.com/maps/api/js?key={{ GMAPS_API_KEY }}&sensor={{ sensor|yesno:"true,false"}}"> | |||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
{% if map_var %}, | |||
map: {{ map_var }} | |||
{% endif %} | |||
{% if kwargs %},{% endif %} | |||
{% for k,v in kwargs.items %}{{k}}: {{v}}{% if not forloop.last%},{% endif %}{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
<script type="text/javascript"> | |||
$().ready(function() { | |||
{{ output }} | |||
}); | |||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
var {{ map_var }} = new google.maps.Map(document.getElementById('{{ element_id }}'), { | |||
center: new google.maps.LatLng({{ latitude }}, {{ longitude }}), | |||
zoom: {{ zoom }}, | |||
mapTypeId: {{ map_type }} | |||
{% include "quakeparser/templatetags/gmaps/kwargs.js" %} | |||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
new google.maps.Marker({ | |||
position: new google.maps.LatLng({{ latitude }}, {{ longitude }}) | |||
{% include "quakeparser/templatetags/gmaps/kwargs.js" %} | |||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
new google.maps.Polygon({ | |||
paths: [ | |||
{% for point in coords %} | |||
new google.maps.LatLng({{ point.1 }}, {{ point.0 }}){% if not forloop.last %},{% endif %} | |||
{% endfor %} | |||
] | |||
{% include "quakeparser/templatetags/gmaps/kwargs.js" %} | |||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
new google.maps.Polyline({ | |||
path: [ | |||
{% for point in coords %} | |||
new google.maps.LatLng({{ point.1 }}, {{ point.0 }}){% if not forloop.last %},{% endif %} | |||
{% endfor %} | |||
] | |||
{% include "quakeparser/templatetags/gmaps/kwargs.js" %} | |||
}); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,195 @@ | |||
""" | |||
{% load gmaps %} | |||
{% gmap_js [<sensor>] %} | |||
{% map <element_id> <center_location> [zoom <zoom>] [map_type <type>] %} | |||
{% marker <location> [title <title>] %} | |||
{% marker <location> [title <title>] %} | |||
{% polygon <mpoly> %} | |||
{% endmap %} | |||
""" | |||
|
|||
""" | |||
function initialize() { | |||
var map = new google.maps.Map(document.getElementById('map-canvas'), { | |||
center: new google.maps.LatLng(37.4419, -122.1419), | |||
zoom: 13, | |||
mapTypeId: google.maps.MapTypeId.ROADMAP | |||
}); | |||
var marker = new google.maps.Marker({ | |||
position: new google.maps.LatLng(37.4440, -122.1419), | |||
map: map, | |||
title:"Hello World!" | |||
}); | |||
var marker2 = new google.maps.Marker({ | |||
position: new google.maps.LatLng(37.4460, -122.1300), | |||
map: map, | |||
title:"Hello World!2" | |||
}); | |||
var marker3 = new google.maps.Marker({ | |||
position: new google.maps.LatLng(37.4500, -122.1500), | |||
map: map, | |||
title:"Hello World!3" | |||
}); | |||
var triangleCoords = [ | |||
new google.maps.LatLng(37.4440, -122.1419), | |||
new google.maps.LatLng(37.4460, -122.1300), | |||
new google.maps.LatLng(37.4500, -122.1500), | |||
new google.maps.LatLng(37.4440, -122.1419) | |||
]; | |||
var triangle = new google.maps.Polygon({ | |||
paths: triangleCoords, | |||
strokeColor: "#FF0000", | |||
strokeOpacity: 0.8, | |||
strokeWeight: 2, | |||
fillColor: "#FF0000", | |||
fillOpacity: 0.35, | |||
map: map | |||
}); | |||
} | |||
""" | |||
|
|||
from django import template | |||
from django.conf import settings | |||
from django.core.exceptions import ImproperlyConfigured | |||
|
|||
|
|||
register = template.Library() | |||
TEMPLATE_ROOT = 'gmaps/templatetags/gmaps/' | |||
|
|||
|
|||
def list_to_dict(x): | |||
return dict(x[i:i + 2] for i in range(0, len(x), 2)) | |||
|
|||
|
|||
@register.inclusion_tag(TEMPLATE_ROOT + 'gmap_js.html') | |||
def gmap_js(sensor=False): | |||
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, | |||
'GMAPS_API_KEY': api_key, | |||
} | |||
|
|||
|
|||
MAP_TYPES = { | |||
'hybrid': 'google.maps.MapTypeId.HYBRID', | |||
'roadmap': 'google.maps.MapTypeId.ROADMAP', | |||
'satellite': 'google.maps.MapTypeId.SATELLITE', | |||
'terrain': 'google.maps.MapTypeId.TERRAIN', | |||
} | |||
|
|||
|
|||
class MapNode(template.Node): | |||
template_name = TEMPLATE_ROOT + 'map.js' | |||
template_name_handler = TEMPLATE_ROOT + 'load_handler.js' | |||
|
|||
def __init__(self, nodelist, element_id, location, map_type='"roadmap"', zoom="13", **kwargs): | |||
self.nodelist = nodelist | |||
self.element_id = template.Variable(element_id) | |||
self.location = template.Variable(location) | |||
self.map_type = template.Variable(map_type) | |||
self.zoom = template.Variable(zoom) | |||
|
|||
for k, v in kwargs.items(): | |||
kwargs[k] = template.Variable(v) | |||
self.kwargs = kwargs | |||
|
|||
def render(self, context): | |||
location = self.location.resolve(context) | |||
lon = location.x | |||
lat = location.y | |||
|
|||
element_id = self.element_id.resolve(context) | |||
map_var = "%s_map" % element_id | |||
|
|||
for k, v in self.kwargs.items(): | |||
self.kwargs[k] = v.resolve(context) | |||
|
|||
ctx = { | |||
'map_var': map_var, | |||
'element_id': element_id, | |||
'latitude': lat, | |||
'longitude': lon, | |||
'map_type': MAP_TYPES[self.map_type.resolve(context)], | |||
'zoom': self.zoom.resolve(context), | |||
'kwargs': self.kwargs | |||
} | |||
output = template.loader.render_to_string(self.template_name, ctx) | |||
|
|||
context['map_var'] = map_var | |||
output += self.nodelist.render(context) | |||
|
|||
return template.loader.render_to_string(self.template_name_handler, {'output': output}) | |||
|
|||
|
|||
@register.tag | |||
def map(parser, token): | |||
bits = token.split_contents()[1:] | |||
args = bits[:2] | |||
kwargs = list_to_dict(bits[2:]) | |||
nodelist = parser.parse(('endmap',)) | |||
parser.delete_first_token() | |||
return MapNode(nodelist, *args, **kwargs) | |||
|
|||
|
|||
@register.inclusion_tag(TEMPLATE_ROOT + 'marker.js', takes_context=True) | |||
def marker(context, location, *args): | |||
""" | |||
Outputs the necessary code to put a marker on the map. | |||
{% marker <location> [options] %} | |||
""" | |||
kwargs = list_to_dict(args) | |||
|
|||
lon = location.x | |||
lat = location.y | |||
|
|||
context.update({ | |||
'latitude': lat, | |||
'longitude': lon, | |||
'kwargs': kwargs | |||
}) | |||
|
|||
return context | |||
|
|||
|
|||
@register.inclusion_tag(TEMPLATE_ROOT + 'polygon.js', takes_context=True) | |||
def polygon(context, mpoly, *args): | |||
""" | |||
Given a GeoDjango mpoly fields, outputs the necessary code to generate a Polygon. | |||
""" | |||
kwargs = list_to_dict(args) | |||
coords = mpoly.coords[0] | |||
|
|||
context.update({ | |||
'coords': coords, | |||
'kwargs': kwargs | |||
}) | |||
return context | |||
|
|||
|
|||
@register.inclusion_tag(TEMPLATE_ROOT + 'polyline.js', takes_context=True) | |||
def polyline(context, mpoly, *args): | |||
""" | |||
Given a GeoDjango mpoly fields, outputs the necessary code to generate a Polyline. | |||
""" | |||
kwargs = list_to_dict(args) | |||
coords = mpoly.coords[0] | |||
|
|||
context.update({ | |||
'coords': coords, | |||
'kwargs': kwargs | |||
}) | |||
|
|||
return context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
# Wrtie tests here |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,34 @@ | |||
import os | |||
from setuptools import setup, find_packages | |||
|
|||
from gmaps import __version__ | |||
|
|||
|
|||
def read(fname): | |||
return open(os.path.join(os.path.dirname(__file__), fname)).read() | |||
|
|||
requirements = [] | |||
|
|||
setup( | |||
name = "django-google-maps", | |||
version = ".".join(map(str, __version__)), | |||
description = "", | |||
long_description = read('README.rst'), | |||
url = '', | |||
license = 'MIT', | |||
author = 'Flavio Curella', | |||
author_email = 'flavio.curella@gmail.com', | |||
packages = find_packages(exclude=['tests']), | |||
classifiers = [ | |||
'Development Status :: 3 - Alpha', | |||
'Environment :: Console', | |||
'Intended Audience :: Developers', | |||
'Intended Audience :: Information Technology', | |||
'License :: OSI Approved :: MIT License', | |||
'Operating System :: OS Independent', | |||
'Programming Language :: Python', | |||
'Framework :: Django', | |||
], | |||
install_requires = requirements, | |||
tests_require = [], | |||
) |
Empty file.