diff --git a/.gitignore b/.gitignore index 0444c3c73ce0041df63d184c25efb9f753158e0b..d0687e4e95120dd169dedbb0ee849d71a874c828 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ VIPSWeb/default.sqlite3 VIPSWeb/assets VIPSWeb/local_settings.py -VIPSWeb/static/js/ol.js .project .pydevproject *.pyc diff --git a/VIPSWeb/static/css/ol.css b/VIPSWeb/static/css/ol.css new file mode 120000 index 0000000000000000000000000000000000000000..06cdbf9ba878fe2c9ee9d0b0d8910c81dc2bab3a --- /dev/null +++ b/VIPSWeb/static/css/ol.css @@ -0,0 +1 @@ +/home/treinar/prosjekter/vips/2013_ny_vips/lib/OpenLayers-v3.0.0-beta.2/build/ol.css \ No newline at end of file diff --git a/VIPSWeb/static/js/forecastmap.js b/VIPSWeb/static/js/forecastmap.js index 06c650fcadbae0503587045df955ec184500fcdc..76d8f6392c56c3993c0d144da21d7fce5877682d 100644 --- a/VIPSWeb/static/js/forecastmap.js +++ b/VIPSWeb/static/js/forecastmap.js @@ -43,11 +43,9 @@ function initForecastMap(lonLat, zoomLevel, sourceHostname) // Fetching KML from VIPSLogic var forecastLayer = new ol.layer.Vector({ - source: new ol.source.Vector({ - parser: new ol.parser.KML({ - maxDepth: 1, extractStyles: true, extractAttributes: true - }), - url: "http://" + sourceHostname + "/rest/forecastresults/aggregate" + source: new ol.source.KML({ + url: "http://" + sourceHostname + "/rest/forecastresults/aggregate", + projection: "EPSG:3857" }) }); @@ -61,13 +59,13 @@ function initForecastMap(lonLat, zoomLevel, sourceHostname) target: 'map', layers: [backgroundLayer, forecastLayer], overlays: [popOverlay], - renderer: ol.RendererHint.CANVAS + renderer: 'canvas' }); - // Setting zoom and center for the map + // Setting zoom and center for the map (need to do this after creating map. so that we kan transform our + // center to correct map projection) var view = new ol.View2D({ - // bb is probably replaced with getCode() in future release - center: ol.proj.transform(lonLat, 'EPSG:4326', map.getView().getProjection().bb), + center: ol.proj.transform(lonLat, 'EPSG:4326', map.getView().getProjection().getCode()), zoom:zoomLevel }); map.setView(view); @@ -84,19 +82,19 @@ function initForecastMap(lonLat, zoomLevel, sourceHostname) // Using Bootstrap's popover plugin. See http://getbootstrap.com/javascript/#popovers var poiDetails = $("#popover"); - + // State cariable var currentClickedFeature = false; + // Initiated on mouseover + // Displays station name in a tooltip box var displayFeatureName = function(pixel) { poiTitle.css({ left: pixel[0] + 'px', top: (pixel[1] - 15) + 'px' }); - map.getFeatures({ - pixel: pixel, - layers: [forecastLayer], - success: function(layerFeatures) { - var feature = layerFeatures[0][0]; + var feature = map.forEachFeatureAtPixel(pixel, function(feature,layer){ + return feature; + }); var title = poiTitle.data("bs.tooltip").options.title; if (feature && feature != currentClickedFeature) { poiTitle.tooltip('hide'); @@ -110,110 +108,104 @@ function initForecastMap(lonLat, zoomLevel, sourceHostname) } } - } - }); + }; + // Error handling when collecting forecast information from server fails var handleAjaxError = function(jqXHR,textStatus,errorThrown){ var message = jqXHR.responseJSON !== undefined ? jqXHR.responseJSON.message : jqXHR.responseText; alert ("Error: " + message); }; + // Displays popup with forecasts for a given station + // (if there is a station where the click event is fired) var displayFeatureDetails = function(pixel, coordinate) { - /*poiDetails.css({ - left: pixel[0] + 'px', - top: (pixel[1] - 15) + 'px' - }); - */ - popOverlay.setPosition(coordinate); - map.getFeatures({ - pixel: pixel, - layers: [forecastLayer], - success: function(layerFeatures) { - var feature = layerFeatures[0][0]; - if (feature) { - poiTitle.tooltip('hide'); - poiDetails.popover('destroy'); - currentClickedFeature = feature; - var request = $.ajax({ - type:"GET", - url: "http://" + sourceHostname + "/rest/forecastresults/latest/poi/" + feature.getId(), - statusCode:{ - 200: function(data,textStatus, jqXHR){ - // Building result HTML - var resultHTML = [] - //console.log(data.results); - for(index in data.results) - { - var forecastConfiguration = data.forecastConfigurations[data.results[index].forecastConfigurationId]; - var alertClass = ""; - switch(data.results[index].warningStatus) - { - case 2: - alertClass = "alert-success"; - break; - case 3: - alertClass = "alert-warning"; - break; - case 4: - alertClass = "alert-danger"; - break; - default: - alertClass = "alert-info"; - } - - //console.log(forecastConfiguration); - resultHTML.push("<div class=\"" + alertClass + "\">" + moment(data.results[index].resultValidTime).format("YYYY-MM-DD") + ": <a href=\"/forecasts/" + forecastConfiguration.forecastConfigurationId + "\" class=\"alert-link\">" + modelLocalNames[forecastConfiguration.modelId] + "</a></div>"); - } - - if(resultHTML.length == 0) + var feature = map.forEachFeatureAtPixel(pixel, function(feature,layer){ + return feature; + }); + + if (feature) { + // Position the popup, and hiding it + // Resetting information from (possible) former popups + var geometry = feature.getGeometry(); + popOverlay.setPosition(geometry.getCoordinates()); + poiTitle.tooltip('hide'); + poiDetails.popover('destroy'); + currentClickedFeature = feature; + // Fetching information asynchronously from server + var request = $.ajax({ + type:"GET", + url: "http://" + sourceHostname + "/rest/forecastresults/latest/poi/" + feature.getId(), + statusCode:{ + 200: function(data,textStatus, jqXHR){ + // Building result HTML + var resultHTML = [] + for(index in data.results) + { + var forecastConfiguration = data.forecastConfigurations[data.results[index].forecastConfigurationId]; + var alertClass = ""; + switch(data.results[index].warningStatus) { - resultHTML.push(gettext("No forecasts found for") + " " + feature.get("name")); + case 2: + alertClass = "alert-success"; + break; + case 3: + alertClass = "alert-warning"; + break; + case 4: + alertClass = "alert-danger"; + break; + default: + alertClass = "alert-info"; } - - // Testing - //resultHTML = ["Mange små ord mange små ord Få ord"]; - poiDetails.popover({ - animation: true, - trigger: 'manual', - html: true, - placement: "auto top", - title: feature.get("name"), - content: resultHTML.join("") - }); - - poiDetails.popover('show'); - //info.data("bs.tooltip").options.title = resultHTML.join("") ; - //info.tooltip('show'); - }, - 400: handleAjaxError, - 401: handleAjaxError, - 404: handleAjaxError, - 500: handleAjaxError - } - }); - - - } else { - currentClickedFeature = null; - poiDetails.popover('destroy'); - } - } - }); - }; + + resultHTML.push("<div class=\"" + alertClass + "\">" + moment(data.results[index].resultValidTime).format("YYYY-MM-DD") + ": <a href=\"/forecasts/" + forecastConfiguration.forecastConfigurationId + "\" class=\"alert-link\">" + modelLocalNames[forecastConfiguration.modelId] + "</a></div>"); + } + + if(resultHTML.length == 0) + { + resultHTML.push(gettext("No forecasts found for") + " " + feature.get("name")); + } + + // Create the popup, showing it + poiDetails.popover({ + animation: true, + trigger: 'manual', + html: true, + placement: "auto top", + title: feature.get("name"), + content: resultHTML.join("") + }); + + poiDetails.popover('show'); + + }, + 400: handleAjaxError, + 401: handleAjaxError, + 404: handleAjaxError, + 500: handleAjaxError + } + }); + + + } else { + currentClickedFeature = null; + poiDetails.popover('destroy'); + } + + }; - // On mouseover, display name of POI - //$(map.getViewport()).on('mousemove', function(evt) { + // On mouseover, display name of POI in tooltip map.on('mousemove', function(evt) { - //var pixel = map.getEventPixel(evt.originalEvent); - var pixel = evt.getPixel() + var pixel = map.getEventPixel(evt.originalEvent); displayFeatureName(pixel); }); - // On click, display forecasts + // On click, display forecasts in popup map.on('click', function(evt) { - displayFeatureDetails(evt.getPixel(),evt.getCoordinate()); + var pixel = map.getEventPixel(evt.originalEvent); + displayFeatureDetails(pixel); }); map.on('moveend', function(evt) { diff --git a/VIPSWeb/static/test/mockKML.kml b/VIPSWeb/static/test/mockKML.kml index a8471064df7054005c61c92de252609150221d26..312391dfaacc079e64470448160a8bfddc5da770 100644 --- a/VIPSWeb/static/test/mockKML.kml +++ b/VIPSWeb/static/test/mockKML.kml @@ -44,7 +44,8 @@ <IconStyle> <scale>0.55</scale> <Icon> - <href>http://www.vips-landbruk.no/graphics/dot_green.png</href> + <!--href>http://www.vips-landbruk.no/graphics/dot_green.png</href--> + <href>http://maps.google.com/mapfiles/kml/shapes/parking_lot.png</href> </Icon> </IconStyle> </Style> @@ -75,7 +76,7 @@ <Placemark> <name>Apelsvoll</name> <description><![CDATA[Mangler informasjon om varsler for Apelsvoll]]></description> - <styleUrl>#style_4</styleUrl> + <!--styleUrl>#style_4</styleUrl--> <Point> <coordinates>10.86952,60.70024</coordinates> </Point> diff --git a/VIPSWeb/templates/index.html b/VIPSWeb/templates/index.html index c465fa88762e1fe327692c85685ba917a3c39888..4a278d626c42f0f24a0615646028014a79a17d7a 100644 --- a/VIPSWeb/templates/index.html +++ b/VIPSWeb/templates/index.html @@ -21,11 +21,11 @@ {% load i18n l10n staticfiles forecast_extras %} {% block title%}{% trans "Welcome" %}{%endblock%} {% block customCSS %} -<link rel="stylesheet" href="http://ol3js.org/en/master/build/ol.css" type="text/css"> +<link rel="stylesheet" href="{% static "css/ol.css" %}" type="text/css"> {% endblock %} {% block customJS %} <script type="text/javascript" src="{% url 'django.views.i18n.javascript_catalog' %}"></script> -<script type="text/javascript" src="{% static "js/ol.js" %}" type="text/javascript"></script> +<script type="text/javascript" src="{% static "js/ol.js" %}"></script> <script type="text/javascript" src="/forecasts/models/js/modelLocalNames.js"></script> <script type="text/javascript" src="{% static "js/moment.min.js" %}"></script> <script type="text/javascript" src="{% static "js/forecastmap.js" %}"></script> @@ -53,7 +53,7 @@ {% for message_tag in message_tags %} <thead> <tr> - <th colspan="2">{{message_tag.default_tag_name}}</th> + <th colspan="2">{{message_tag.local_tag_name|default_if_none:message_tag.default_tag_name}}</th> </tr> </thead> <tbody> diff --git a/messages/models.py b/messages/models.py index 820a2aeddfe25e8184fb72cb721aafcdb100f92c..982a94b0e0ed87805642138c4fceb1b0b52bc881 100644 --- a/messages/models.py +++ b/messages/models.py @@ -43,10 +43,14 @@ class MessageTag: @staticmethod def get_instance_from_dict(item): + local_tag_name = None + for tagLocale in item["messageTagLocaleSet"]: + if tagLocale["messageTagLocalePK"]["locale"] == settings.VIPSLOGIC_LANGUAGE_CODE: + local_tag_name = tagLocale["localName"] return MessageTag( item["messageTagId"], item["defaultTagName"], - None + local_tag_name ) class Message: