Skip to content

Commit 0c756e1

Browse files
authored
HTML: add safe bbox function for dateline crossing (#2352)
1 parent 2433cea commit 0c756e1

4 files changed

Lines changed: 72 additions & 13 deletions

File tree

pygeoapi/static/js/default.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/******************************************************************
2+
*
3+
* Authors: Tom Kralidis <tomkralidis@gmail.com>
4+
*
5+
* Copyright (c) 2026 Tom Kralidis
6+
*
7+
* Permission is hereby granted, free of charge, to any person
8+
* obtaining a copy of this software and associated documentation
9+
* files (the "Software"), to deal in the Software without
10+
* restriction, including without limitation the rights to use,
11+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the
13+
* Software is furnished to do so, subject to the following
14+
* conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be
17+
* included in all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26+
* OTHER DEALINGS IN THE SOFTWARE.
27+
*
28+
******************************************************************/
29+
30+
/**
31+
* Generates a dateline safe bbox
32+
*
33+
* @param {[number, number, number, number]} bbox
34+
* Array of minx, miny, maxx, maxy
35+
*
36+
* @returns {[number, number, number, number]}
37+
* Dateline safe bbox
38+
*/
39+
40+
function gen_safe_bbox(bbox) {
41+
if (bbox[2] < bbox[0]) {
42+
bbox[2] += 360;
43+
}
44+
45+
return bbox;
46+
}

pygeoapi/templates/collections/collection.html

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
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='https://unpkg.com/leaflet-imageoverlay-ogcapi@0.1.0/Leaflet.ImageOverlay.OGCAPI.js'></script>
13+
<script src="https://unpkg.com/leaflet-imageoverlay-ogcapi@0.1.0/Leaflet.ImageOverlay.OGCAPI.js"></script>
14+
<script src="{{ config['server']['url'] }}/static/js/default.js"></script>
1415
{% endblock %}
1516

1617
{% block body %}
@@ -148,11 +149,13 @@ <h3>{% trans %}Storage CRS{% endtrans %}</h3>
148149
}
149150
));
150151

152+
var bbox = gen_safe_bbox({{ data['extent']['spatial']['bbox'][0] }});
153+
151154
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] }}']
155+
[bbox[1], bbox[0]],
156+
[bbox[3], bbox[0]],
157+
[bbox[3], bbox[2]],
158+
[bbox[1], bbox[2]]
156159
]);
157160

158161
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: 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 %}
@@ -97,12 +98,16 @@ <h4>{% trans %}Assets{% endtrans %}</h4>
9798
attribution: '{{ config['server']['map']['attribution'] | safe }}'
9899
}
99100
));
101+
102+
var bbox = gen_safe_bbox({{ data['extent']['spatial']['bbox'][0] }});
103+
100104
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] }}],
105+
[bbox[1], bbox[0]],
106+
[bbox[3], bbox[0]],
107+
[bbox[3], bbox[2]],
108+
[bbox[1], bbox[2]]
105109
]);
110+
106111
map.addLayer(bbox_layer);
107112
map.fitBounds(bbox_layer.getBounds(), {maxZoom: 10});
108113
</script>

0 commit comments

Comments
 (0)