@@ -44,39 +44,52 @@ <h2>Links</h2>
44
44
</ ul >
45
45
</ div >
46
46
< div class ="col-sm ">
47
+ {% if response.extent and response.extent.spatial %}
47
48
< div id ="map " class ="rounded " style ="width: 100%; height: 400px ">
48
49
Loading...
49
50
</ div >
51
+ {% endif %}
50
52
</ div >
51
53
</ div >
52
54
55
+ {% if response.extent and response.extent.spatial %}
53
56
< script >
54
57
$ ( 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 © <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 ( [
59
79
[ bbox [ 1 ] , bbox [ 0 ] ] ,
60
80
[ bbox [ 1 ] , bbox [ 2 ] ] ,
61
81
[ bbox [ 3 ] , bbox [ 2 ] ] ,
62
82
[ bbox [ 3 ] , bbox [ 0 ] ]
63
- ] ) ;
83
+ ] , options ) ;
64
84
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 © <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>'
70
- }
71
- ) ) ;
72
85
73
86
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
+ }
77
90
}
78
-
79
91
} ) ;
80
92
</ script >
93
+ {% endif %}
81
94
82
95
{% include "footer.html" %}
0 commit comments