summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/models.py21
-rw-r--r--ishtar_common/static/js/ishtar-map.js60
-rw-r--r--ishtar_common/templates/ishtar/blocks/sheet_simple_map.html15
3 files changed, 87 insertions, 9 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index ea6bd3bf0..bd6c38ff1 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -47,6 +47,7 @@ from django.contrib.postgres.search import SearchVectorField, SearchVector
from django.core.cache import cache
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.core.files.uploadedfile import SimpleUploadedFile
+from django.core.serializers import serialize
from django.core.urlresolvers import reverse, NoReverseMatch
from django.core.validators import validate_slug
from django.db import connection
@@ -1609,7 +1610,25 @@ class DocumentItem(object):
return actions
-class BaseHistorizedItem(DocumentItem, FullSearch, Imported, JsonData,
+class GeoItem(object):
+ @property
+ def point_2d_geojson(self):
+ if not hasattr(self, 'point_2d'):
+ return ""
+ return serialize('geojson', self.__class__.objects.filter(pk=self.pk),
+ geometry_field='point_2d',
+ fields=('cache_complete_id',))
+
+ @property
+ def multi_polygon_geojson(self):
+ if not hasattr(self, 'multi_polygon'):
+ return ""
+ return serialize('geojson', self.__class__.objects.filter(pk=self.pk),
+ geometry_field='multi_polygon',
+ fields=('cache_complete_id',))
+
+
+class BaseHistorizedItem(DocumentItem, FullSearch, Imported, JsonData, GeoItem,
FixAssociated):
"""
Historized item with external ID management.
diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js
index 226767914..ceef3a59e 100644
--- a/ishtar_common/static/js/ishtar-map.js
+++ b/ishtar_common/static/js/ishtar-map.js
@@ -52,6 +52,18 @@ var get_icon_style = function(feature){
});
};
+var get_vector_style = function(feature){
+ return new ol.style.Style({
+ stroke: new ol.style.Stroke({
+ color: 'red',
+ width: 2
+ }),
+ fill: new ol.style.Fill({
+ color: 'rgba(255,0,0,0.2)'
+ })
+ });
+};
+
var cluster_get_style = function(feature, resolution){
feature.set('key', 'cluster');
var cluster_features = feature.get('features');
@@ -356,6 +368,9 @@ var proj_options = {
var geojson_format = new ol.format.GeoJSON(proj_options);
var wkt_format = new ol.format.WKT(proj_options);
var link_template;
+var vector_source;
+var vector_layer;
+var vector_features;
var initialize_base_map = function(layers){
center = wkt_format.readGeometry(map_default_center).getCoordinates();
@@ -385,27 +400,56 @@ var redraw_map = function(layers){
};
-var display_map = function(current_map_id, points, layers){
- link_template = points['link_template'];
+var display_map = function(current_map_id, points, lines_and_polys, layers){
+ if (points){
+ link_template = points['link_template'];
+ } else {
+ /// link_template = lines_and_polys['link_template'];
+ }
map_id = current_map_id;
if (map){
redraw_map(layers);
} else {
initialize_base_map(layers);
}
- point_features = geojson_format.readFeatures(points);
+ display_points(points);
+ display_lines_and_polys(lines_and_polys);
- enable_clustering();
- cluster_source.getSource().addFeatures(point_features);
init_popup();
+ map.on('click', manage_click_on_map);
+ map.on('pointermove', manage_hover);
+};
+
+var display_points = function(points){
+ if (!points) return;
+ point_features = geojson_format.readFeatures(points);
+ enable_clustering();
+ cluster_source.getSource().addFeatures(point_features);
if (points.features.length){
map_view.fit(cluster_source.getSource().getExtent());
if (map_view.getZoom() > 12){
map_view.setZoom(12);
}
}
+};
- map.on('click', manage_click_on_map);
- map.on('pointermove', manage_hover);
-}
+var display_lines_and_polys = function(lines_and_polys){
+ if (!lines_and_polys) return;
+ vector_features = geojson_format.readFeatures(lines_and_polys);
+ vector_source = new ol.source.Vector();
+ vector_layer = new ol.layer.Vector({
+ source: vector_source,
+ style: get_vector_style
+ });
+ vector_source.addFeatures(vector_features);
+ vector_source.addFeature(new ol.Feature(
+ new ol.geom.Circle([6.079860710813087, 43.11452983279191], 2))) ;
+ map_layers.push(vector_layer);
+ if (lines_and_polys.features.length){
+ map_view.fit(vector_source.getExtent());
+ if (map_view.getZoom() > 12){
+ map_view.setZoom(12);
+ }
+ }
+};
diff --git a/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html b/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html
new file mode 100644
index 000000000..bf25db653
--- /dev/null
+++ b/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html
@@ -0,0 +1,15 @@
+{% if geo_item.point_2d or geo_item.multi_polygon %}
+<div class="window-map"
+ id="map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}"></div>
+
+<script type="text/javascript">
+{% if geo_item.point_source == 'P' or not geo_item.multi_polygon %}
+var {{geo_item.SLUG}}{{geo_item.pk}} = {{geo_item.point_2d_geojson|safe}};
+display_map("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", {{geo_item.SLUG}}{{geo_item.pk}});
+{% else %}
+var {{geo_item.SLUG}}{{geo_item.pk}} = {{geo_item.multi_polygon_geojson|safe}};
+display_map("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", null, {{geo_item.SLUG}}{{geo_item.pk}});
+{% endif %}
+</script>
+
+{% endif %}