diff options
author | Étienne Loks <etienne@peacefrogs.net> | 2019-02-06 19:08:42 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-04-24 19:38:56 +0200 |
commit | 7940a5e8379f822da0514e3f9068f9b3221331e3 (patch) | |
tree | 40856bb52074133833bb506a57118d11b96a0dfa | |
parent | 251a3124d2c462620a5f6ecfff9160f853a113b0 (diff) | |
download | Ishtar-7940a5e8379f822da0514e3f9068f9b3221331e3.tar.bz2 Ishtar-7940a5e8379f822da0514e3f9068f9b3221331e3.zip |
Sheet - Map: WIP - manage vector source for polygons
-rw-r--r-- | archaeological_context_records/models.py | 2 | ||||
-rw-r--r-- | archaeological_finds/models_finds.py | 1 | ||||
-rw-r--r-- | archaeological_finds/templates/ishtar/sheet_basefind.html | 39 | ||||
-rw-r--r-- | ishtar_common/models.py | 21 | ||||
-rw-r--r-- | ishtar_common/static/js/ishtar-map.js | 60 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/blocks/sheet_simple_map.html | 15 | ||||
-rw-r--r-- | scss/custom.scss | 6 |
7 files changed, 119 insertions, 25 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 4b41fddb7..71551a49d 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -539,7 +539,7 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem, def get_town_polygons(self): if self.town: return self.town.limit - return self.operation.get_town_polygon() + return self.operation.get_town_polygons() @classmethod def cached_label_bulk_update(cls, operation_id=None, parcel_id=None, diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 3f0ade1df..9d16cb66b 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -267,6 +267,7 @@ class BFBulkView(object): class BaseFind(BulkUpdatedItem, BaseHistorizedItem, OwnPerms): EXTERNAL_ID_KEY = 'base_find_external_id' EXTERNAL_ID_DEPENDENCIES = ['find'] + SLUG = 'basefind' label = models.TextField(_(u"Free ID")) external_id = models.TextField(_(u"External ID"), blank=True, null=True) auto_external_id = models.BooleanField( diff --git a/archaeological_finds/templates/ishtar/sheet_basefind.html b/archaeological_finds/templates/ishtar/sheet_basefind.html index 7ea16fecb..74a2b527e 100644 --- a/archaeological_finds/templates/ishtar/sheet_basefind.html +++ b/archaeological_finds/templates/ishtar/sheet_basefind.html @@ -45,9 +45,31 @@ {% field_flex_full "Description" base_find.description "<pre>" "</pre>" first %} {% field_flex_full "Comment" base_find.comment "<pre>" "</pre>" first %} </div> + <h3>{% trans "Sheet"%}</h3> + <div class='row'> + {% with item.history_creation_date|date:"SHORT_DATETIME_FORMAT" as creation_date %} + {% with item.history_creator.ishtaruser.full_label|add:"<br/><i>"|add:creation_date|add:"</i>" as creator %} + {% field_flex "Created by" creator|safe '' '' first %} + {% endwith %}{% endwith %} + {% if item.history_creation_date != item.last_edition_date %} + {% with item.last_edition_date|date:"SHORT_DATETIME_FORMAT" as edition_date %} + {% with item.history_modifier.ishtaruser.full_label|add:"<br/><i>"|add:edition_date|add:"</i>" as modifier %} + {% trans "Last modified by" as lastmodifiedby_label %} + {% field_flex lastmodifiedby_label modifier|safe '' '' first %} + {% endwith %}{% endwith %} + {% endif %} + </div> + {% if base_find.point_2d or base_find.x or base_find.y or base_find.topographic_localisation %} + {% if base_find.point_2d %} + <div class="clearfix"> + </div> + {% endif %} + <h3>{% trans "Map"%}</h3> + {% with geo_item=base_find %} + {% include "ishtar/blocks/sheet_simple_map.html"%} + {% endwith %} {% if base_find.x or base_find.y or base_find.topographic_localisation %} - <h3>{% trans "Coordinates"%}</h3> <div class='row'> {% field_flex "Point of topographic reference" base_find.topographic_localisation %} <dl class="col-12 d-flex flex-wrap row"> @@ -67,19 +89,6 @@ </dl> </div> {% endif %} - <h3>{% trans "Sheet"%}</h3> - <div class='row'> - {% with item.history_creation_date|date:"SHORT_DATETIME_FORMAT" as creation_date %} - {% with item.history_creator.ishtaruser.full_label|add:"<br/><i>"|add:creation_date|add:"</i>" as creator %} - {% field_flex "Created by" creator|safe '' '' first %} - {% endwith %}{% endwith %} - {% if item.history_creation_date != item.last_edition_date %} - {% with item.last_edition_date|date:"SHORT_DATETIME_FORMAT" as edition_date %} - {% with item.history_modifier.ishtaruser.full_label|add:"<br/><i>"|add:edition_date|add:"</i>" as modifier %} - {% trans "Last modified by" as lastmodifiedby_label %} - {% field_flex lastmodifiedby_label modifier|safe '' '' first %} - {% endwith %}{% endwith %} - {% endif %} - </div> + {% endif %} </div> 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 %} diff --git a/scss/custom.scss b/scss/custom.scss index c577c7def..1d7088cab 100644 --- a/scss/custom.scss +++ b/scss/custom.scss @@ -690,6 +690,12 @@ ul.compact{ overflow-y: auto; } +.window-map{ + width: 100%; + height: 300px; + padding-bottom: 1em; +} + .ishtar-table-map{ width: 100%; height: 50%; |