Skip to content

Commit

Permalink
Merge branch 'EMC-440-show-facilities-in-monitoring-facility-map' int…
Browse files Browse the repository at this point in the history
…o 'develop'

show child facility on monitoring map.  EMC-440

Closes EMC-440

See merge request eip/catalogue!811
  • Loading branch information
rodscott committed Jan 31, 2025
2 parents fc1db3e + d26dc22 commit 013811b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ public List<Link> relationships(String uri, String relation) {
return links(pss);
}

public List<Link> relationshipsWithOwner(String uri, String relation) {
String sparql = "PREFIX dc: <http://purl.org/dc/terms/> PREFIX pso: <http://purl.org/spar/pso/> PREFIX hasGeometry: <http://www.opengis.net/ont/geosparql#hasGeometry> " +
"SELECT DISTINCT ?node ?title ?publicationStatus ?type ?rel ?geom " +
"WHERE {{?me dc:title ?title; pso:PublicationStatus ?publicationStatus; dc:type ?type; hasGeometry: ?geom. BIND(?me as ?node)} " +
"UNION {?me ?relation ?node. ?node dc:title ?title; pso:PublicationStatus ?publicationStatus; dc:type ?type; hasGeometry: ?geom. BIND(?relation as ?rel)}} " +
"ORDER BY ?title";
ParameterizedSparqlString pss = new ParameterizedSparqlString(sparql);
pss.setIri("me", uri);
pss.setIri("relation", relation);
return links(pss);
}

public List<Link> inverseRelationships(String uri, String relation) {
String hasGeometry = "http://www.opengis.net/ont/geosparql#hasGeometry";
String publicationDate = "http://purl.org/dc/terms/available";
Expand Down Expand Up @@ -177,6 +189,15 @@ public String programmeCombinedGeometries(String uri) throws JsonProcessingExcep
*/
public String inverseRelationshipCombinedGeometries(String uri, String relation) throws JsonProcessingException {
List<Link> links = inverseRelationships(uri, relation);
return getCombinedGeometriesString(links, uri);
}

public String relationshipCombinedGeometriesWithOwner(String uri, String relation) throws JsonProcessingException {
List<Link> links = relationshipsWithOwner(uri, relation);
return getCombinedGeometriesString(links, uri);
}

private String getCombinedGeometriesString(List<Link> links, String uri) throws JsonProcessingException {
// Return if no links found
if (links.isEmpty()) {
return "";
Expand All @@ -196,7 +217,11 @@ public String inverseRelationshipCombinedGeometries(String uri, String relation)
((ObjectNode)jsonNode).set("properties", propertiesNode);
}
propertiesNode.put("title", link.getTitle());
propertiesNode.put("link", link.getHref());
if (link.getHref().equals(uri)) {
propertiesNode.put("showPolygon", true);
} else {
propertiesNode.put("link", link.getHref());
}
features.add(jsonNode);
}
}
Expand Down Expand Up @@ -267,7 +292,7 @@ private List<Link> links(ParameterizedSparqlString pss) {
.publicationStatus(s.getLiteral("publicationStatus").getString())
.href(s.getResource("node").getURI())
.associationType(s.getLiteral("type").getString())
.rel(s.getResource("rel").getURI())
.rel(s.getResource("rel") != null ? s.getResource("rel").getURI() : "")
.geometry(s.getLiteral("geom") != null ? s.getLiteral("geom").getString() : "")
.build()
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class JenaLookupServiceTest {

private static final Property OSDP_PRODUCES = ResourceFactory.createProperty("http://onto.nerc.ac.uk/CEHMD/rels/produces");
private static final Property BELONGS_TO = ResourceFactory.createProperty("http://purl.org/voc/ef#belongsTo");
private static final Property NARROWER = ResourceFactory.createProperty("http://onto.ceh.ac.uk/EF#narrower");

@BeforeEach
void init() {
Expand Down Expand Up @@ -143,6 +144,30 @@ public void inverseRelationshipCombinedGeometries() throws JsonProcessingExcepti
assertThat("Generates correct combined GeoJSON", actual, equalTo(combinedGeometry));
}

@Test
public void relationshipCombinedGeometriesWithOwner() throws JsonProcessingException {
//Given
Model triples = jenaTdb.getDefaultModel();
String geometryString = "{\"type\":\"Feature\",\"properties\":{\"name\":\"Sample Point\"},\"geometry\":{\"type\":\"Point\",\"coordinates\":[0,0]}}";
String geometryString2 = "{\"type\":\"Feature\",\"properties\":{\"name\":\"Sample Point2\"},\"geometry\":{\"type\":\"Point\",\"coordinates\":[1,1]}}";
String combinedGeometry = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{\"name\":\"Sample Point\",\"title\":\"Monitoring Facility\",\"link\":\"http://monitoringFacility\"},\"geometry\":{\"type\":\"Point\",\"coordinates\":[0,0]}},{\"type\":\"Feature\",\"properties\":{\"name\":\"Sample Point2\",\"title\":\"Monitoring Facility 2\",\"showPolygon\":true},\"geometry\":{\"type\":\"Point\",\"coordinates\":[1,1]}}]}";
triples.add(createResource("http://monitoringFacility"), TITLE, "Monitoring Facility");
triples.add(createResource("http://monitoringFacility"), METADATA_STATUS, "published");
triples.add(createResource("http://monitoringFacility"), TYPE, "Monitoring Facility");
triples.add(createResource("http://monitoringFacility"), HAS_GEOMETRY, geometryString);
triples.add(createResource("http://monitoringFacility2"), TITLE, "Monitoring Facility 2");
triples.add(createResource("http://monitoringFacility2"), METADATA_STATUS, "published");
triples.add(createResource("http://monitoringFacility2"), NARROWER, createResource("http://monitoringFacility"));
triples.add(createResource("http://monitoringFacility2"), TYPE, "Monitoring Facility");
triples.add(createResource("http://monitoringFacility2"), HAS_GEOMETRY, geometryString2);

//When
String actual = service.relationshipCombinedGeometriesWithOwner("http://monitoringFacility2", NARROWER.toString());

//Then
assertThat("Generates correct combined GeoJSON with owner", actual, equalTo(combinedGeometry));
}

@Test
public void lookupProgrammeFeatures() {
// Given
Expand Down
24 changes: 12 additions & 12 deletions templates/html/monitoring/facility.ftlh
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
<@m.keyValue "Type" "type of monitoring facility">${facilityType.value}</@m.keyValue>
</#if>

<#if geometry?? && geometry?has_content>
<div>
<#if geometry.geometryString?? && geometry.geometryString?has_content>
<@m.keyValue "Location">
<@m.map geometry.geometryString />
</@m.keyValue>

<#if geometryRepresentative>
Geometry is representative
</#if>
</#if>
</div>
<#assign relationshipCombinedGeometriesOutput>
<@m.relationshipCombinedGeometriesWithOwner "http://onto.ceh.ac.uk/EF#narrower" />
</#assign>
<#if relationshipCombinedGeometriesOutput?has_content>
<@m.keyValue "Location">
<div class="childFeatures">
<div class="featureMap">${relationshipCombinedGeometriesOutput}</div>
</div>
</@m.keyValue>
</#if>

<#if geometryRepresentative>
<@m.keyValue "">Geometry is representative</@m.keyValue>
</#if>
<#if mobile>
<@m.keyValue "Mobile?">Yes</@m.keyValue>
</#if>
Expand Down
7 changes: 7 additions & 0 deletions templates/html/monitoring/monitoringBase.ftlh
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ Operating period
</#if>
</#macro>

<#macro relationshipCombinedGeometriesWithOwner relation>
<#local combinedGeometry=jena.relationshipCombinedGeometriesWithOwner(uri, relation) />
<#if combinedGeometry?has_content>
<@map combinedGeometry />
</#if>
</#macro>

<#macro programmeCombinedGeometries relation>
<#local combinedGeometry=jena.programmeCombinedGeometries(uri) />
<#if combinedGeometry?has_content>
Expand Down
10 changes: 7 additions & 3 deletions web/src/study-area/src/View/StudyAreaView.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ export default Backbone.View.extend({
// Convert all features in feature collection to points in order to play
// nicely with Leaflet.ClusterMap library
const pointFeatureCollection = studyArea.features.map(feature => {
if (feature.geometry.type === 'Polygon' || feature.geometry.type === 'MultiPolygon') {
if ((feature.geometry.type === 'Polygon' || feature.geometry.type === 'MultiPolygon') &&
(typeof feature.properties.showPolygon === 'undefined' || !feature.properties.showPolygon)) {
const polygon = L.geoJSON(feature.geometry)
const centroid = this.centerPointOfPolygon(polygon)
return {
Expand All @@ -116,8 +117,11 @@ export default Backbone.View.extend({
const featureInPoints = L.geoJson(pointFeatureCollection, {
onEachFeature: (feature, layer) => {
const title = feature.properties.title
const link = feature.properties.link
const content = `<h5><a href=${link}>${title}</a></h5>`
let content = `<h5>${title}</h5>`
if (typeof feature.properties.link !== 'undefined') {
const link = feature.properties.link
content = `<h5><a href=${link}>${title}</a></h5>`
}
layer.bindPopup(content)
}
})
Expand Down

0 comments on commit 013811b

Please sign in to comment.