|
| 1 | +{% extends "_base.html" %} |
| 2 | +{% block title %}{{ super() }} {{ data['title'] }} {% endblock %} |
| 3 | +{% block crumbs %}{{ super() }} |
| 4 | +/ <a href="{{ data['collections_path'] }}">{% trans %}Collections{% endtrans %}</a> |
| 5 | +/ <a href="../{{ data['id'] }}">{{ data['title'] }}</a> |
| 6 | +/ <a href="../{{ data['id'] }}/tiles">{% trans %}Tiles{% endtrans %}</a> |
| 7 | +{% endblock %} |
| 8 | +{% block extrahead %} |
| 9 | + <link rel=" stylesheet" href=" https://unpkg.com/[email protected]/dist/leaflet.css" /> |
| 10 | + <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.1/leaflet.js"></script> |
| 11 | + <script src="https://unpkg.com/leaflet.vectorgrid@latest/dist/Leaflet.VectorGrid.bundled.js"></script> |
| 12 | + <style> |
| 13 | + .leaflet-popup-content { |
| 14 | + width: 200px; |
| 15 | + height: 100px; |
| 16 | + } |
| 17 | + </style> |
| 18 | +{% endblock %} |
| 19 | + |
| 20 | +{% block body %} |
| 21 | + <section id="collection"> |
| 22 | + <h1>{{ data['title'] }}</h1> |
| 23 | + <p>{{ data['description'] }}</p> |
| 24 | + <p> |
| 25 | + {% for kw in data['keywords'] %} |
| 26 | + <span class="badge text-bg-primary bg-primary">{{ kw }}</span> |
| 27 | + {% endfor %} |
| 28 | + </p> |
| 29 | + <h3>Tiles</h3> |
| 30 | + <div class="row"> |
| 31 | + <div class="col-md-2 col-sm-12">{% trans %}Tile Matrix Set{% endtrans %}</div> |
| 32 | + <div class="col-md-8"> |
| 33 | + <select id="tilingScheme"> |
| 34 | + {% for tileset in data['tilesets'] %} |
| 35 | + <option value="{{ tileset }}">{{ tileset }}</option> |
| 36 | + {% endfor %} |
| 37 | + </select> |
| 38 | + </div> |
| 39 | + </div> |
| 40 | + <br/> |
| 41 | + <div class="row"> |
| 42 | + <div class="col-md-2 col-sm-12">{% trans %}Metadata{% endtrans %}</div> |
| 43 | + <div class="col-md-8"><a id="metadata_link" href="" target="_blank">Metadata</a></div> |
| 44 | + </div> |
| 45 | + <script> |
| 46 | + var select = document.getElementById('tilingScheme'); |
| 47 | + let params = (new URL(document.location)).searchParams; |
| 48 | + var scheme = params.get('scheme') ?? select.value; |
| 49 | + if (scheme) { |
| 50 | + select.value = scheme; |
| 51 | + document.getElementById("metadata_link").href = "{{ config['server']['url'] }}/collections/{{ data['id'] }}/tiles/" + scheme + "/metadata"; |
| 52 | + } |
| 53 | + select.addEventListener('change', ev => { |
| 54 | + var scheme = ev.target.value; |
| 55 | + console.log(scheme); |
| 56 | + document.location.search = `scheme=${scheme}`; |
| 57 | + document.getElementById("metadata_link").href = "{{ config['server']['url'] }}/collections/{{ data['id'] }}/tiles/" + scheme + "/metadata"; |
| 58 | + }); |
| 59 | + </script> |
| 60 | + <br/> |
| 61 | + <div class="row"> |
| 62 | + <div class="col-md-2 col-sm-12">Map</div> |
| 63 | + <div class="col-md-8"> |
| 64 | + <div id="items-map"></div> |
| 65 | + </div> |
| 66 | + </div> |
| 67 | + </section> |
| 68 | +{% endblock %} |
| 69 | + |
| 70 | +{% block extrafoot %} |
| 71 | + <script> |
| 72 | + var map = L.map('items-map').setView([{{ 45 }}, {{ -75 }}], 10); |
| 73 | + |
| 74 | + map.addLayer(new L.TileLayer( |
| 75 | + '{{ config["server"]["map"]["url"] }}', { |
| 76 | + maxZoom: {{ data['maxzoom'] }}, |
| 77 | + attribution: '{{ config["server"]["map"]["attribution"] | safe }}' |
| 78 | + } |
| 79 | + )); |
| 80 | + |
| 81 | + {% for link in data["links"] %} |
| 82 | + {% if link["rel"] == "item" %} |
| 83 | + var tilesUrl = '{{ link["href"] }}'; |
| 84 | + {% endif %} |
| 85 | + {% endfor %} |
| 86 | + var url = tilesUrl |
| 87 | + .replace('{dataset}', '{{ data["id"] }}') |
| 88 | + .replace('{tileMatrixSetId}', scheme) |
| 89 | + .replace("tileMatrix", "z") |
| 90 | + {% if data['tile_type'] == 'raster' %} |
| 91 | + url = url |
| 92 | + .replace("tileRow", "y") |
| 93 | + .replace("tileCol", "x"); |
| 94 | + map.addLayer(new L.TileLayer( |
| 95 | + url, { |
| 96 | + maxZoom: {{ data['maxzoom'] }}, |
| 97 | + crs: 'EPSG:3857' |
| 98 | + } |
| 99 | + )); |
| 100 | + {% elif data['tile_type'] == 'vector' %} |
| 101 | + url = url |
| 102 | + .replace("tileRow", "x") |
| 103 | + .replace("tileCol", "y"); |
| 104 | + var VectorTileOptions = { |
| 105 | + interactive: true, |
| 106 | + rendererFactory: L.canvas.tile, |
| 107 | + maxZoom: {{ data['maxzoom'] }}, |
| 108 | + indexMaxZoom: 5, |
| 109 | + getFeatureId: function(feat) { |
| 110 | + return feat.properties["id"] |
| 111 | + }, |
| 112 | + vectorTileLayerStyles: { |
| 113 | + {{ data["id"] }}: function(properties, zoom) { |
| 114 | + |
| 115 | + return { |
| 116 | + weight: 1, |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + }; |
| 121 | + |
| 122 | + var highlight; |
| 123 | + var clearHighlight = function() { |
| 124 | + if (highlight) { |
| 125 | + tilesPbfLayer.resetFeatureStyle(highlight); |
| 126 | + } |
| 127 | + highlight = null; |
| 128 | + }; |
| 129 | + |
| 130 | + var tilesPbfLayer = L.vectorGrid.protobuf(url, VectorTileOptions) |
| 131 | + .on('click', function(e) { // The .on method attaches an event handler |
| 132 | + var uri = e.layer.properties.uri; |
| 133 | + L.popup({minWidth: 300, maxHeight: 50}) |
| 134 | + .setContent(`<b>URI</b>: <a href="${uri}">${uri}</a>`) |
| 135 | + .setLatLng(e.latlng) |
| 136 | + .openOn(map); |
| 137 | + |
| 138 | + clearHighlight(); |
| 139 | + highlight = e.layer.properties.id; |
| 140 | + tilesPbfLayer.setFeatureStyle(highlight, { |
| 141 | + weight: 2, |
| 142 | + color: 'red', |
| 143 | + opacity: 1, |
| 144 | + fillColor: 'red', |
| 145 | + fill: false, |
| 146 | + radius: 6, |
| 147 | + fillOpacity: 1 |
| 148 | + }); |
| 149 | + |
| 150 | + L.DomEvent.stop(e); |
| 151 | + }) |
| 152 | + .addTo(map); |
| 153 | + |
| 154 | + map.on('click', clearHighlight); |
| 155 | + {% endif %} |
| 156 | + |
| 157 | + bounds = L.latLngBounds([ |
| 158 | + [ |
| 159 | + {{ data['bounds'][1] }}, |
| 160 | + {{ data['bounds'][0] }} |
| 161 | + ],[ |
| 162 | + {{ data['bounds'][3] }}, |
| 163 | + {{ data['bounds'][2] }} |
| 164 | + ] |
| 165 | + ]); |
| 166 | + map.fitBounds(bounds, maxZoom={{ data['maxzoom']}}); |
| 167 | + |
| 168 | + </script> |
| 169 | +{% endblock %} |
0 commit comments