summaryrefslogtreecommitdiff
path: root/ishtar_common/static/js/ishtar-map.js
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2022-09-01 19:15:02 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-12 12:23:18 +0100
commit4798e764adf21e259e6738eaaf18c0fa7ae18bac (patch)
tree5b95b1695cf8772e547deca7313af2e9b19d3344 /ishtar_common/static/js/ishtar-map.js
parente0bcbeaa84c2adf3b8a179cdea792dd58fa109b2 (diff)
downloadIshtar-4798e764adf21e259e6738eaaf18c0fa7ae18bac.tar.bz2
Ishtar-4798e764adf21e259e6738eaaf18c0fa7ae18bac.zip
Geo: display related items on sheet
Diffstat (limited to 'ishtar_common/static/js/ishtar-map.js')
-rw-r--r--ishtar_common/static/js/ishtar-map.js169
1 files changed, 133 insertions, 36 deletions
diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js
index 95f8ad3e3..a0709c059 100644
--- a/ishtar_common/static/js/ishtar-map.js
+++ b/ishtar_common/static/js/ishtar-map.js
@@ -32,7 +32,7 @@ var fetching_msg = "Fetching data...";
var base_maps_msg = "Base maps";
var _map_submit_search = function(query_vars, name, source, extra){
- if (!extra) extra = "default";
+ if (!extra) extra = "default";
var modal_base_text = $('.modal-progress .modal-header').html();
$('.modal-progress .modal-header').html(fetching_msg);
$('.modal-progress').modal('show');
@@ -175,7 +175,7 @@ var TrackPositionControl = (function (Control) {
/* base layers */
var source_osm = function(options){
- options["source"] = new ol.source.OSM();
+ options["source"] = new ol.source.OSM();
return new ol.layer.Tile(options);
};
@@ -207,19 +207,19 @@ var ign_resolutions = [
var ign_key = "essentiels";
var source_ign = function(options){
- options["source"] = new ol.source.WMTS({
- url: "https://wxs.ign.fr/" + ign_key + "/geoportail/wmts",
- layer: "ORTHOIMAGERY.ORTHOPHOTOS",
- matrixSet: "PM",
- format: "image/jpeg",
- style: "normal",
- tileGrid : new ol.tilegrid.WMTS({
- origin: [-20037508,20037508], // topLeftCorner
- resolutions: ign_resolutions, // résolutions
- matrixIds: ["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19"] // ids des TileMatrix
- })
- });
- return new ol.layer.Tile(options);
+ options["source"] = new ol.source.WMTS({
+ url: "https://wxs.ign.fr/" + ign_key + "/geoportail/wmts",
+ layer: "ORTHOIMAGERY.ORTHOPHOTOS",
+ matrixSet: "PM",
+ format: "image/jpeg",
+ style: "normal",
+ tileGrid : new ol.tilegrid.WMTS({
+ origin: [-20037508,20037508], // topLeftCorner
+ resolutions: ign_resolutions, // résolutions
+ matrixIds: ["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19"] // ids des TileMatrix
+ })
+ });
+ return new ol.layer.Tile(options);
}
var default_map_layers = {
@@ -230,14 +230,14 @@ var default_map_layers = {
var get_layers = function(layers){
if (!layers){
layers = [
- {
- 'type': 'ign',
- 'options': {'title': "IGN aérien (France)", 'visible': false, "type": 'base'}
- },
- {
- 'type': 'osm',
- 'options': {'title': "OpenStreetMap", 'visible': true, "type": 'base'}
- }
+ {
+ 'type': 'ign',
+ 'options': {'title': "IGN aérien (France)", 'visible': false, "type": 'base'}
+ },
+ {
+ 'type': 'osm',
+ 'options': {'title': "OpenStreetMap", 'visible': true, "type": 'base'}
+ }
];
}
var ol_layers = [];
@@ -627,12 +627,12 @@ var initialize_base_map = function(map_id, layers){
center = wkt_format.readGeometry(map_default_center).getCoordinates();
map_layers[map_id] = [
- new ol.layer.Group({
- title: base_maps_msg,
- visible: true,
- layers: get_layers(layers)
- })
- ];
+ new ol.layer.Group({
+ title: base_maps_msg,
+ visible: true,
+ layers: get_layers(layers)
+ })
+ ];
map_view[map_id] = new ol.View({
projection: view_projection,
@@ -661,14 +661,14 @@ var initialize_base_map = function(map_id, layers){
view: map_view[map_id]
});
var layer_switcher = new ol.control.LayerSwitcher({
- tipLabel: 'Légende',
- groupSelectStyle: 'children'
- });
- map[map_id].addControl(layer_switcher);
+ tipLabel: 'Légende',
+ groupSelectStyle: 'children'
+ });
+ map[map_id].addControl(layer_switcher);
}
var redraw_map = function(map_id, layers){
- if (!map || !map[map_id]) return;
+ if (!map || !map[map_id]) return;
map[map_id].setTarget(null);
map[map_id] = null;
initialize_base_map(map_id, layers);
@@ -705,7 +705,6 @@ var display_map = function(map_id, points, lines_and_polys, layers){
var display_points = function(map_id, points, first_init){
if (!points) return;
point_features[map_id] = geojson_format.readFeatures(points);
- console.log(708);
if (!cluster_source[map_id]){
enable_clustering(map_id);
} else {
@@ -736,7 +735,6 @@ var display_lines_and_polys = function(map_id, lines_and_polys, first_init){
style: get_vector_style
});
- console.log(738);
map[map_id].addLayer(vector_layer[map_id]);
if (first_init && lines_and_polys.features && lines_and_polys.features.length){
map_view[map_id].fit(vector_source[map_id].getExtent());
@@ -896,3 +894,102 @@ var base_features_type = function (id) {
}
else { return 'Point and MultiPolygon' }
}
+
+var _geo_points = new Array();
+var _geo_other = new Array();
+
+var _point_list_crs = new Array();
+var _other_list_crs = new Array();
+var _point_list_finds = new Array();
+var _other_list_finds = new Array();
+
+const _refresh_map_crs = function(idx) {
+ if (idx in _geo_points && idx in _point_list_crs){
+ for (const feat of _point_list_crs[idx]){
+ _geo_points[idx]["features"].push(feat);
+ }
+ }
+ if (idx in _geo_other && idx in _other_list_crs){
+ for (const feat of _other_list_crs[idx]){
+ _geo_other[idx]["features"].push(feat);
+ }
+ }
+}
+const _refresh_map_finds = function(idx) {
+ if (idx in _geo_points && idx in _point_list_finds){
+ for (const feat of _point_list_finds[idx]){
+ _geo_points[idx]["features"].push(feat);
+ }
+ }
+ if (idx in _geo_other && idx in _other_list_finds){
+ for (const feat of _other_list_finds[idx]){
+ _geo_other[idx]["features"].push(feat);
+ }
+ }
+}
+
+const refresh_map_finds_crs = function(url, attrs, idx, crs_check, find_check) {
+ if (idx in _point_list_finds){
+ if (crs_check) _refresh_map_crs(idx);
+ if (find_check) _refresh_map_finds(idx);
+ return;
+ }
+ _point_list_crs[idx] = new Array();
+ _other_list_crs[idx] = new Array();
+ _point_list_finds[idx] = new Array();
+ _other_list_finds[idx] = new Array();
+ $.get(url, attrs).done(
+ function(data) {
+ data = JSON.parse(data);
+ if (data) {
+ if (data["context-records"] && data["context-records"]["features"]) {
+ for (let feat of data["context-records"]["features"]){
+ if (feat["geometry"]["type"] === 'Point' ||
+ feat["geometry"]["type"] === 'MultiPoint'){
+ _point_list_crs[idx].push(feat);
+ } else {
+ _other_list_crs[idx].push(feat);
+ }
+ }
+ if (crs_check) _refresh_map_crs(idx);
+ }
+ if (data["finds"] && data["finds"]["features"]) {
+ for (let feat of data["finds"]["features"]){
+ if (feat["geometry"]["type"] === 'Point' ||
+ feat["geometry"]["type"] === 'MultiPoint'){
+ _point_list_finds[idx].push(feat);
+ } else {
+ _other_list_finds[idx].push(feat);
+ }
+ }
+ if (finds_check) _refresh_map_finds(idx);
+ }
+ }
+ }
+ );
+}
+
+
+const refresh_map = function(idx, geodata_list, url, attrs) {
+ _geo_points[idx] = {"type": "FeatureCollection", "features": []};
+ _geo_other[idx] = {"type": "FeatureCollection", "features": []};
+ for (const key in geodata_list){
+ if ($("#map-ol-" + key).prop('checked')){
+ let geo_type = geodata_list[key][0];
+ let geojson = geodata_list[key][1];
+ if (geo_type === 'POINT'){
+ Array.prototype.push.apply(
+ _geo_points[idx]["features"], geojson["features"]);
+ } else {
+ Array.prototype.push.apply(
+ _geo_other[idx]["features"], geojson["features"]);
+ }
+ }
+ }
+ if (url && attrs){
+ let find_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);
+ }
+}
+