From c5a6d45415c7601f9a515d05a61ee795dc37536b Mon Sep 17 00:00:00 2001 From: "luxagraf@c63593aa-01b0-44d9-8516-4b9c7e931d7f" Date: Sun, 13 Jun 2010 01:18:25 +0000 Subject: updated maps.html to use google maps v3 and created custom route model using gmaps polyline tools to encode points --- apps/blog/signals.py | 9 +- apps/locations/admin.py | 55 +- apps/locations/models.py | 19 + apps/locations/urls.py | 2 +- apps/locations/views.py | 24 +- apps/photos/views.py | 2 +- base_urls.py | 3 +- media/js/mainmap.js | 1359 +++++++++++++ templates/archives/map.html | 13 +- templates/details/photo_galleries.html | 2 +- templates/includes/map_entry_list.html | 2323 +++++++++++++---------- templates/includes/map_entry_list_template.html | 176 +- templates/includes/map_sidebar.html | 9 +- templates/includes/map_sidebar_template.html | 7 +- 14 files changed, 2870 insertions(+), 1133 deletions(-) create mode 100644 media/js/mainmap.js diff --git a/apps/blog/signals.py b/apps/blog/signals.py index 9809f6f..23e6d3f 100644 --- a/apps/blog/signals.py +++ b/apps/blog/signals.py @@ -3,7 +3,7 @@ from django.conf import settings from django.template import Context from django.db.models import get_model -from locations.models import Region,Country +from locations.models import Region,Country,Route def update_recent(sender, instance, signal, *args, **kwargs): # Update recent entries static file @@ -20,13 +20,14 @@ def update_recent(sender, instance, signal, *args, **kwargs): qs = model.objects.filter(status__exact=1) cl = Country.objects.filter(visited=True).exclude(name='default') rl = Region.objects.all() - c = Context({'object_list':qs, 'country_list':cl,'region_list':rl}) + rtl = Route.objects.all() + c = Context({'object_list':qs, 'country_list':cl,'region_list':rl, 'route_list':rtl}) t = render_to_string('includes/map_entry_list_template.html',c) - fpath = '%s%s' %(settings.PROJ_ROOT,'templates/includes/map_entry_list.html') + fpath = '%s%s' %(settings.PROJ_ROOT,'media/js/mainmap.js') file = codecs.open(fpath, 'w','utf8') file.write(t) file.close() - c = Context({'country_list':cl,'region_list':rl}) + c = Context({'country_list':cl,'region_list':rl,'route_list':rtl}) t = render_to_string('includes/map_sidebar_template.html',c) fpath = '%s%s' %(settings.PROJ_ROOT,'templates/includes/map_sidebar.html') file = codecs.open(fpath, 'w','utf8') diff --git a/apps/locations/admin.py b/apps/locations/admin.py index 77d1bb3..a23ef28 100644 --- a/apps/locations/admin.py +++ b/apps/locations/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin from django.contrib.gis.admin import OSMGeoAdmin -from locations.models import Region,Country,Location,State +from locations.models import Region,Country,Location,State,Route from django.contrib import databrowse from django.contrib.gis.maps.google import GoogleMap from django.conf import settings @@ -240,3 +240,56 @@ class LocationAdmin(OSMGeoAdmin): # associating the Options with the actual model admin.site.register(Location,LocationAdmin) +class RouteAdmin(OSMGeoAdmin): + # Standard Django Admin Options + list_display = ('name','slug',) + prepopulated_fields = {'slug': ('name',)} + search_fields = ('name',) + ordering = ('name',) + save_as = True + search_fields = ['name',] + list_select_related = True + fieldsets = ( + ('Location', {'fields': ('name','slug','pub_date','template_var_name','zoom'), 'classes': ('show','extrapretty')}), + ('Editable Map View', {'fields': ('geometry',), 'classes': ('show', 'wide')}), + ) + extra_js = [GMAP.api_url + GMAP.key] + map_template = 'gis/admin/google.html' + # Default GeoDjango OpenLayers map options + # Uncomment and modify as desired + # To learn more about this jargon visit: + # www.openlayers.org + + #default_lon = 0 + #default_lat = 0 + #default_zoom = 4 + #display_wkt = False + #display_srid = False + #extra_js = [] + #num_zoom = 18 + #max_zoom = False + #min_zoom = False + #units = False + #max_resolution = False + #max_extent = False + #modifiable = True + #mouse_position = True + #scale_text = True + #layerswitcher = True + scrollable = False + #admin_media_prefix = settings.ADMIN_MEDIA_PREFIX + map_width = 700 + map_height = 325 + #map_srid = 4326 + #map_template = 'gis/admin/openlayers.html' + #openlayers_url = 'http://openlayers.org/api/2.6/OpenLayers.js' + #wms_url = 'http://labs.metacarta.com/wms/vmap0' + #wms_layer = 'basic' + #wms_name = 'OpenLayers WMS' + #debug = False + #widget = OpenLayersWidget + +# Finally, with these options set now register the model +# associating the Options with the actual model +admin.site.register(Route,RouteAdmin) + diff --git a/apps/locations/models.py b/apps/locations/models.py index 47c5d65..e088697 100644 --- a/apps/locations/models.py +++ b/apps/locations/models.py @@ -159,6 +159,25 @@ class Location(models.Model): def __unicode__(self): return self.name +class Route(models.Model): + name = models.CharField(max_length=200) + slug = models.SlugField() + zoom = models.CharField(max_length=2, null=True) + template_var_name = models.CharField(max_length=10, null=True) + pub_date = models.DateTimeField('Date published',null=True) + # GeoDjango specific Polygon Field and GeoManager + geometry = models.MultiPointField(srid=4326) + # GeoManager, a subclass that adds a rich set of geospatial queryset methods + objects = models.GeoManager() + + def get_absolute_url(self): + return "/locations/%s/%s/%s/" % (self.slug) + + + def __unicode__(self): return self.name + + + class WritingbyLocationSitemap(Sitemap): changefreq = "weekly" priority = 0.6 diff --git a/apps/locations/urls.py b/apps/locations/urls.py index 2cad114..c49e684 100644 --- a/apps/locations/urls.py +++ b/apps/locations/urls.py @@ -2,6 +2,6 @@ from django.conf.urls.defaults import * from django.views.generic.simple import redirect_to,direct_to_template urlpatterns = patterns('', - #(r'(?P[0-9a-zA-Z_.-]+)/$', 'locations.views.list_view_region'), + (r'data/(?P\d+)/$', 'locations.views.data_json'), (r'^$', direct_to_template, {'template': 'archives/map.html'}), ) diff --git a/apps/locations/views.py b/apps/locations/views.py index a59a2e5..f360429 100644 --- a/apps/locations/views.py +++ b/apps/locations/views.py @@ -2,10 +2,24 @@ from django.shortcuts import render_to_response,get_object_or_404 from django.template import RequestContext from blog.models import Entry -from locations.models import Location, Country, Region +from locations.models import Location, Country, Region, Route def list_view(request): - qs = Entry.objects.filter(status__exact=1) - cl = Country.objects.filter(visited=True).exclude(name='default') - rl = Region.objects.all() - return render_to_response('archives/map.html', {'object_list': qs,'country_list':cl,'region_list':rl}, context_instance=RequestContext(request)) \ No newline at end of file + context = { + 'object_list' : Entry.objects.filter(status__exact=1), + 'country_list' : Country.objects.filter(visited=True).exclude(name='default'), + 'region_list' : Region.objects.all() + } + return render_to_response('archives/map.html', context, context_instance=RequestContext(request)) + +from projects.shortcuts import render_to_geojson + +def data_json(request, id): + qs = Route.objects.filter(pk=id) + return render_to_geojson( + qs, + included_fields=['id',], + geom_attribute='geometry', + mimetype = 'application/json', + pretty_print=True + ) \ No newline at end of file diff --git a/apps/photos/views.py b/apps/photos/views.py index 861f00e..a1e3459 100644 --- a/apps/photos/views.py +++ b/apps/photos/views.py @@ -26,7 +26,7 @@ def gallery(request,slug): context = { 'object': PhotoGallery.objects.get(set_slug=slug) } - render_to_response('details/photo_galleries.html', context, context_instance = RequestContext(request)) + return render_to_response('details/photo_galleries.html', context, context_instance = RequestContext(request)) def photo_json(request, slug): p = PhotoGallery.objects.filter(set_slug=slug) diff --git a/base_urls.py b/base_urls.py index bc6f344..b0af128 100644 --- a/base_urls.py +++ b/base_urls.py @@ -39,10 +39,9 @@ urlpatterns += patterns('', ) urlpatterns += patterns('', - (r'^colophon/', redirect_to, {'url': '/about/'}), (r'^admin/doc/', include('django.contrib.admindocs.urls')), (r'^admin/filebrowser/', include('filebrowser.urls')), - (r'^admin/(.*)', admin.site.root), + (r'^admin/', include(admin.site.urls)), (r'^grappelli/', include('grappelli.urls')), (r'^feeds/(?P.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': feeds}), (r'^robots.txt$', direct_to_template, {'template': 'archives/robots.html'}), diff --git a/media/js/mainmap.js b/media/js/mainmap.js new file mode 100644 index 0000000..6db5a18 --- /dev/null +++ b/media/js/mainmap.js @@ -0,0 +1,1359 @@ + + + +function initialize() { + + //custom marker + var image = new google.maps.MarkerImage('http://media.luxagraf.net/img/marker-entry.png', + new google.maps.Size(15, 26), + new google.maps.Point(0, 0), + new google.maps.Point(7, 26) + ); + //custom marker shadow + var shadow = new google.maps.MarkerImage('http://media.luxagraf.net/img/shadow.png', + new google.maps.Size(37, 34), + new google.maps.Point(0,0), + new google.maps.Point(8, 34) + ); + + + //check for a permalink + var location = window.location.hash; + //find a centerpoint + var pts = new Array(); + pts[0] = ["#austria", 47.683,14.912,8];pts[1] = ["#cambodia", 12.714,104.564,7];pts[2] = ["#croatia", 45.723,16.693,7];pts[3] = ["#czech-republic", 49.9017112173,14.9963378906,7];pts[4] = ["#france", 46.565,2.55,6];pts[5] = ["#hungary", 47.07,19.134,7];pts[6] = ["#india", 21.0,78.5,5];pts[7] = ["#laos", 19.905,102.471,6];pts[8] = ["#nepal", 28.253,83.939,6];pts[9] = ["#nicaragua", 12.84,-85.034,7];pts[10] = ["#slovenia", 46.124,14.827,9];pts[11] = ["#thailand", 15.7,100.844,5];pts[12] = ["#united-kingdom", 53.0,-1.6,6];pts[13] = ["#united-states", 39.622,-98.606,4]; + pts[pts.length] = ["#central-america", 14.3708339734,-87.8686523438,6];pts[pts.length] = ["#southeast-asia", 12.2970682929,102.744140625,5];pts[pts.length] = ["#central-asia", 20.0146454453,79.892578125,5];pts[pts.length] = ["#europe", 47.0102256557,4.74609375,5];pts[pts.length] = ["#north-america", 39.0277188402,-98.349609375,4]; + if (location.length>1) { + for (i=0;i - - + + {% endblock %} {%block bodyid%}id="map" {%endblock%} -{% block bodyevents %}onload="initialize()" onunload="GUnload()"{% endblock %} +{% block bodyevents %}onload="initialize()"{% endblock %} @@ -36,8 +35,4 @@ Google Maps code
-{% endblock %} - -{% block js %} -{% include 'includes/map_entry_list.html' %} -{%endblock%} \ No newline at end of file +{% endblock %} \ No newline at end of file diff --git a/templates/details/photo_galleries.html b/templates/details/photo_galleries.html index 04e1088..41a5976 100644 --- a/templates/details/photo_galleries.html +++ b/templates/details/photo_galleries.html @@ -83,7 +83,7 @@
Camera:
{% if photo.exif_make == 'Canon'%}{{photo.exif_model}}{%endif%}{% if photo.exif_model == 'DMC-LX2'%}{{photo.exif_make}} {{photo.exif_model}}{%endif%}{%if photo.exif_model == 'DMC-GF1' %}{{photo.exif_make}} {{photo.exif_model}}{%endif%}
Lens:
-
{%if photo.exif_lens == 'LUMIX G VARIO 14-45/F3.5-5.6' %}{{photo.exif_lens}}{%endif%}{%if photo.exif_lens == 'LUMIX G 20/F1.7' %}{{photo.exif_lens}}{%endif%}{%if photo.exif_lens =='' %}Built-in{%endif%}
+
{%if photo.exif_lens == 'LUMIX G VARIO 14-45/F3.5-5.6' %}{{photo.exif_lens}}{%endif%}{%if photo.exif_lens == 'LUMIX G 20/F1.7' %}{{photo.exif_lens}}{%endif%}{%if photo.exif_lens == None %}Built-in{%endif%}
Exposure
{{photo.exif_exposure}}
Aperture
diff --git a/templates/includes/map_entry_list.html b/templates/includes/map_entry_list.html index b3fe171..51a299e 100644 --- a/templates/includes/map_entry_list.html +++ b/templates/includes/map_entry_list.html @@ -1,1036 +1,1308 @@ - \ No newline at end of file diff --git a/templates/includes/map_entry_list_template.html b/templates/includes/map_entry_list_template.html index 0705602..206430a 100644 --- a/templates/includes/map_entry_list_template.html +++ b/templates/includes/map_entry_list_template.html @@ -1,89 +1,107 @@ {% load typogrify %} {% load truncateletters %} {% load slugify_under %} - \ No newline at end of file + map.setZoom(zoom); + map.panTo(new google.maps.LatLng(latitude, longitude)); + routePath.setMap(map); + return false; +} diff --git a/templates/includes/map_sidebar.html b/templates/includes/map_sidebar.html index 880cd08..e024753 100644 --- a/templates/includes/map_sidebar.html +++ b/templates/includes/map_sidebar.html @@ -1,8 +1,13 @@ + +

Trips

Regions

    diff --git a/templates/includes/map_sidebar_template.html b/templates/includes/map_sidebar_template.html index ad1af1c..18dd118 100644 --- a/templates/includes/map_sidebar_template.html +++ b/templates/includes/map_sidebar_template.html @@ -1,8 +1,11 @@ +{% load truncateletters %} +{% load slugify_under %}

    Trips

    Regions

      -- cgit v1.2.3