summaryrefslogtreecommitdiff
path: root/ishtar_common/static
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2022-09-08 17:49:05 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-12 12:23:18 +0100
commitf115f144dc01a41c1373485416488b77ecaa62fc (patch)
tree95fc53fcdc8959da12250e0a4f49b35e0af902d3 /ishtar_common/static
parent392a3508b2a5bfe266844b5be4ab58a01caff766 (diff)
downloadIshtar-f115f144dc01a41c1373485416488b77ecaa62fc.tar.bz2
Ishtar-f115f144dc01a41c1373485416488b77ecaa62fc.zip
Geo display: clean old code - manage bad data
Diffstat (limited to 'ishtar_common/static')
-rw-r--r--ishtar_common/static/js/ishtar-map.js173
1 files changed, 12 insertions, 161 deletions
diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js
index ae591db08..8ffe399d6 100644
--- a/ishtar_common/static/js/ishtar-map.js
+++ b/ishtar_common/static/js/ishtar-map.js
@@ -529,6 +529,9 @@ var open_map_window = function(map_id){
var complete_list_label = "complete list...";
+var map_display_base_url_start = "<a class='display_details' href='#' onclick='load_window(\"";
+var map_display_base_url_end = "\")'><i class='fa fa-info-circle' aria-hidden='true'></i></a>";
+
var _display_items = function(map_id, features, offset_x, offset_y){
// console.log("display_items");
var feature = features[0];
@@ -549,7 +552,10 @@ var _display_items = function(map_id, features, offset_x, offset_y){
if (link_template[map_id]){
link = link_template[map_id].replace("<pk>", properties["id"]);
}
- var txt = "<li>" + link + " " + properties['name'] + "</li>";
+ if ("url" in properties){
+ link = map_display_base_url_start + properties["url"] + map_display_base_url_end;
+ }
+ var txt = "<li>" + link + " " + properties["name"] + "</li>";
window_content += txt;
if (idx_feat < 5){
popup_content += txt;
@@ -728,8 +734,7 @@ var display_points = function(map_id, points, first_init){
if (!cluster_source[map_id]){
enable_clustering(map_id);
} else {
- cluster_source[map_id].getSource().clear();
- cluster_source[map_id].getSource().refresh();
+ reinit_clustering(map_id);
}
cluster_source[map_id].getSource().addFeatures(point_features[map_id]);
if (first_init && points.features && points.features.length){
@@ -761,160 +766,6 @@ var display_lines_and_polys = function(map_id, lines_and_polys, first_init){
}
};
-var display_geo_items = function(map_id, base_url, slug, pk,
- disp_cr, disp_bf, get_poly) {
- let 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) {
- const geo_items = to_geo_items(JSON.parse(httpRequest.responseText), slug, disp_cr, disp_bf)
- if (current_test) {
- geo_items_features[map_id] = [];
- }
- let bfs = null;
- let crs = null;
- if (get_poly) {
- bfs = display_associated_polys(map_id, geo_items['base-finds'], 'basefind');
- crs = display_associated_polys(map_id, geo_items['context-records'], 'contextrecord');
- } else {
- bfs = display_associated_points(map_id, geo_items['base-finds'], 'basefind');
- crs = display_associated_points(map_id, geo_items['context-records'], 'contextrecord');
- }
- if (current_test) {
- geo_items_features[map_id].push(bfs)
- geo_items_features[map_id].push(crs)
- $("#http-geo-items-ready-"+slug+"-"+pk).show();
- }
- } else { return; }
- }
- };
- httpRequest.open('GET', url, true);
- httpRequest.send();
-};
-
-var to_geo_items = function (obj, slug, disp_cr, disp_bf) {
- const objects = {'context-records': {'features': [], 'type': 'FeatureCollection'},
- 'base-finds': {'features': [], 'type': 'FeatureCollection'}};
- if (slug === "operation") {
- const crs = obj['properties']['context-records'];
- for (const cr of crs['features']) {
- if (disp_bf) {
- for (const bf of cr['properties']['base-finds']['features']) {
- objects['base-finds']['features'].push(bf)
- }
- }
- delete cr['properties'];
- if (disp_cr) {
- objects['context-records']['features'].push(cr)
- }
- }
- }
- else {
- for (const bf of obj['properties']['base-finds']['features']) {
- objects['base-finds']['features'].push(bf)
- }
- }
- return objects;
-}
-
-var display_associated_polys = function (map_id, polys, slug) {
- const _vector_features = geojson_format.readFeatures(polys);
- const _vector_source = new ol.source.Vector();
- _vector_source.addFeatures(_vector_features);
- let style = get_associated_base_find_style;
- if (slug === 'contextrecord') {
- style = get_associated_context_record_style;
- }
- const _vector_layer = new ol.layer.Vector({
- source: _vector_source,
- style: style
- });
- map[map_id].addLayer(_vector_layer);
- return _vector_features
-}
-
-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)'
- }),
- radius: 10
- });
-};
-
-var display_associated_points = function (map_id, points, slug) {
- const _point_features = geojson_format.readFeatures(points);
- const _cluster_source = new ol.source.Cluster({
- distance: 40,
- source: new ol.source.Vector()
- });
- _cluster_source.getSource().addFeatures(_point_features);
- // TODO: create own style
- const style = cluster_get_style;
- const _cluster_layer = new ol.layer.Vector({
- name: 'Cluster',
- source: _cluster_source,
- style: style
- });
- map[map_id].addLayer(_cluster_layer);
- return _point_features;
-}
-
-var get_features_by_id = function (id) {
- let base_features = null
- if (vector_features[id] == null) {
- base_features = geojson_format.writeFeaturesObject(point_features[id], {decimals: 5});
- } else {
- base_features = geojson_format.writeFeaturesObject(vector_features[id], {decimals: 5});
- }
- const geo_items_feats = [];
- if (geo_items_features && id in geo_items_features) {
- for (const features of geo_items_features[id]) {
- geo_items_feats.push(geojson_format.writeFeaturesObject(features, {decimals: 5}));
- }
- }
- return [base_features, geo_items_feats];
-}
-
-var base_features_type = function (id) {
- if (vector_features[id] == null) {
- if (point_features[id] == null) {
- return 'both null';
- }
- else { return 'Point'; }
- }
- if (point_features[id] == null) {
- return 'MultiPolygon';
- }
- else { return 'Point and MultiPolygon' }
-}
-
var _geo_points = new Array();
var _geo_other = new Array();
@@ -948,10 +799,10 @@ const _refresh_map_finds = function(idx) {
}
}
-const refresh_map_finds_crs = function(url, attrs, idx, crs_check, find_check) {
+const refresh_map_finds_crs = function(url, attrs, idx, crs_check, finds_check) {
if (idx in _point_list_finds){
if (crs_check) _refresh_map_crs(idx);
- if (find_check) _refresh_map_finds(idx);
+ if (finds_check) _refresh_map_finds(idx);
return;
}
_point_list_crs[idx] = new Array();
@@ -1011,9 +862,9 @@ const refresh_map = function(idx, geodata_list, url, attrs) {
}
}
if (url && attrs){
- let find_check = $("#map-ol-" + idx + "-finds").prop('checked');
+ let finds_check = $("#map-ol-" + idx + "-finds").prop('checked');
let crs_check = $("#map-ol-" + idx + "-crs").prop('checked');
- refresh_map_finds_crs(url, attrs, idx, crs_check, find_check);
+ refresh_map_finds_crs(url, attrs, idx, crs_check, finds_check);
}
}