summaryrefslogtreecommitdiff
path: root/ishtar_common/static/js
diff options
context:
space:
mode:
authorQuentin André <quentin.andre@imt-atlantique.net>2021-08-07 01:23:16 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-07-08 09:58:48 +0200
commitf2bb6f81eb089cb027614d03da8fbc5591bebfe2 (patch)
tree2e0ba9944cdc7d9d243cc65c513f772ffe7d937a /ishtar_common/static/js
parent749e04350ecd47952f51913d6296de39d2a96e3a (diff)
downloadIshtar-f2bb6f81eb089cb027614d03da8fbc5591bebfe2.tar.bz2
Ishtar-f2bb6f81eb089cb027614d03da8fbc5591bebfe2.zip
PR for peer review
Diffstat (limited to 'ishtar_common/static/js')
-rw-r--r--ishtar_common/static/js/ishtar-map.js143
1 files changed, 135 insertions, 8 deletions
diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js
index c78da1098..d4eb7285d 100644
--- a/ishtar_common/static/js/ishtar-map.js
+++ b/ishtar_common/static/js/ishtar-map.js
@@ -550,6 +550,17 @@ var vector_source = {};
var vector_layer = {};
var vector_features = {};
+// for test
+var geo_items_features = null;
+var current_test = false;
+var initialize_test_map = function () {
+ geo_items_features = {};
+ current_test = true;
+ if ($("#http-geo-items-ready").length === 0) {
+ $("#display-geo-items").after('<div id="http-geo-items-ready">Ready!</div>');
+ }
+ $("#http-geo-items-ready").hide();
+}
var initialize_base_map = function(map_id, layers){
center = wkt_format.readGeometry(map_default_center).getCoordinates();
@@ -603,20 +614,31 @@ var display_map = function(map_id, points, lines_and_polys, layers){
link_template[map_id] = lines_and_polys['link_template'];
}
if (map[map_id]){
+
redraw_map(map_id, layers);
} else {
initialize_base_map(map_id, layers);
}
+ console.log('map init')
+ console.log(map[map_id]);
display_points(map_id, points);
display_lines_and_polys(map_id, lines_and_polys);
+ console.log('map after points');
+ console.log(map[map_id]);
init_popup(map_id);
map[map_id].on('click', manage_click_on_map(map_id));
map[map_id].on('pointermove', manage_hover(map_id));
+
+ if (current_test) {
+ geo_items_features[map_id] = []; // for test
+ }
};
var display_points = function(map_id, points){
+ console.log('points');
+ console.log(points);
if (!points) return;
point_features[map_id] = geojson_format.readFeatures(points);
enable_clustering(map_id);
@@ -662,19 +684,32 @@ var disp_geo_items = function(map_id, base_url, slug, pk,
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) {
geo_items = to_geo_items(JSON.parse(httpRequest.responseText), slug, display_both)
+ if (current_test) {
+ geo_items_features[map_id] = [];
+ }
+ var feat = null;
for (geo_item of geo_items['base-finds']) {
if (get_poly) {
- display_associated_polys(map_id, geo_item, 'basefind');
+ feat = display_associated_polys(map_id, geo_item, 'basefind');
} else {
- display_associated_points(map_id, geo_item, 'basefind');
+ feat = display_associated_points(map_id, geo_item, 'basefind');
+ }
+ if (current_test) {
+ geo_items_features[map_id].push(feat);
}
}
for (geo_item of geo_items['context-records']) {
if (get_poly) {
- display_associated_polys(map_id, geo_item, 'contextrecord');
+ feat = display_associated_polys(map_id, geo_item, 'contextrecord');
} else {
- display_associated_points(map_id, geo_item, 'contextrecord');
+ feat = display_associated_points(map_id, geo_item, 'contextrecord');
}
+ if (current_test) {
+ geo_items_features[map_id].push(feat);
+ }
+ }
+ if (current_test) {
+ $("#http-geo-items-ready").show();
}
} else { return; }
}
@@ -714,6 +749,7 @@ var display_associated_polys = function (map_id, polys, slug) {
style: style
});
map[map_id].addLayer(_vector_layer);
+ return _vector_features
}
var get_associated_base_find_style = function (feature) {
@@ -742,17 +778,18 @@ var get_associated_context_record_style = function (feature) {
};
var display_associated_points = function (map_id, points, slug) {
+ console.log('geo items points')
console.log(points);
- _point_features = geojson_format.readFeatures(points);
- console.log(_point_features[0].getGeometry().getType())
+ /*_point_features = geojson_format.readFeatures(points);
_cluster_source = new ol.source.Cluster({
distance: 40,
source: new ol.source.Vector()
});
_cluster_source.getSource().addFeatures(_point_features);
- style = get_associated_base_find_style;
+ // TODO: create own style
+ style = cluster_get_style;
if (slug === 'contextrecord') {
- style = get_associated_context_record_style;
+ style = style;
}
_cluster_layer = new ol.layer.Vector({
name: 'Cluster',
@@ -760,5 +797,95 @@ var display_associated_points = function (map_id, points, slug) {
style: style
});
map[map_id].addLayer(_cluster_layer);
+ return _point_features;*/
+}
+
+// for test purpose
+// to insert in sheet_simple_map.html when working with maps
+// wait_for_map("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}");
+var wait_for_map = function(map_id) {
+ map[map_id].on('rendercomplete', function(event) {
+ console.log("map fully loaded");
+ })
+ if (map_id in cluster_layer) {
+ console.log('cluster layer');
+ cluster_layer[map_id].on('change', function(event) {
+ if (cluster_layer.getState === "ready") {
+ console.log("cluster fully loaded");
+ }
+ })
+ }
+ if (map_id in vector_layer) {
+ console.log('vector layer');
+ vector_layer[map_id].on('change', function(event) {
+ if (vector_layer.getState === "ready") {
+ console.log("vector fully loaded");
+ }
+ })
+ }
+ if (map_id in cluster_source) {
+ console.log('cluster source');
+ cluster_source[map_id].on('change', function(event) {
+ if (cluster_source.getState === "ready") {
+ console.log("cluster source fully loaded");
+ }
+ })
+ }
+ if (map_id in vector_source) {
+ console.log('vector source');
+ vector_source[map_id].on('change', function(event) {
+ if (vector_source.getState === "ready") {
+ console.log("vector source fully loaded");
+ }
+ })
+ }
+}
+
+var get_map_by_id_test = function (id) {
+// problem here: async function because map and layers are not fully loaded directly
+ map[id].getLayers().getArray()[0].getSource().on(
+ 'change', function (evt) {
+ console.log('change')
+ var source = evt.target;
+ if (source.getState() === "ready") {
+ console.log('ready');
+ console.log(map_layers[id][0].getSource().getKeys())
+ }
+ }
+ )
+ map[id].on(
+ 'change', function (evt) {
+ console.log('change')
+ var map = evt.target;
+ if (map.getState() === "ready") {
+ console.log('ready');
+ console.log(map_layers[id][0].getSource().getKeys())
+ }
+ }
+ )
+ console.log("vector_features")
+ console.log(vector_features[id])
+ console.log("layers")
+ console.log(map_layers[id])
+ console.log("source")
+ console.log(map_layers[id][0].getSource())
+}
+
+var get_map_by_id = function (id) {
+ if (vector_features[id] == null) {
+ var base_features = geojson_format.writeFeaturesObject(point_features[id], {decimals: 3});
+ } else {
+ var base_features = geojson_format.writeFeaturesObject(vector_features[id], {decimals: 3});
+ }
+ var geo_items_feats = [];
+ if (geo_items_features && id in geo_items_features) {
+ for (var features of geo_items_features[id]) {
+ geo_items_feats.push(geojson_format.writeFeaturesObject(features, {decimals: 3}));
+ }
+ }
+ return [base_features, geo_items_feats];
+}
+var print = function (id) {
+ return "vector " + typeof vector_features[id] + ", cluster " + typeof point_features[id] ;
} \ No newline at end of file