diff --git a/VIPSWeb/static/css/vipsweb.css b/VIPSWeb/static/css/vipsweb.css index bcb97eb70a9ea5a8c24f9edb5a64c90bfd21a766..b2d983cf2fd697b06d1343b3730bf31b8b80b1c2 100755 --- a/VIPSWeb/static/css/vipsweb.css +++ b/VIPSWeb/static/css/vipsweb.css @@ -130,7 +130,14 @@ a.signinLink, a.signinLink:visited { } - +.featureInfo { + display: none; + position: absolute; + background-color: white; + border: 1px solid black; + padding: 5px; + transition: opacity 0.5s ease-out; +} a.dropdown-toggle{ height: 65px; diff --git a/docs/install.md b/docs/install.md index 5178f33e008dccc9a9d2fbe12475cfca2a6b79cb..7163a9e1943bace41105d8f4d515152c34ca7067 100644 --- a/docs/install.md +++ b/docs/install.md @@ -29,6 +29,11 @@ pip install -r requirements.txt ./manage.py migrate ``` +5. Run application +``` +python3 manage.py runserver +``` + ## Running with mod_wsgi The official Django documentation for this [can be found here](https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/modwsgi/) diff --git a/spatial/static/spatial/js/spatialMap.js b/spatial/static/spatial/js/spatialMap.js index 4ddd83d28fec29c5fb73bfe8c458f53ef94c8e2b..d10c7e10937f8773694f3a3237a87159a222392c 100644 --- a/spatial/static/spatial/js/spatialMap.js +++ b/spatial/static/spatial/js/spatialMap.js @@ -26,19 +26,27 @@ /* ----------------------- Global elements ------------------- */ var maxMapZoom = 10; - +var warningStatusText = { + 0: 'Sverming av 1. generasjon er over og varslingen er avsluttet', + 1: 'Mangler data', + 2: 'Sverming har ikke begynt', + 3: 'Svermingen er i startfasen', + 4: 'Svermingen er på sitt mest aktive' +} /** * Initializes the spatial map * @param {ol.Coordinate} lonLat - coordinates for the map's center (WGS84) - * @param {int} zoom - the zoom level (1-15, 1 is world wide view, 15 is greatest zoom) + * @param {int} zoomLevel - the zoom level (1-15, 1 is world wide view, 15 is greatest zoom) * @param {string} mapAttribution - The text in the corner of the map giving credits where it's due + * @param {string} mapId - The unique id of this map */ function initSpatialMap(lonLat, zoomLevel, mapAttribution, mapId) { var map; var carrotLayer; - var featureInfo = document.getElementById(mapId + "Info"); + var featureInfoId = mapId + "Info"; + var featureInfoDiv = document.getElementById(featureInfoId); // ---------- Background layer is OpenStreetMap -------------- var backgroundLayer = new ol.layer.Tile({ @@ -91,6 +99,7 @@ function initSpatialMap(lonLat, zoomLevel, mapAttribution, mapId) { map.on('singleclick', function (evt) { const coordinate = proj4('EPSG:3857', 'EPSG:25833', evt.coordinate) + const url = carrotLayerSource.getGetFeatureInfoUrl( coordinate, view.getResolution(), @@ -102,12 +111,36 @@ function initSpatialMap(lonLat, zoomLevel, mapAttribution, mapId) { .then((response) => response.text()) .then((body) => { const parser = new DOMParser(); - const xmlDOM = parser.parseFromString(body,"text/xml"); - const vipsResult = xmlDOM.getElementsByTagName("vipsResult")[0] - if(vipsResult) { - const modelName = vipsResult.getElementsByTagName("modelName")[0] - const warningStatus = vipsResult.getElementsByTagName("warningStatus")[0]; - featureInfo.innerHTML = '<h4>' + modelName.textContent + '</h4><p>coordinates = ' + proj4('EPSG:3857', 'EPSG:4326', evt.coordinate) + ' <br/>warningStatus = ' + warningStatus.getAttribute('value') + '</p>' + const xmlDOM = parser.parseFromString(body,"text/xml"); + const result = xmlDOM.getElementsByTagName("vipsResult")[0] + if(result) { + const modelName = result.getElementsByTagName("modelName")[0] + const warningStatus = result.getElementsByTagName("warningStatus")[0]; + + // Calculate position of feature info div + const mapRect = document.getElementById(mapId).getBoundingClientRect(); + const mapLeft = mapRect.left + window.scrollX; + const mapTop = mapRect.top + window.scrollY; + const pixel = map.getEventPixel(evt.originalEvent); + const clickLeft = mapLeft + pixel[0] - 180; + const clickTop = mapTop + pixel[1] - 100; + + // Hide when warning status is 0 + if (warningStatus.getAttribute('value') === '0') { + featureInfoDiv.style.display = 'none'; + } else { + featureInfoDiv.innerHTML = warningStatusText[warningStatus.getAttribute('value')]; + featureInfoDiv.style.display = 'block'; + featureInfoDiv.style.opacity = "1" + featureInfoDiv.style.left = clickLeft + "px"; + featureInfoDiv.style.top = clickTop + "px"; + + // Hide the feature info div after the specified duration + var duration = 2500; + setTimeout(function() { + featureInfoDiv.style.opacity = "0"; + }, duration); + } } }); diff --git a/spatial/templates/spatial/index.html b/spatial/templates/spatial/index.html index 2972cd1a3dd7a0204411b0225c44b37465d2218f..16e2949ca7f2588e055f728ec96406cf975f94cf 100644 --- a/spatial/templates/spatial/index.html +++ b/spatial/templates/spatial/index.html @@ -79,10 +79,10 @@ <div class="col-md-6" id="mapToday" class="map" style="height: {{settings.MAP_HEIGHT}}px;">Today</div> <div class="col-md-6" id="mapTomorrow" class="map" style="height: {{settings.MAP_HEIGHT}}px;">Tomorrow</div> </div><!-- End row --> - <div class="row" id="featureInfoRow" style="background-color:#fff;"> - <div id="mapTodayInfo" class="mapTodayInfo col-md-6"></div> - <div id="mapTomorrowInfo" class="col-md-6"></div> - </div><!-- End row --> + + <div id="mapTodayInfo" class="featureInfo"></div> + <div id="mapTomorrowInfo" class="featureInfo"></div> + </div> {% endblock %} \ No newline at end of file