From 6f97020d6b56f19d37a0941b299e68b2e8837d68 Mon Sep 17 00:00:00 2001 From: etienne Date: Tue, 4 Nov 2008 00:06:58 +0000 Subject: Icon dimensions are automatically got from the file for correct display on the map git-svn-id: http://www.peacefrogs.net/svn/chimere/trunk@2 9215b0d5-fb2c-4bbd-8d3e-bd2e9090e864 --- main/models.py | 20 ++++++++++++++------ static/main_map.js | 2 ++ urls.py | 2 -- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/main/models.py b/main/models.py index 6d673d8..d4ba9be 100644 --- a/main/models.py +++ b/main/models.py @@ -27,7 +27,8 @@ class Icon(models.Model): '''Icon ''' name = models.CharField(_("Name"), max_length=150) - image = models.ImageField(_("Image"), upload_to='icons') + image = models.ImageField(_("Image"), upload_to='icons', + height_field='height', width_field='width') def __unicode__(self): return self.name class Meta: @@ -67,7 +68,8 @@ class Marker(models.Model): name = models.CharField(_("Name"), max_length=150) subcategory = models.ForeignKey(SubCategory, verbose_name=_("Subcategory")) point = PointField(_("Localisation")) - picture = models.ImageField(_("Image"), upload_to='upload', blank=True) + picture = models.ImageField(_("Image"), upload_to='upload', blank=True, + height_field='height', width_field='width') STATUS = (('S', _('Submited')), ('A', _('Available')), ('D', _('Disabled')),) @@ -120,10 +122,16 @@ class Marker(models.Model): def getGeoJSON(self): '''Return a GeoJSON string ''' - return """{"type":"Feature", "geometry":{"type":"Point", "crs": "EPSG:%(epsg)d", "coordinates":[%(longitude)s, %(latitude)s]}, "properties":{"pk": %(id)d, "name": "%(name)s", "icon_path":"%(icon_path)s"}}""" \ - % {'id':self.id, 'name':self.name, 'icon_path':self.subcategory.icon.image, -'latitude':self.getLatitude(), 'longitude':self.getLongitude(), -'epsg':settings.EPSG_PROJECTION} + print self.subcategory.icon.image + return """{"type":"Feature", "geometry":{"type":"Point", \ +"crs": "EPSG:%(epsg)d", "coordinates":[%(longitude)s, %(latitude)s]}, \ +"properties":{"pk": %(id)d, "name": "%(name)s", \ +"icon_path":"%(icon_path)s", "icon_width":%(icon_width)d, \ +"icon_height":%(icon_height)d}}""" % {'id':self.id, 'name':self.name, +'icon_path':self.subcategory.icon.image, 'latitude':self.getLatitude(), +'longitude':self.getLongitude(), 'epsg':settings.EPSG_PROJECTION, +'icon_width':self.subcategory.icon.image.width, +'icon_height':self.subcategory.icon.image.height,} class PropertyModel(models.Model): '''Model for a property diff --git a/static/main_map.js b/static/main_map.js index 9bb703f..1d5d845 100644 --- a/static/main_map.js +++ b/static/main_map.js @@ -86,6 +86,8 @@ function putMarker(mark) { marker */ lat = mark.geometry.coordinates[1]; lon = mark.geometry.coordinates[0]; + var size = new OpenLayers.Size(mark.properties.icon_width, + mark.properties.icon_height); iconclone = new OpenLayers.Icon(media_path + mark.properties.icon_path, size, offset); var feature = new OpenLayers.Feature(markers, diff --git a/urls.py b/urls.py index 0f45476..6b7365c 100644 --- a/urls.py +++ b/urls.py @@ -16,8 +16,6 @@ urlpatterns = patterns('', 'chimere.main.views.getDetail'), (r'^chimere/getMarkers/(?P\w+)/$', 'chimere.main.views.getMarkers'), - (r'^chimere/static/(?P.*)$', 'django.views.static.serve', - {'document_root': 'static/'}), (r'^chimere/static/(?P.*)$', 'django.views.static.serve', {'document_root': ROOT_PATH + 'static/'}), (r'^chimere/media/(?P.*)$', 'django.views.static.serve', -- cgit v1.2.3