Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions map-view/src/components/FeatureInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,17 @@ class FeatureInfo extends React.Component<FeatureInfoProps, FeatureInfoState> {
const feature = features[featureIndex];
const fid = feature["id_"];
const featureType = fid.split(".")[0];
const { id, value, txt, direction, device_type_code, device_type_description } = feature.getProperties();
const {
id,
value,
txt,
direction,
device_type_code,
device_type_description,
mount_type_description_fi,
content_s,
additional_information,
} = feature.getProperties();
const deviceTypeText = `${device_type_code} - ${device_type_description}${value ? ` (${value})` : ""}`;

// Only run when distance is undefined (don't spam requests)
Expand All @@ -99,12 +109,32 @@ class FeatureInfo extends React.Component<FeatureInfoProps, FeatureInfoState> {
</Typography>
<Typography className={classes.content} variant="body1" component="p">
<b>Id</b>: {id}
{device_type_code && (
<>
<br />
<b>{t("Device type")}</b>: {deviceTypeText}
</>
)}
{mount_type_description_fi && !device_type_code && (
<>
<br />
<b>{t("Mount type")}</b>: {mount_type_description_fi}
</>
)}
{direction && (
<>
<br />
<b>{t("Direction")}</b>: {direction}
</>
)}
<br />
<b>{t("Device type")}</b>: {deviceTypeText}
<br />
<b>{t("Direction")}</b>: {direction}
<br />
<b>{t("Additional info")}</b>: {txt}
<b>{t("Additional info")}</b>: {txt || additional_information}
{content_s && (
<>
<br />
<b>{t("Content Schema")}</b>: {content_s}
</>
)}
{feature.getProperties().device_plan_id && (
<>
<br />
Expand Down
8 changes: 6 additions & 2 deletions map-view/src/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
"additionalsignreal": "Additional Sign Real",
"additionalsignplan": "Additional Sign Plan",
"furnituresignpostreal": "Furniture Signpost Real",
"furnituresignpostplan": "Furniture Signpost Plan"
"furnituresignpostplan": "Furniture Signpost Plan",
"mountrealcentroid": "Mount Real Centroid",
"mountplancentroid": "Mount Plan Centroid"
},
"Device type": "Device type",
"Direction": "Direction",
"Additional info": "Additional info"
"Additional info": "Additional info",
"Mount type": "Mount type",
"Content Schema": "Content Schema"
}
}
8 changes: 6 additions & 2 deletions map-view/src/locale/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
"additionalsignreal": "Lisäkilpitoteuma",
"additionalsignplan": "Lisäkilpisuunnitelma",
"furnituresignpostreal": "Kaupunkikalustetoteuma",
"furnituresignpostplan": "Kaupunkikalustesuunnitelma"
"furnituresignpostplan": "Kaupunkikalustesuunnitelma",
"mountrealcentroid": "Kiinnityskohta_keskipiste (toteuma)",
"mountplancentroid": "Kiinnityskohta_keskipiste (suunnitelma)"
},
"Device type": "Merkki",
"Direction": "Suunta",
"Additional info": "Lisätieto"
"Additional info": "Lisätieto",
"Mount type": "Kiinnityskohdan tyyppi",
"Content Schema": "Sisällön skeema"
}
}
3 changes: 3 additions & 0 deletions map-view/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export interface FeatureProperties {
device_type_code: string;
device_type_description: string;
device_plan_id: string;
mount_type_description_fi: string;
content_s: Object;
additional_information: string;
}

export interface Feature {
Expand Down
27 changes: 26 additions & 1 deletion traffic_control/tests/wfs/test_mount_wfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ def _assert_envelope(feature):
@pytest.mark.django_db
def test__wfs_mount__geojson(model_name: str, factory):
device = factory(location=test_point_helsinki)

geojson = wfs_get_features_geojson(model_name)

features = geojson_get_features(geojson)
Expand All @@ -321,3 +320,29 @@ def test__wfs_mount__geojson(model_name: str, factory):

# Coordinate order is always [X,Y,Z] in GeoJSON
assert geojson_feature_point_coordinates(feature) == [device.location.x, device.location.y, device.location.z]


@pytest.mark.parametrize(
"feature_name, factory",
(
("mountrealcentroid", MountRealFactory),
("mountplancentroid", MountPlanFactory),
),
)
@pytest.mark.parametrize("geometry", (TEST_GEOMETRY_COLLECTION, TEST_MULTI_LINE, TEST_GEOMETRY_COLLECTION))
@pytest.mark.django_db
def test__wfs_mount_centroid_geojson(feature_name, factory, geometry):
device = factory(location=geometry)
geojson = wfs_get_features_geojson(feature_name)

features = geojson_get_features(geojson)
assert len(features) == 1
feature = features[0]

assert geojson_crs(geojson) == EPSG_3879_URN

assert geojson_feature_id(feature) == f"{feature_name}.{device.id}"

# Coordinate order is always [X,Y,Z] in GeoJSON
centroid_location = device.centroid_location
assert geojson_feature_point_coordinates(feature) == [centroid_location.x, centroid_location.y, centroid_location.z]
17 changes: 17 additions & 0 deletions traffic_control/views/wfs/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional, Type

from django.conf import settings
from django.db import models
from enumfields import Enum
from gisserver.features import ComplexFeatureField, FeatureField
from gisserver.geometries import CRS
Expand Down Expand Up @@ -62,6 +63,22 @@ def _format_geojson_value(self, value):
return value.label
return super()._format_geojson_value(value)

def render_geometry(self, feature_type, instance: models.Model) -> bytes:
"""Support to convert location to centroid location if supported by the instance"""
if self._is_centroid_feature_type(feature_type):
geometry = getattr(instance, "centroid_location", None)
else:
geometry = getattr(instance, feature_type.geometry_field.name)
if geometry is None:
return b"null"

self.output_crs.apply_to(geometry)
return geometry.json.encode()

@staticmethod
def _is_centroid_feature_type(feature_type):
return "centroid" in feature_type.name


class CustomGetFeature(SwapBoundingBoxMixin, GetFeature):
# Use CustomGeoJsonRenderer
Expand Down
4 changes: 2 additions & 2 deletions traffic_control/views/wfs/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
fields=deepcopy(_mount_fields)
+ [
FeatureField(
"mount_plan_id", model_attribute="mount_plan.id", abstract="ID of the Mount plan related to this Mount"
"device_plan_id", model_attribute="mount_plan_id", abstract="ID of the Mount plan related to this Mount"
),
FeatureField("inspected_at", abstract="Timestamp when the mount was inspected."),
FeatureField("diameter", abstract="Diameter of the mount."),
Expand All @@ -88,7 +88,7 @@
fields=deepcopy(_mount_centroid_fields)
+ [
FeatureField(
"mount_plan_id", model_attribute="mount_plan.id", abstract="ID of the Mount plan related to this Mount"
"device_plan_id", model_attribute="mount_plan_id", abstract="ID of the Mount plan related to this Mount"
),
FeatureField("inspected_at", abstract="Timestamp when the mount was inspected."),
FeatureField("diameter", abstract="Diameter of the mount."),
Expand Down