Skip to content

Commit 2238373

Browse files
committed
Render data-cluster bboxes
1 parent 7e004e7 commit 2238373

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

runtimes/eoapi/stac/eoapi/stac/templates/collection.html

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,39 +44,52 @@ <h2>Links</h2>
4444
</ul>
4545
</div>
4646
<div class="col-sm">
47+
{% if response.extent and response.extent.spatial %}
4748
<div id="map" class="rounded" style="width: 100%; height: 400px">
4849
Loading...
4950
</div>
51+
{% endif %}
5052
</div>
5153
</div>
5254

55+
{% if response.extent and response.extent.spatial %}
5356
<script>
5457
$(function() {
55-
var collection = {{ response|tojson }};
56-
if (collection.extent && collection.extent.spatial){
57-
var bbox = collection.extent.spatial.bbox[0]
58-
var bbox_polygon = L.polygon([
58+
const collection = {{ response|tojson }};
59+
var map = L.map('map').setView([0, 0], 1);
60+
map.addLayer(new L.TileLayer(
61+
'https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
62+
maxZoom: 18,
63+
attribution: 'Map data &copy; <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>'
64+
}
65+
));
66+
67+
for (let i = 0, len = collection.extent.spatial.bbox.length; i < len; i++) {
68+
const options = i === 0 ? {
69+
fill: false,
70+
weight: 2
71+
} : {
72+
color: "red",
73+
fill: false,
74+
dashArray: 2,
75+
weight: 1
76+
};
77+
const bbox = collection.extent.spatial.bbox[i];
78+
const bbox_polygon = L.polygon([
5979
[bbox[1], bbox[0]],
6080
[bbox[1], bbox[2]],
6181
[bbox[3], bbox[2]],
6282
[bbox[3], bbox[0]]
63-
]);
83+
], options);
6484

65-
var map = L.map('map').setView([0, 0], 1);
66-
map.addLayer(new L.TileLayer(
67-
'https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
68-
maxZoom: 18,
69-
attribution: 'Map data &copy; <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>'
70-
}
71-
));
7285

7386
map.addLayer(bbox_polygon);
74-
map.fitBounds(bbox_polygon.getBounds());
75-
} else {
76-
document.getElementById("map").style.display = "none";
87+
if (i === 0) {
88+
map.fitBounds(bbox_polygon.getBounds());
89+
}
7790
}
78-
7991
});
8092
</script>
93+
{% endif %}
8194

8295
{% include "footer.html" %}

0 commit comments

Comments
 (0)