summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorQuentinAndre <quentin.andre@imt-atlantique.net>2021-07-26 14:43:05 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-11-16 17:04:41 +0100
commit568e79635b5447299553451848132ffac6ea2451 (patch)
treee642a555490b4ab93f475a66b0ca0e8c47d0f931 /ishtar_common
parentc217e7b18bc499f336d9679f4821078ee2ff1a61 (diff)
downloadIshtar-568e79635b5447299553451848132ffac6ea2451.tar.bz2
Ishtar-568e79635b5447299553451848132ffac6ea2451.zip
url with get and display geo items
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/static/js/ishtar-map.js109
-rw-r--r--ishtar_common/templates/ishtar/blocks/sheet_geo_items.html48
-rw-r--r--ishtar_common/templates/ishtar/blocks/sheet_simple_map.html56
-rw-r--r--ishtar_common/urls.py1
4 files changed, 204 insertions, 10 deletions
diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js
index a93813e61..b22467668 100644
--- a/ishtar_common/static/js/ishtar-map.js
+++ b/ishtar_common/static/js/ishtar-map.js
@@ -285,7 +285,9 @@ var enable_clustering = function(map_id){
};
var reinit_clustering = function(map_id){
- cluster_source[map_id].getSource().clear();
+ if (map_id in cluster_source) {
+ cluster_source[map_id].getSource().clear();
+ }
_styleCache = {};
};
@@ -642,3 +644,108 @@ var display_lines_and_polys = function(map_id, lines_and_polys){
map_view[map_id].fit(vector_source[map_id].getExtent());
}
};
+
+var disp_geo_items = function(map_id, base_url, slug, pk, display_both) {
+ var url = base_url;
+ if (slug === "operation") {
+ url += "?operation_pk=";
+ }
+ else {
+ url += "?context_record_pk=";
+ }
+ url += pk;
+
+ httpRequest = new XMLHttpRequest();
+ if (!httpRequest) { return; }
+ httpRequest.onreadystatechange = function() {
+ if (httpRequest.readyState === XMLHttpRequest.DONE) {
+ if (httpRequest.status === 200) {
+ geo_items = to_geo_items(JSON.parse(httpRequest.responseText), slug, display_both)
+ for (geo_item of geo_items['base-finds']) {
+ display_associated_polys(map_id, geo_item, 'basefind');
+ }
+ for (geo_item of geo_items['context-records']) {
+ display_associated_polys(map_id, geo_item, 'contextrecord');
+ }
+ } else { return; }
+ }
+ };
+ httpRequest.open('GET', url, true);
+ httpRequest.send();
+};
+
+var to_geo_items = function (obj, slug, display_both) {
+ var objects = {'context-records': [], 'base-finds': []};
+ if (slug === "operation") {
+ var crs = obj['properties']['context-records'];
+ for (cr of crs['features']) {
+ if (display_both) {
+ objects['base-finds'].push(cr['properties']['base-finds'])
+ }
+ delete cr['properties'];
+ }
+ objects['context-records'].push(crs);
+ }
+ else {
+ objects['base-finds'].push(obj['properties']['base-finds'])
+ }
+ return objects;
+}
+
+var display_associated_polys = function (map_id, polys, slug) {
+ _vector_features = geojson_format.readFeatures(polys);
+ _vector_source = new ol.source.Vector();
+ _vector_source.addFeatures(_vector_features);
+ style = get_associated_base_find_style;
+ if (slug === 'contextrecord') {
+ style = get_associated_context_record_style;
+ }
+ _vector_layer = new ol.layer.Vector({
+ source: _vector_source,
+ style: style
+ });
+ map[map_id].addLayer(_vector_layer);
+}
+
+var get_associated_base_find_style = function (feature) {
+ return new ol.style.Style({
+ stroke: new ol.style.Stroke({
+ color: 'rgba(0, 0, 0, 1)',
+ width: 2
+ }),
+ fill: new ol.style.Fill({
+ color: 'rgba(O, O, O, 0.2)'
+ })
+ });
+};
+
+var get_associated_context_record_style = function (feature) {
+ return new ol.style.Style({
+ stroke: new ol.style.Stroke({
+ color: 'rgba(255, 255, 255, 1)',
+ width: 2
+ }),
+ fill: new ol.style.Fill({
+ color: 'rgba(255, 255, 255, 0.2)'
+ })
+ });
+};
+
+var display_associated_points = function (map_id, points, slug) {
+ _point_features = geojson_format.readFeatures(points);
+ _cluster_source = new ol.source.Cluster({
+ distance: 40,
+ source: new ol.source.Vector()
+ });
+ style = get_associated_base_find_style;
+ if (slug === 'contextrecord') {
+ style = get_associated_context_record_style;
+ }
+ _cluster_layer = new ol.layer.Vector({
+ name: 'Cluster',
+ source: _cluster_source,
+ style: style
+ });
+ map[map_id].addLayer(_cluster_layer);
+ _cluster_source.getSource().addFeatures(_point_features);
+} \ No newline at end of file
diff --git a/ishtar_common/templates/ishtar/blocks/sheet_geo_items.html b/ishtar_common/templates/ishtar/blocks/sheet_geo_items.html
new file mode 100644
index 000000000..451453d59
--- /dev/null
+++ b/ishtar_common/templates/ishtar/blocks/sheet_geo_items.html
@@ -0,0 +1,48 @@
+{% load i18n window_field %}{% if PROFILE.mapping %}
+{% if geo_item.point_2d or geo_item.multi_polygon %}
+<dl class="col-12">
+ <dt>{% trans "Display geo items" %}</dt>
+ <dd>
+ <label for="display-geo-items">{% trans "Display associated features: " %}</label>
+ <select name="display-geo-items" id="display-geo-items">
+ <option value="" selected="selected">{% trans "None" %}</option>
+ <option id="disp-context-records" value="contextrecords">{% trans "Context records" %}</option>
+ <option value="basefinds">{% trans "Base finds" %}</option>
+ </select>
+ </dd>
+ <dd>
+ <label for="get-polygons" id="label-get-polygons">{% trans "Geometry: " %}</label>
+ <select name="get-polygons" id="get-polygons">
+ <option value="polygons" selected="selected">{% trans "Display polygons" %}</option>
+ <option value="points">{% trans "Display points" %}</option>
+ </select>
+ </dd>
+</dl>
+<script>
+var hide_context_records = function() {
+ if ("{{geo_item.SLUG}}" === "contextrecord") {
+ const disp_cr = $("#disp-context-records")[0];
+ disp_cr.hidden = true;
+ }
+}
+hide_context_records();
+
+var hide_get_polygons = function() {
+ const disp = $("#display-geo-items")[0];
+ const get_poly = $("#get-polygons")[0];
+ const label = $("#label-get-polygons")[0];
+ get_poly.hidden = true;
+ label.hidden = true;
+ disp.addEventListener('change', (event) => {
+ if (event.target.value === "") {
+ get_poly.hidden = true;
+ label.hidden = true;
+ get_poly.value = "";
+ } else { get_poly.hidden = false;
+ label.hidden = false;}
+ })
+}
+hide_get_polygons();
+</script>
+{% endif %}
+{% endif %} \ No newline at end of file
diff --git a/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html b/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html
index d755fe531..b475e7343 100644
--- a/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html
+++ b/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html
@@ -6,15 +6,53 @@
<div id="map-content-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}"></div>
</div>
<script type="text/javascript">
-var html = render_map("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", false, true);
-$("#map-content-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}").html(html);
-{% if geo_item.most_precise_geo == 'point' %}
-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 %}
+var disp_map = function() {
+ var html = render_map("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", false, true);
+ $("#map-content-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}").html(html);
+ {% if geo_item.most_precise_geo == 'point' %}
+ 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 %}
+}
+disp_map();
+
+if ("{{geo_item.SLUG}}" === 'contextrecord' || "{{geo_item.SLUG}}" === 'operation') {
+ var display_geo_items = function(disp, get_polygons) {
+ var display_both = false;
+ if ((disp === "basefinds") && ("{{geo_item.SLUG}}" === "operation")) {
+ display_both = true;
+ }
+ var url = null;
+ if (get_polygons === "Points") {
+ url = "{% url 'archaeological_finds:api-get-geo-points' %}";
+ }
+ else {
+ url = "{% url 'archaeological_finds:api-get-geo-polygons' %}";
+ }
+ disp_geo_items("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", url, "{{geo_item.SLUG}}", "{{geo_item.pk}}", display_both);
+ }
+
+ var geo_items_displayed_once = false;
+ var disp = $("#display-geo-items")[0];
+ var get_polygons = $("#get-polygons")[0];
+ disp.addEventListener('change', (event) => {
+ if (geo_items_displayed_once) {
+ disp_map();
+ }
+ if (disp.value !== "") {
+ console.log("geo items");
+ display_geo_items(disp.value, get_polygons.value);
+ geo_items_displayed_once = true;
+ }
+ })
+ get_polygons.addEventListener('change', (event) => {
+ disp_map();
+ display_geo_items(disp.value, get_polygons.value);
+ })
+}
</script>
{% endif %}
{% endif %}
diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py
index 9266a7a9a..7fe905c33 100644
--- a/ishtar_common/urls.py
+++ b/ishtar_common/urls.py
@@ -559,6 +559,7 @@ urlpatterns += [
views.QANotAvailable.as_view(),
name="qa-not-available",
),
+ url(r"^", include("archaeological_finds.urls", namespace="archaeological_finds")),
]
urlpatterns += get_urls_for_model(models.Document, views, own=True)