OpenStreetMap Integration
This commit is contained in:
parent
1220aa8a11
commit
192fe2d974
|
@ -10,6 +10,10 @@ class Country(models.Model):
|
|||
class Meta:
|
||||
verbose_name_plural ='Pays'
|
||||
verbose_name = 'Pays'
|
||||
ordering = ['label']
|
||||
|
||||
def __str__(self):
|
||||
return self.label
|
||||
|
||||
def __unicode__(self):
|
||||
return self.label
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
from osm.models import *
|
||||
from django.contrib import admin
|
||||
|
||||
admin.site.register(Coordinates)
|
|
@ -0,0 +1 @@
|
|||
[{"pk": 1, "model": "osm.coordinates", "fields": {"latitude": "46.6", "country": 1, "longitude": "1.89"}}, {"pk": 2, "model": "osm.coordinates", "fields": {"latitude": "54.7024", "country": 2, "longitude": "-3.2766"}}, {"pk": 3, "model": "osm.coordinates", "fields": {"latitude": "50.5996", "country": 4, "longitude": "4.4097"}}, {"pk": 4, "model": "osm.coordinates", "fields": {"latitude": "14.475", "country": 5, "longitude": "-14.4529"}}]
|
|
@ -0,0 +1,20 @@
|
|||
#coding=utf-8
|
||||
|
||||
from django.db import models
|
||||
from xcards.cards.models import Country
|
||||
|
||||
# Create your models here.
|
||||
class Coordinates(models.Model):
|
||||
"""
|
||||
Représentation des coordonnées pour un pays au format DD (Degré Décimal) eg. (49.5000 - 123.5000)
|
||||
"""
|
||||
latitude = models.DecimalField(max_digits=7, decimal_places=4, verbose_name='Latitude')
|
||||
longitude = models.DecimalField(max_digits=8, decimal_places=4, verbose_name='Longitude')
|
||||
country = models.OneToOneField(Country, verbose_name='Pays')
|
||||
|
||||
def __unicode__(self):
|
||||
return '%s - Lat: %s Long: %s )' % (self.country, str(self.latitude), str(self.longitude))
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = 'Coordonnées'
|
||||
verbose_name = 'Coordonnées'
|
|
@ -0,0 +1,13 @@
|
|||
from django import template
|
||||
from django.conf import settings
|
||||
from django.utils.numberformat import format
|
||||
from osm.models import Coordinates
|
||||
|
||||
register = template.Library()
|
||||
|
||||
def floatdot(value, separator=".", decimal_pos=4):
|
||||
return format(value, separator, decimal_pos)
|
||||
|
||||
floatdot.is_safe = True
|
||||
|
||||
register.filter(floatdot)
|
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
This file demonstrates writing tests using the unittest module. These will pass
|
||||
when you run "manage.py test".
|
||||
|
||||
Replace this with more appropriate tests for your application.
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
def test_basic_addition(self):
|
||||
"""
|
||||
Tests that 1 + 1 always equals 2.
|
||||
"""
|
||||
self.assertEqual(1 + 1, 2)
|
|
@ -0,0 +1,21 @@
|
|||
# Create your views here.
|
||||
|
||||
#coding=utf-8
|
||||
|
||||
from django.shortcuts import render_to_response, get_object_or_404
|
||||
from django.http import HttpResponseRedirect, HttpResponse, Http404
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.template import RequestContext
|
||||
from django import forms
|
||||
from cards.models import Card, Country, Category, SubCategory
|
||||
from django.core.context_processors import csrf
|
||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||
|
||||
from osm.models import Coordinates
|
||||
|
||||
def map(request):
|
||||
coordinates = Coordinates.objects.all()
|
||||
|
||||
context = { 'coordinates' : coordinates }
|
||||
|
||||
return render_to_response('osm/map.html', RequestContext(request, context))
|
|
@ -128,6 +128,7 @@ INSTALLED_APPS = (
|
|||
'django.contrib.admin',
|
||||
'django.contrib.admindocs',
|
||||
'cards',
|
||||
'osm',
|
||||
)
|
||||
|
||||
# A sample logging configuration. The only tangible logging
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
{% load osm_tags %}
|
||||
|
||||
<html>
|
||||
<body>
|
||||
<div id="mapdiv"></div>
|
||||
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
|
||||
<script>
|
||||
map = new OpenLayers.Map("mapdiv");
|
||||
map.addLayer(new OpenLayers.Layer.OSM());
|
||||
|
||||
var zoom=2;
|
||||
|
||||
var markers = new OpenLayers.Layer.Markers( "Markers" );
|
||||
map.addLayer(markers);
|
||||
|
||||
{% for coord in coordinates %}
|
||||
var lonLat = new OpenLayers.LonLat({{ coord.longitude|floatdot }}, {{ coord.latitude|floatdot }})
|
||||
.transform(
|
||||
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
|
||||
map.getProjectionObject() // to Spherical Mercator Projection
|
||||
);
|
||||
|
||||
// A popup with some information about our location
|
||||
var popup = new OpenLayers.Popup.FramedCloud("Popup",
|
||||
lonLat.getBounds().getCenterLonLat(), null,
|
||||
'<a target="_blank" href="http://openlayers.org/">We</a> ' +
|
||||
'could be here.<br>Or elsewhere.', null,
|
||||
true // <-- true if we want a close (X) button, false otherwise
|
||||
);
|
||||
|
||||
markers.addMarker(new OpenLayers.Marker(lonLat));
|
||||
map.addPopup(popup);
|
||||
|
||||
{% endfor %}
|
||||
|
||||
map.addControl(new OpenLayers.Control.PanZoomBar());
|
||||
map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false}));
|
||||
map.addControl(new OpenLayers.Control.Permalink());
|
||||
map.addControl(new OpenLayers.Control.Permalink('permalink'));
|
||||
map.addControl(new OpenLayers.Control.MousePosition());
|
||||
map.addControl(new OpenLayers.Control.OverviewMap());
|
||||
map.addControl(new OpenLayers.Control.KeyboardDefaults());
|
||||
|
||||
map.setCenter (lonLat, zoom);
|
||||
</script>
|
||||
<ul>
|
||||
{% for coord in coordinates %}
|
||||
<li>{{ coord }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</body></html>
|
1
urls.py
1
urls.py
|
@ -16,6 +16,7 @@ urlpatterns = patterns('',
|
|||
url(r'^list/country/(?P<country_id>\d+)/$', 'cards.views.search_by_country', name='list-by-country'),
|
||||
url(r'^list/category/(?P<category_id>\d+)/$', 'cards.views.search_by_category', name='list-by-category'),
|
||||
url(r'^list/subcategory/(?P<subcategory_id>\d+)/$', 'cards.views.search_by_subcategory', name='list-by-subcategory'),
|
||||
url(r'^map/$', 'osm.views.map', name='map'),
|
||||
|
||||
|
||||
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
|
||||
|
|
Loading…
Reference in New Issue