# WIP: Integration netgis client
* adds adjustments for integration of newest netgis client version (81fa3bef48
)
This commit is contained in:
parent
3c1cbcd0bd
commit
6ff67d12c9
@ -27,13 +27,12 @@ class SimpleGeomForm(BaseForm):
|
||||
"""
|
||||
read_only = True
|
||||
geometry_simplified = False
|
||||
geom = JSONField(
|
||||
output = JSONField(
|
||||
label=_("Geometry"),
|
||||
help_text=_(""),
|
||||
label_suffix="",
|
||||
required=False,
|
||||
disabled=False,
|
||||
template_name="output"
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
@ -49,29 +48,32 @@ class SimpleGeomForm(BaseForm):
|
||||
raise AttributeError
|
||||
|
||||
geojson = self.instance.geometry.as_feature_collection(srid=DEFAULT_SRID_RLP)
|
||||
|
||||
geojson = self._set_editable_status(geojson)
|
||||
|
||||
geom = json.dumps(geojson)
|
||||
except AttributeError:
|
||||
# If no geometry exists for this form, we simply set the value to None and zoom to the maximum level
|
||||
geom = ""
|
||||
self.empty = True
|
||||
|
||||
self.initialize_form_field("geom", geom)
|
||||
self.initialize_form_field("output", geom)
|
||||
|
||||
def is_valid(self):
|
||||
super().is_valid()
|
||||
is_valid = True
|
||||
|
||||
# Get geojson from form
|
||||
geom = self.data["geom"]
|
||||
geom = self.data["output"]
|
||||
if geom is None or len(geom) == 0:
|
||||
# empty geometry is a valid geometry
|
||||
self.cleaned_data["geom"] = MultiPolygon(srid=DEFAULT_SRID_RLP).ewkt
|
||||
self.cleaned_data["output"] = MultiPolygon(srid=DEFAULT_SRID_RLP).ewkt
|
||||
return is_valid
|
||||
geom = json.loads(geom)
|
||||
|
||||
# Write submitted data back into form field to make sure invalid geometry
|
||||
# will be rendered again on failed submit
|
||||
self.initialize_form_field("geom", self.data["geom"])
|
||||
self.initialize_form_field("output", self.data["output"])
|
||||
|
||||
# Read geojson into gdal geometry
|
||||
# HINT: This can be simplified if the geojson format holds data in epsg:4326 (GDAL provides direct creation for
|
||||
@ -98,7 +100,7 @@ class SimpleGeomForm(BaseForm):
|
||||
g = self.__flatten_geom_to_2D(g)
|
||||
|
||||
if g.geom_type not in accepted_ogr_types:
|
||||
self.add_error("geom", _("Only surfaces allowed. Points or lines must be buffered."))
|
||||
self.add_error("output", _("Only surfaces allowed. Points or lines must be buffered."))
|
||||
is_valid &= False
|
||||
return is_valid
|
||||
|
||||
@ -107,7 +109,7 @@ class SimpleGeomForm(BaseForm):
|
||||
polygon = Polygon.from_ewkt(g.ewkt)
|
||||
is_valid &= polygon.valid
|
||||
if not polygon.valid:
|
||||
self.add_error("geom", polygon.valid_reason)
|
||||
self.add_error("output", polygon.valid_reason)
|
||||
return is_valid
|
||||
|
||||
features.append(polygon)
|
||||
@ -124,7 +126,7 @@ class SimpleGeomForm(BaseForm):
|
||||
# Write unioned Multipolygon into cleaned data
|
||||
if self.cleaned_data is None:
|
||||
self.cleaned_data = {}
|
||||
self.cleaned_data["geom"] = form_geom.ewkt
|
||||
self.cleaned_data["output"] = form_geom.ewkt
|
||||
|
||||
return is_valid
|
||||
|
||||
@ -134,7 +136,7 @@ class SimpleGeomForm(BaseForm):
|
||||
Returns:
|
||||
|
||||
"""
|
||||
geom = self.cleaned_data.get("geom")
|
||||
geom = self.cleaned_data.get("output")
|
||||
g = gdal.OGRGeometry(geom, srs=DEFAULT_SRID_RLP)
|
||||
num_vertices = g.num_coords
|
||||
|
||||
@ -150,7 +152,7 @@ class SimpleGeomForm(BaseForm):
|
||||
|
||||
if not is_area_valid:
|
||||
self.add_error(
|
||||
"geom",
|
||||
"output",
|
||||
_("Geometry must be greater than 1m². Currently is {}m²").format(
|
||||
float(geom.area)
|
||||
)
|
||||
@ -193,14 +195,14 @@ class SimpleGeomForm(BaseForm):
|
||||
if self.instance is None or self.instance.geometry is None:
|
||||
raise LookupError
|
||||
geometry = self.instance.geometry
|
||||
geometry.geom = self.cleaned_data.get("geom", MultiPolygon(srid=DEFAULT_SRID_RLP))
|
||||
geometry.geom = self.cleaned_data.get("output", MultiPolygon(srid=DEFAULT_SRID_RLP))
|
||||
geometry.modified = action
|
||||
|
||||
geometry.save()
|
||||
except LookupError:
|
||||
# No geometry or linked instance holding a geometry exist --> create a new one!
|
||||
geometry = Geometry.objects.create(
|
||||
geom=self.cleaned_data.get("geom", MultiPolygon(srid=DEFAULT_SRID_RLP)),
|
||||
geom=self.cleaned_data.get("output", MultiPolygon(srid=DEFAULT_SRID_RLP)),
|
||||
created=action,
|
||||
)
|
||||
|
||||
@ -224,3 +226,19 @@ class SimpleGeomForm(BaseForm):
|
||||
g_wkt = wkt_w.write(geom.geos).decode("utf-8")
|
||||
geom = gdal.OGRGeometry(g_wkt)
|
||||
return geom
|
||||
|
||||
def _set_editable_status(self, geojson: dict):
|
||||
""" Toggles the editable property of the geojson for proper handling in map client
|
||||
|
||||
Args:
|
||||
geojson (dict): The GeoJson
|
||||
|
||||
Returns:
|
||||
geojson (dict): The altered GeoJson
|
||||
"""
|
||||
features = geojson.get("features", [])
|
||||
for feature in features:
|
||||
feature["properties"] = {
|
||||
"editable": not self.read_only
|
||||
}
|
||||
return geojson
|
||||
|
@ -15,7 +15,7 @@
|
||||
},
|
||||
"menu":
|
||||
{
|
||||
"header": "<a href='.' target='_self'>LANIS Demo</a>",
|
||||
"header": "",
|
||||
"items":
|
||||
[
|
||||
{ "id": "searchplace", "title": "<i class='fas fa-search'></i><span>Suche</span>" },
|
||||
@ -39,7 +39,7 @@
|
||||
},
|
||||
"folders":
|
||||
[
|
||||
{ "id": "bg", "title": "Hintergrund", "parent": null },
|
||||
{ "id": "bg", "title": "Hintergrund", "parent": null , "radio": true},
|
||||
{ "id": "alkis", "title": "ALKIS Liegenschaften", "parent": null },
|
||||
{ "id": "verwaltung", "title": "Verwaltungsgrenzen", "parent": null },
|
||||
{ "id": "fachdaten", "title": "Geofachdaten", "parent": null },
|
||||
@ -123,7 +123,7 @@
|
||||
"searchplace":
|
||||
{
|
||||
"title": "Adresse...",
|
||||
"url": "/client/proxy?https://www.geoportal.rlp.de/mapbender/geoportal/gaz_geom_mobile.php?outputFormat=json&resultTarget=web&searchEPSG={epsg}&maxResults=5&maxRows=5&featureClass=P&style=full&searchText={q}&name_startsWith={q}",
|
||||
"url": "/client/proxy?https://www.geoportal.rlp.de/mapbender/geoportal/gaz_geom_mobile.php?outputFormat=json&resultTarget=web&searchEPSG={epsg}&maxResults=5&maxRows=5&featureClass=P&style=full&searchText={query}&name_startsWith={query}",
|
||||
"zoom": 17,
|
||||
"marker_color": "darkgray",
|
||||
"marker_title": "Such-Ergebnis"
|
||||
@ -219,7 +219,7 @@
|
||||
"interactive_render": true,
|
||||
"buffer":
|
||||
{
|
||||
"default_radius": 300,
|
||||
"default_radius": 5,
|
||||
"default_segments": 3
|
||||
},
|
||||
"snapping":
|
||||
|
2
templates/map/client/dist/netgis.min.css
vendored
2
templates/map/client/dist/netgis.min.css
vendored
File diff suppressed because one or more lines are too long
6178
templates/map/client/dist/netgis.min.js
vendored
6178
templates/map/client/dist/netgis.min.js
vendored
File diff suppressed because it is too large
Load Diff
@ -24,7 +24,7 @@
|
||||
style="position: relative; width: 100%; height: 100%;">
|
||||
</main>
|
||||
|
||||
<input type="hidden" id="netgis-storage" name="output" value="{{geom_form.fields.geom.initial}}"/>
|
||||
<input type="hidden" id="netgis-storage" name="output" value="{{geom_form.fields.output.initial}}"/>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user