diff options
| author | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-04-05 14:28:35 +0200 |
|---|---|---|
| committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-04-05 14:28:35 +0200 |
| commit | 426eb4711ff92cc0e6df9cd1004ff322f112c814 (patch) | |
| tree | a1884d4c36beb027207a964974ca3f7c3d0a9eb5 | |
| parent | 1ab25dfc2603d6145a7ca6100558e470761ce766 (diff) | |
| download | Chimère-426eb4711ff92cc0e6df9cd1004ff322f112c814.tar.bz2 Chimère-426eb4711ff92cc0e6df9cd1004ff322f112c814.zip | |
Weighted markers: first display with Leaflet
| -rw-r--r-- | chimere/models.py | 17 | ||||
| -rw-r--r-- | chimere/static/chimere/js/jquery.chimere-leaflet.js | 17 |
2 files changed, 27 insertions, 7 deletions
diff --git a/chimere/models.py b/chimere/models.py index 3400118..c269439 100644 --- a/chimere/models.py +++ b/chimere/models.py @@ -171,7 +171,8 @@ class Color(models.Model): """ code = models.CharField(_(u"Code"), max_length=6) order = models.IntegerField(_(u"Order")) - color_theme = models.ForeignKey(ColorTheme, verbose_name=_(u"Color theme")) + color_theme = models.ForeignKey(ColorTheme, verbose_name=_(u"Color theme"), + related_name='colors') def __unicode__(self): return self.code class Meta: @@ -637,14 +638,24 @@ class Marker(GeographicItem): if cat.hover_icon else '', 'icon_width':cat.icon.image.width, 'icon_height':cat.icon.image.height, - 'category_name':json.dumps(cat.name)} + 'category_name':json.dumps(cat.name),} + items['weight'] = '' + if cat.weighted: + if not self.weight: + continue + items['weight'] = u', "weight":%d' % self.weight + if cat.color_theme and cat.color_theme.colors.count(): + items['weight'] += u', "colors":["#%s"]' % '", "#'.join( + [color.code for color in cat.color_theme.colors.\ + order_by('order').all()]) jsons.append(u'{"type":"Feature", "geometry":%(geometry)s, '\ u'"properties":{"pk": %(id)d, "name": %(name)s, '\ u'"icon_path":"%(icon_path)s", '\ u'"icon_hover_path":"%(icon_hover_path)s", '\ u'"icon_width":%(icon_width)d, '\ u'"icon_height":%(icon_height)d, '\ - u'"category_name":%(category_name)s}}' % items) + u'"category_name":%(category_name)s'\ + u'%(weight)s}}' % items) return ",".join(jsons) @property diff --git a/chimere/static/chimere/js/jquery.chimere-leaflet.js b/chimere/static/chimere/js/jquery.chimere-leaflet.js index 569f9f5..5e0e811 100644 --- a/chimere/static/chimere/js/jquery.chimere-leaflet.js +++ b/chimere/static/chimere/js/jquery.chimere-leaflet.js @@ -125,12 +125,21 @@ See the file COPYING for details. layer.bindPopup(feature.properties.name); }, pointToLayer: function (feature, latlng) { - if (feature.properties.weigthed){ + if (feature.properties.weight){ + var fill_color = "#ff7800"; + if (feature.properties.colors){ + var idx = feature.properties.weight/5; + if (idx < feature.properties.colors.length){ + fill_color = feature.properties.colors[idx]; + } else { + fill_color = feature.properties.colors[feature.properties.colors.length-1]; + } + } var geojsonMarkerOptions = { - radius: 8, - fillColor: "#ff7800", + radius: feature.properties.weight*2, + fillColor: fill_color, color: "#000", - weight: 1, + weight: feature.properties.weight/2, opacity: 1, fillOpacity: 0.8 }; |
