Skip to content

Commit 68f98f0

Browse files
committed
HTML: add safe bbox function for dateline crossing
1 parent 2433cea commit 68f98f0

4 files changed

Lines changed: 39 additions & 12 deletions

File tree

pygeoapi/static/js/default.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
function gen_safe_bbox(bbox) {
3+
// generate a dateline safe bbox
4+
//
5+
// args: bbox: array of minx, miny, maxx, maxy
6+
//
7+
// returns: array of dateline safe bbox
8+
9+
if (Math.abs(bbox[2] - bbox[0]) > 180) {
10+
bbox[2] += 360;
11+
}
12+
13+
return bbox
14+
}

pygeoapi/templates/collections/collection.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css"/>
1212
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"></script>
1313
<script src='https://unpkg.com/leaflet-imageoverlay-ogcapi@0.1.0/Leaflet.ImageOverlay.OGCAPI.js'></script>
14+
<script src='https://unpkg.com/leaflet-imageoverlay-ogcapi@0.1.0/Leaflet.ImageOverlay.OGCAPI.js'></script>
15+
<script src="{{ config['server']['url'] }}/static/js/default.js"></script>
1416
{% endblock %}
1517

1618
{% block body %}
@@ -148,11 +150,13 @@ <h3>{% trans %}Storage CRS{% endtrans %}</h3>
148150
}
149151
));
150152

153+
var bbox = gen_safe_bbox({{ data['extent']['spatial']['bbox'][0] }});
154+
151155
var bbox_layer = L.polygon([
152-
['{{ data['extent']['spatial']['bbox'][0][1] }}', '{{ data['extent']['spatial']['bbox'][0][0] }}'],
153-
['{{ data['extent']['spatial']['bbox'][0][3] }}', '{{ data['extent']['spatial']['bbox'][0][0] }}'],
154-
['{{ data['extent']['spatial']['bbox'][0][3] }}', '{{ data['extent']['spatial']['bbox'][0][2] }}'],
155-
['{{ data['extent']['spatial']['bbox'][0][1] }}', '{{ data['extent']['spatial']['bbox'][0][2] }}']
156+
[bbox[1], bbox[0]],
157+
[bbox[3], bbox[0]],
158+
[bbox[3], bbox[2]],
159+
[bbox[1], bbox[2]]
156160
]);
157161

158162
var lbounds = bbox_layer.getBounds();

pygeoapi/templates/stac/collection_base.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
{% block extrahead %}
1111
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css"/>
1212
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"></script>
13+
<script src="{{ config['server']['url'] }}/static/js/default.js"></script>
1314
{% endblock %}
1415

1516
{% block body %}
@@ -102,12 +103,16 @@ <h4>{% trans %}Assets{% endtrans %}</h4>
102103
attribution: '{{ config['server']['map']['attribution'] | safe }}'
103104
}
104105
));
106+
107+
var bbox = gen_safe_bbox({{ data['extent']['spatial']['bbox'][0] }});
108+
105109
var bbox_layer = L.polygon([
106-
[{{ data['extent']['spatial']['bbox'][0][1] }}, {{ data['extent']['spatial']['bbox'][0][0] }}],
107-
[{{ data['extent']['spatial']['bbox'][0][3] }}, {{ data['extent']['spatial']['bbox'][0][0] }}],
108-
[{{ data['extent']['spatial']['bbox'][0][3] }}, {{ data['extent']['spatial']['bbox'][0][2] }}],
109-
[{{ data['extent']['spatial']['bbox'][0][1] }}, {{ data['extent']['spatial']['bbox'][0][2] }}],
110+
[bbox[1], bbox[0]],
111+
[bbox[3], bbox[0]],
112+
[bbox[3], bbox[2]],
113+
[bbox[1], bbox[2]]
110114
]);
115+
111116
map.addLayer(bbox_layer);
112117
map.fitBounds(bbox_layer.getBounds(), {maxZoom: 10});
113118
</script>

pygeoapi/templates/stac/item.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,16 @@ <h4>{% trans %}Assets{% endtrans %}</h4>
9797
attribution: '{{ config['server']['map']['attribution'] | safe }}'
9898
}
9999
));
100+
101+
var bbox = gen_safe_bbox({{ data['extent']['spatial']['bbox'][0] }});
102+
100103
var bbox_layer = L.polygon([
101-
[{{ data['bbox'][1] }}, {{ data['bbox'][0] }}],
102-
[{{ data['bbox'][3] }}, {{ data['bbox'][0] }}],
103-
[{{ data['bbox'][3] }}, {{ data['bbox'][2] }}],
104-
[{{ data['bbox'][1] }}, {{ data['bbox'][2] }}],
104+
[bbox[1], bbox[0]],
105+
[bbox[3], bbox[0]],
106+
[bbox[3], bbox[2]],
107+
[bbox[1], bbox[2]]
105108
]);
109+
106110
map.addLayer(bbox_layer);
107111
map.fitBounds(bbox_layer.getBounds(), {maxZoom: 10});
108112
</script>

0 commit comments

Comments
 (0)