summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_operations/models.py95
-rw-r--r--ishtar_common/models_common.py5
-rw-r--r--ishtar_common/static/js/ishtar-map.js62
3 files changed, 124 insertions, 38 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 080ddddab..69f8d4fdc 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -20,6 +20,8 @@
from collections import OrderedDict
import datetime
from itertools import groupby
+import json
+import re
import uuid
from django.apps import apps
@@ -45,6 +47,7 @@ from ishtar_common.models import (
GeneralRecordRelations,
GeneralRelationType,
GeneralType,
+ GeoVectorData,
IshtarUser,
LightHistorizedItem,
OperationType,
@@ -1726,30 +1729,88 @@ class Operation(
q = self.towns.filter(limit__isnull=False).annotate(poly=Union("limit")).all()
if not q.count():
return None
- return q.all()[0].poly, self._meta.verbose_name
+ return q.all()[0].poly, self._meta.verbose_namea
+
+ """
+ def _get_child_geodata(self, query, cr_list, collection_context_records_id,
+ current_geodata):
+ childs = []
+ for cr in query.exclude(id__in=cr_list).values(
+ "main_geodata", "id").distinct().all():
+ childs.append(cr["id"])
+ geodata_id = cr["main_geodata"]
+ if geodata_id not in collection_context_records_id \
+ and geodata_id not in current_geodata:
+ collection_context_records_id.append(geodata_id)
+ cr_list += childs
+ return childs
+ """
def get_geo_items(self, rounded=True):
dct = super(Operation, self).get_geo_items(rounded=rounded)
ContextRecord = apps.get_model(
"archaeological_context_records", "ContextRecord"
)
+
+ q = self.context_record.filter(main_geodata__isnull=False)
+
+ """
+ included = q.filter(
+ right_relations__relation_type__txt_idx='is_included')
+ q_upper = q.exclude(id__in=set(included.values_list("id", flat=True)))
+ cr_list = []
+
+ childs = self._get_child_geodata(
+ q_upper, cr_list, collection_context_records_id,
+ current_geodata)
+ while childs:
+ new_childs = []
+ for child_id in childs:
+ q_lower = q.filter(
+ right_relations__relation_type__txt_idx='is_included',
+ right_relations__right_record_id=child_id
+ )
+ new_childs += self._get_child_geodata(
+ q_lower, cr_list, collection_context_records_id,
+ current_geodata)
+ childs = new_childs
+
+
+
+ """
+
+ collection_context_records_id = []
+ current_geodata = self.geodata.values_list("id", flat=True)
+ q = q.values("main_geodata", "id")
+ for cr in q.distinct().all():
+ geodata_id = cr["main_geodata"]
+ if geodata_id not in collection_context_records_id \
+ and geodata_id not in current_geodata:
+ collection_context_records_id.append(geodata_id)
+
collection_context_records = []
- import datetime
- n = datetime.datetime.now()
- n1 = datetime.datetime.now()
- times = []
- print("archaeological_operations.models.py", "get_geo_items", 1741)
- for cr in self.context_record.distinct().all():
- try:
- geo_item = cr.get_geo_items(rounded=rounded)
- collection_context_records.append(geo_item)
- times.append((datetime.datetime.now() - n1).seconds)
- n1 = datetime.datetime.now()
- except ContextRecord.DoesNotExist:
- pass
- print("full", datetime.datetime.now() - n)
- if times:
- print("mean", sum(times)/len(times))
+ for cr_id in collection_context_records_id:
+ geo = json.loads(GeoVectorData.objects.get(pk=cr_id).geojson)
+ geo_type = geo.get("type", None)
+ if geo_type == "FeatureCollection":
+ collection_context_records += geo["features"]
+ elif geo_type:
+ collection_context_records.append(geo)
+
+ profile = get_current_profile()
+ precision = profile.point_precision
+ if not precision and rounded:
+ precision = 5
+ if precision is not None:
+ r = re.compile(r"(\d+)\.(\d{6})(\d*)")
+ for feat in collection_context_records:
+ geom_type = feat["geometry"].get("type", None)
+ if geom_type == "Point":
+ feat["geometry"]["coordinates"] = [
+ round(feat["geometry"]["coordinates"][0], precision),
+ round(feat["geometry"]["coordinates"][1], precision),
+ ]
+
dct["context-records"] = {
"type": "FeatureCollection",
"features": collection_context_records,
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py
index 5d3cdbec2..9d71ae0dc 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -2360,7 +2360,8 @@ class GeoVectorData(Imported, OwnPerms):
return profile.srs
def get_geo_items(self, rounded=5):
- dct = {"type": "Feature", "geometry": {}, "properties": {"label": str(self)}}
+ dct = {"type": "Feature", "geometry": {},
+ "properties": {"label": str(self)}}
if self.multi_polygon:
list_coords = []
for polygon in self.multi_polygon:
@@ -2394,7 +2395,7 @@ class GeoVectorData(Imported, OwnPerms):
list_coords.append([])
for coords in line:
point_2d = Point(
- coords.x, coords.y, srid=self.multi_points.srid
+ coords.x, coords.y, srid=self.multi_line.srid
)
list_coords[-1].append(
self.convert_coordinates(point_2d, rounded)
diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js
index a0709c059..ae591db08 100644
--- a/ishtar_common/static/js/ishtar-map.js
+++ b/ishtar_common/static/js/ishtar-map.js
@@ -14,6 +14,18 @@ var base_color_V = 66;
var base_color_B = 193;
var base_color_rvb;
+var base_colors = [
+ "rgba(230,0,73, 1)",
+ "rgba(11,180,255, 1)",
+ "rgba(80,233,145, 1)",
+ "rgba(230,216,0, 1)",
+ "rgba(155,25,245, 1)",
+ "rgba(255,163,0, 1)",
+ "rgba(220,10,180, 1)",
+ "rgba(179,212,255, 1)",
+ "rgba(0,191,160, 1)"
+];
+
var map_default_center = 'SRID=4326;POINT (2.4397 46.5528)';
var map_default_zoom = '7';
var min_auto_zoom_on_cluster = 13;
@@ -263,16 +275,24 @@ var get_icon_style = function(feature){
});
};
+var get_random_int = function(max) {
+ return Math.floor(Math.random() * max);
+}
+
+var _vector_style_cache = {};
+var tmp;
+
+
var get_vector_style = function(feature){
- return new ol.style.Style({
- stroke: new ol.style.Stroke({
- color: 'rgba(' + base_color_rvb + ', 1)',
- width: 2
- }),
- fill: new ol.style.Fill({
- color: 'rgba(' + base_color_rvb + ', 0.2)'
- })
- });
+ let feature_id = feature.getProperties()["id"]
+ if (!(feature_id in _vector_style_cache)){
+ _vector_style_cache[feature_id] = new ol.style.Style({
+ stroke: new ol.style.Stroke({
+ color: base_colors[get_random_int(base_colors.length)],
+ width: 2})
+ });
+ }
+ return _vector_style_cache[feature_id];
};
var cluster_get_style = function(feature, resolution){
@@ -944,22 +964,26 @@ const refresh_map_finds_crs = function(url, attrs, idx, crs_check, find_check) {
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 (feat["geometry"]){
+ 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 (feat["geometry"]){
+ 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);