Skip to content
Snippets Groups Projects
Commit f8991044 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Added editing of weather stations and lots of back buttons

parent 808fb897
Branches
Tags
No related merge requests found
Showing
with 876 additions and 60 deletions
...@@ -80,6 +80,8 @@ public class ObservationController extends HttpServlet { ...@@ -80,6 +80,8 @@ public class ObservationController extends HttpServlet {
{ {
Observation observation = new Observation(); Observation observation = new Observation();
request.setAttribute("observation", observation); request.setAttribute("observation", observation);
request.setAttribute("defaultMapCenter",user.getOrganizationId().getDefaultMapCenter());
request.setAttribute("defaultMapZoom", user.getOrganizationId().getDefaultMapZoom());
List<Organism> allOrganisms = em.createNamedQuery("Organism.findAll").getResultList(); List<Organism> allOrganisms = em.createNamedQuery("Organism.findAll").getResultList();
request.setAttribute("allOrganisms", allOrganisms); request.setAttribute("allOrganisms", allOrganisms);
// Hierarchy categories // Hierarchy categories
...@@ -152,7 +154,6 @@ public class ObservationController extends HttpServlet { ...@@ -152,7 +154,6 @@ public class ObservationController extends HttpServlet {
observation.setLocation(formValidation.getFormField("location").getValueAsPointWGS84()); observation.setLocation(formValidation.getFormField("location").getValueAsPointWGS84());
observation = SessionControllerGetter.getObservationBean().storeObservation(observation); observation = SessionControllerGetter.getObservationBean().storeObservation(observation);
// Redirecting to form
// Redirect to form // Redirect to form
response.sendRedirect(new StringBuilder("http://") response.sendRedirect(new StringBuilder("http://")
.append(ServletUtil.getServerName(request)) .append(ServletUtil.getServerName(request))
......
...@@ -22,14 +22,26 @@ package no.bioforsk.vips.logic.controller.servlet; ...@@ -22,14 +22,26 @@ package no.bioforsk.vips.logic.controller.servlet;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.TimeZone; import java.util.TimeZone;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import no.bioforsk.vips.logic.entity.Country;
import no.bioforsk.vips.logic.entity.PointOfInterest; import no.bioforsk.vips.logic.entity.PointOfInterest;
import no.bioforsk.vips.logic.entity.PointOfInterestType;
import no.bioforsk.vips.logic.entity.PointOfInterestWeatherStation; import no.bioforsk.vips.logic.entity.PointOfInterestWeatherStation;
import no.bioforsk.vips.logic.entity.VipsLogicRole;
import no.bioforsk.vips.logic.entity.VipsLogicUser; import no.bioforsk.vips.logic.entity.VipsLogicUser;
import no.bioforsk.vips.logic.entity.WeatherStationDataSource;
import no.bioforsk.vips.logic.util.Globals;
import no.bioforsk.vips.logic.util.SessionControllerGetter; import no.bioforsk.vips.logic.util.SessionControllerGetter;
import no.bioforsk.vips.util.ExceptionUtil;
import no.bioforsk.vips.util.ServletUtil;
import no.bioforsk.web.forms.FormValidation;
import no.bioforsk.web.forms.FormValidationException;
import no.bioforsk.web.forms.FormValidator;
/** /**
* Handles transactions for POIs * Handles transactions for POIs
...@@ -37,7 +49,8 @@ import no.bioforsk.vips.logic.util.SessionControllerGetter; ...@@ -37,7 +49,8 @@ import no.bioforsk.vips.logic.util.SessionControllerGetter;
* @author Tor-Einar Skog <tor-einar.skog@bioforsk.no> * @author Tor-Einar Skog <tor-einar.skog@bioforsk.no>
*/ */
public class PointOfInterestController extends HttpServlet { public class PointOfInterestController extends HttpServlet {
@PersistenceContext(unitName="VIPSLogic-PU")
EntityManager em;
/** /**
* Processes requests for both HTTP * Processes requests for both HTTP
* <code>GET</code> and * <code>GET</code> and
...@@ -53,7 +66,7 @@ public class PointOfInterestController extends HttpServlet { ...@@ -53,7 +66,7 @@ public class PointOfInterestController extends HttpServlet {
request.getSession().removeAttribute("weatherStations"); request.getSession().removeAttribute("weatherStations");
request.getSession().removeAttribute("weatherStation"); request.getSession().removeAttribute("weatherStation");
String action = request.getParameter("action");
VipsLogicUser user = (VipsLogicUser) request.getSession().getAttribute("user"); VipsLogicUser user = (VipsLogicUser) request.getSession().getAttribute("user");
/* /*
...@@ -66,46 +79,182 @@ public class PointOfInterestController extends HttpServlet { ...@@ -66,46 +79,182 @@ public class PointOfInterestController extends HttpServlet {
if(request.getServletPath().equals("/weatherStation")) if(request.getServletPath().equals("/weatherStation"))
{ {
// Decide if requsted view is list view or single view if(action == null)
String pointOfInterestId = request.getParameter("pointOfInterestId");
// List view
if(pointOfInterestId == null)
{ {
List<PointOfInterestWeatherStation> weatherStations; // Decide if requested view is list view or single view
if(user.isSuperUser()){ String pointOfInterestId = request.getParameter("pointOfInterestId");
weatherStations = SessionControllerGetter.getPointOfInterestBean().getAllWeatherStations(); // List view
if(pointOfInterestId == null)
{
List<PointOfInterestWeatherStation> weatherStations;
if(user.isSuperUser()){
weatherStations = SessionControllerGetter.getPointOfInterestBean().getAllWeatherStations();
}
else
{
weatherStations = SessionControllerGetter.getPointOfInterestBean().getWeatherstationsForOrganization(user.getOrganizationId());
}
request.setAttribute("defaultMapCenter",user.getOrganizationId().getDefaultMapCenter());
request.setAttribute("defaultMapZoom", user.getOrganizationId().getDefaultMapZoom());
request.getSession().setAttribute("weatherStations", weatherStations);
request.getRequestDispatcher("/weatherstationList.ftl").forward(request, response);
} }
// Single view
else else
{ {
weatherStations = SessionControllerGetter.getPointOfInterestBean().getWeatherstationsForUser(user.getUserId()); PointOfInterest weatherStation = SessionControllerGetter.getPointOfInterestBean().getPointOfInterest(Integer.valueOf(pointOfInterestId));
if(weatherStation instanceof PointOfInterestWeatherStation)
{
PointOfInterestWeatherStation stationWithDataSource = (PointOfInterestWeatherStation) weatherStation;
request.getSession().setAttribute("weatherStation", stationWithDataSource);
}
else
{
request.getSession().setAttribute("weatherStation", weatherStation);
}
request.getSession().setAttribute("availableTimeZones", TimeZone.getAvailableIDs());
request.getSession().setAttribute("defaultTimeZoneId", user.getOrganizationId().getDefaultTimeZone());
request.setAttribute("defaultMapCenter",user.getOrganizationId().getDefaultMapCenter());
request.setAttribute("defaultMapZoom", user.getOrganizationId().getDefaultMapZoom());
request.getRequestDispatcher("/weatherstationView.ftl").forward(request, response);
} }
request.getSession().setAttribute("weatherStations", weatherStations);
request.getRequestDispatcher("/weatherstationlist.ftl").forward(request, response);
} }
// Single view else if(action.equals("newWeatherStationForm"))
else
{ {
PointOfInterest weatherStation = SessionControllerGetter.getPointOfInterestBean().getPointOfInterest(Integer.valueOf(pointOfInterestId)); if(SessionControllerGetter.getUserBean().authorizeUser(user, VipsLogicRole.ORGANIZATION_ADMINISTRATOR, VipsLogicRole.SUPERUSER))
if(weatherStation instanceof PointOfInterestWeatherStation)
{ {
PointOfInterestWeatherStation stationWithDataSource = (PointOfInterestWeatherStation) weatherStation; try
request.getSession().setAttribute("weatherStation", stationWithDataSource); {
PointOfInterest weatherStation = new PointOfInterestWeatherStation();
request.getSession().setAttribute("weatherStation", weatherStation);
request.setAttribute("defaultMapCenter",user.getOrganizationId().getDefaultMapCenter());
request.setAttribute("defaultMapZoom", user.getOrganizationId().getDefaultMapZoom());
request.getSession().setAttribute("dataSources", SessionControllerGetter.getPointOfInterestBean().getWeatherStationDataSources());
request.getSession().setAttribute("availableTimeZones", TimeZone.getAvailableIDs());
request.getSession().setAttribute("defaultTimeZoneId", user.getOrganizationId().getDefaultTimeZone());
request.getSession().setAttribute("availableCountries", em.createNamedQuery("Country.findAll").getResultList());
request.getSession().setAttribute("defaultCountryCode", user.getOrganizationId().getCountryCode().getCountryCode());
if(user.isSuperUser())
{
request.getSession().setAttribute("users", em.createNamedQuery("VipsLogicUser.findAll", VipsLogicUser.class).getResultList());
}
request.getRequestDispatcher("/weatherstationForm.ftl").forward(request, response);
}
catch(NullPointerException | NumberFormatException ex)
{
response.sendError(500, ExceptionUtil.getStackTrace(ex));
}
} }
else else
{ {
request.getSession().setAttribute("weatherStation", weatherStation); response.sendError(403,"Access not authorized"); // HTTP Forbidden
} }
request.getSession().setAttribute("availableTimeZones", TimeZone.getAvailableIDs()); }
request.getSession().setAttribute("defaultTimeZoneId", TimeZone.getDefault().getID()); // Authorization: ORGANIZATION ADMIN or SUPERUSER
else if(action.equals("editWeatherStationForm"))
// Dispatch to read or write view? {
if(request.getPathInfo() != null && request.getPathInfo().equals("/edit")) if(SessionControllerGetter.getUserBean().authorizeUser(user, VipsLogicRole.ORGANIZATION_ADMINISTRATOR, VipsLogicRole.SUPERUSER))
{ {
request.getRequestDispatcher("/weatherstationForm.ftl").forward(request, response); try
{
Integer pointOfInterestId = Integer.valueOf(request.getParameter("pointOfInterestId"));
PointOfInterest weatherStation = em.find(PointOfInterest.class, pointOfInterestId);
request.getSession().setAttribute("weatherStation", weatherStation);
request.setAttribute("defaultMapCenter",user.getOrganizationId().getDefaultMapCenter());
request.setAttribute("defaultMapZoom", user.getOrganizationId().getDefaultMapZoom());
request.getSession().setAttribute("dataSources", SessionControllerGetter.getPointOfInterestBean().getWeatherStationDataSources());
request.getSession().setAttribute("availableTimeZones", TimeZone.getAvailableIDs());
request.getSession().setAttribute("defaultTimeZoneId", user.getOrganizationId().getDefaultTimeZone());
request.getSession().setAttribute("availableCountries", em.createNamedQuery("Country.findAll").getResultList());
request.getSession().setAttribute("defaultCountryCode", user.getOrganizationId().getCountryCode().getCountryCode());
if(user.isSuperUser())
{
request.getSession().setAttribute("users", em.createNamedQuery("VipsLogicUser.findAll", VipsLogicUser.class).getResultList());
}
request.getRequestDispatcher("/weatherstationForm.ftl").forward(request, response);
}
catch(NullPointerException | NumberFormatException ex)
{
response.sendError(500, ExceptionUtil.getStackTrace(ex));
}
}
else
{
response.sendError(403,"Access not authorized"); // HTTP Forbidden
}
}
// Authorization: ORGANIZATION ADMIN or SUPERUSER
else if(action.equals("weatherStationFormSubmit"))
{
if(SessionControllerGetter.getUserBean().authorizeUser(user, VipsLogicRole.ORGANIZATION_ADMINISTRATOR, VipsLogicRole.SUPERUSER))
{
try
{
Integer pointOfInterestId = Integer.valueOf(request.getParameter("pointOfInterestId"));
PointOfInterestWeatherStation weatherStation = pointOfInterestId > 0 ?
em.find(PointOfInterestWeatherStation.class, pointOfInterestId)
: new PointOfInterestWeatherStation();
FormValidation formValidation = FormValidator.validateForm("weatherStationForm", request, getServletContext());
if(formValidation.isValid())
{
// Set values
weatherStation.setName(formValidation.getFormField("name").getWebValue());
weatherStation.setAltitude(formValidation.getFormField("altitude").getValueAsDouble());
weatherStation.setLongitude(formValidation.getFormField("location").getValueAsPointWGS84().getX());
weatherStation.setLatitude(formValidation.getFormField("location").getValueAsPointWGS84().getY());
weatherStation.setWeatherStationDataSourceId(em.find(WeatherStationDataSource.class, formValidation.getFormField("weatherStationDataSourceId").getValueAsInteger()));
weatherStation.setWeatherStationRemoteId(formValidation.getFormField("weatherStationRemoteId").getWebValue());
weatherStation.setTimeZone(formValidation.getFormField("timeZone").getWebValue());
weatherStation.setCountryCode(em.find(Country.class, formValidation.getFormField("countryCode").getWebValue()));
if(weatherStation.getPointOfInterestType() == null)
{
weatherStation.setPointOfInterestType(em.find(PointOfInterestType.class, Globals.POI_TYPE_WEATHERSTATION));
}
// If userId is set from form, always update
if(user.isSuperUser() && !formValidation.getFormField("userId").isEmpty())
{
weatherStation.setUserId(em.find(VipsLogicUser.class, formValidation.getFormField("userId").getValueAsInteger()));
}
// If user is not set, use current user
else if(weatherStation.getUserId() == null)
{
weatherStation.setUserId(user);
}
// Store
weatherStation = SessionControllerGetter.getPointOfInterestBean().storeWeatherStation(weatherStation);
// Redirect to form
response.sendRedirect(new StringBuilder("http://")
.append(ServletUtil.getServerName(request))
.append("/weatherStation?action=editWeatherStationForm&pointOfInterestId=").append(weatherStation.getPointOfInterestId())
.append("&messageKey=").append("weatherStationStored").toString()
);
}
else
{
request.setAttribute("formValidation", formValidation);
request.setAttribute("weatherStation", weatherStation);
request.setAttribute("defaultMapCenter",user.getOrganizationId().getDefaultMapCenter());
request.setAttribute("defaultMapZoom", user.getOrganizationId().getDefaultMapZoom());
request.getSession().setAttribute("dataSources", SessionControllerGetter.getPointOfInterestBean().getWeatherStationDataSources());
request.getSession().setAttribute("availableTimeZones", TimeZone.getAvailableIDs());
request.getSession().setAttribute("defaultTimeZoneId", user.getOrganizationId().getDefaultTimeZone());
request.getSession().setAttribute("availableCountries", em.createNamedQuery("Country.findAll").getResultList());
request.getSession().setAttribute("defaultCountryCode", user.getOrganizationId().getCountryCode().getCountryCode());
request.getRequestDispatcher("/weatherstationForm.ftl").forward(request, response);
}
}
catch(NullPointerException | NumberFormatException | FormValidationException ex)
{
response.sendError(500, ExceptionUtil.getStackTrace(ex));
}
} }
else else
{ {
request.getRequestDispatcher("/weatherstation.ftl").forward(request, response); response.sendError(403,"Access not authorized"); // HTTP Forbidden
} }
} }
} }
......
...@@ -19,14 +19,28 @@ ...@@ -19,14 +19,28 @@
package no.bioforsk.vips.logic.controller.session; package no.bioforsk.vips.logic.controller.session;
import de.micromata.opengis.kml.v_2_2_0.Coordinate;
import de.micromata.opengis.kml.v_2_2_0.Document;
import de.micromata.opengis.kml.v_2_2_0.Kml;
import de.micromata.opengis.kml.v_2_2_0.KmlFactory;
import de.micromata.opengis.kml.v_2_2_0.Placemark;
import de.micromata.opengis.kml.v_2_2_0.Point;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.ResourceBundle;
import java.util.Set;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import javax.persistence.Query; import javax.persistence.Query;
import no.bioforsk.vips.logic.entity.Organization;
import no.bioforsk.vips.logic.entity.PointOfInterest; import no.bioforsk.vips.logic.entity.PointOfInterest;
import no.bioforsk.vips.logic.entity.PointOfInterestWeatherStation; import no.bioforsk.vips.logic.entity.PointOfInterestWeatherStation;
import no.bioforsk.vips.logic.entity.UserPointOfInterest;
import no.bioforsk.vips.logic.entity.UserPointOfInterestPK;
import no.bioforsk.vips.logic.entity.VipsLogicUser;
import no.bioforsk.vips.logic.entity.WeatherStationDataSource;
import no.bioforsk.vips.logic.util.Globals; import no.bioforsk.vips.logic.util.Globals;
...@@ -79,4 +93,78 @@ public class PointOfInterestBean { ...@@ -79,4 +93,78 @@ public class PointOfInterestBean {
return (PointOfInterest) q.getSingleResult(); return (PointOfInterest) q.getSingleResult();
} }
public Kml getWeatherstationsForOrganization(Integer organizationId, Integer excludeWeatherStationId, Integer highlightWeatherStationId, String serverName, ResourceBundle i18nBundle) {
String iconPath = "http://" + serverName + "/public/images/";
Organization organization = em.find(Organization.class, organizationId);
// Initialization
final Kml kml = KmlFactory.createKml();
final Document document = kml.createAndSetDocument()
.withName("Weather stations").withDescription("Weather stations for ");
document.createAndAddStyle()
.withId("weatherstation_icon")
.createAndSetIconStyle()
.withScale(0.55)
.createAndSetIcon()
.withHref(iconPath + "dot_blue.png");
document.createAndAddStyle()
.withId("weatherstation_icon_highlighted")
.createAndSetIconStyle()
.withScale(0.55)
.createAndSetIcon()
.withHref(iconPath + "anemometer_mono.png");
List<PointOfInterestWeatherStation> weatherStations = this.getWeatherstationsForOrganization(organization);
String description = "";
for(PointOfInterestWeatherStation weatherStation:weatherStations)
{
if(excludeWeatherStationId != null && excludeWeatherStationId.equals(weatherStation.getPointOfInterestId()))
{
continue;
}
String styleUrl = "#weatherstation_icon"
+ (highlightWeatherStationId != null && highlightWeatherStationId.equals(weatherStation.getPointOfInterestId()) ? "_highlighted" :"");
if(weatherStation instanceof PointOfInterestWeatherStation)
{
description = i18nBundle.getString("dataSourceName") +
": <a href=\"" + weatherStation.getWeatherStationDataSourceId().getUri() + "\" target=\"new\">"
+ weatherStation.getWeatherStationDataSourceId().getName()
+ "</a>";
}
final Placemark placemark = document.createAndAddPlacemark()
.withName(weatherStation.getName())
.withDescription(description)
.withStyleUrl(styleUrl)
.withId(weatherStation.getPointOfInterestId().toString());
final Point point = placemark.createAndSetPoint();
List<Coordinate> coord = point.createAndSetCoordinates();
coord.add(new Coordinate(
weatherStation.getLongitude(),
weatherStation.getLatitude(),
weatherStation.getAltitude() != null ? weatherStation.getAltitude() : 0
));
}
return kml;
}
public List<WeatherStationDataSource> getWeatherStationDataSources() {
return em.createNamedQuery("WeatherStationDataSource.findAll").getResultList();
}
public PointOfInterestWeatherStation storeWeatherStation(PointOfInterestWeatherStation weatherStation) {
weatherStation = em.merge(weatherStation);
return weatherStation;
}
public List<PointOfInterestWeatherStation> getWeatherstationsForOrganization(Organization organization) {
return em.createNamedQuery("PointOfInterestWeatherStation.findByOrganizationId", PointOfInterestWeatherStation.class)
.setParameter("organizationId", organization)
.getResultList();
}
} }
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
package no.bioforsk.vips.logic.entity; package no.bioforsk.vips.logic.entity;
import java.io.Serializable; import java.io.Serializable;
import java.util.Locale;
import java.util.Set; import java.util.Set;
import javax.persistence.Basic; import javax.persistence.Basic;
import javax.persistence.Column; import javax.persistence.Column;
...@@ -32,6 +33,7 @@ import javax.persistence.NamedQueries; ...@@ -32,6 +33,7 @@ import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
...@@ -50,19 +52,11 @@ import org.codehaus.jackson.annotate.JsonIgnore; ...@@ -50,19 +52,11 @@ import org.codehaus.jackson.annotate.JsonIgnore;
@NamedQuery(name = "Country.findByCountryCode", query = "SELECT c FROM Country c WHERE c.countryCode = :countryCode")}) @NamedQuery(name = "Country.findByCountryCode", query = "SELECT c FROM Country c WHERE c.countryCode = :countryCode")})
public class Country implements Serializable { public class Country implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull @NotNull
@Size(min = 1, max = 2) @Size(min = 1, max = 2)
@Column(name = "country_code")
private String countryCode; private String countryCode;
@JoinTable(name = "external_resource_validity", joinColumns = { private Set<ExternalResource> externalResourceSet;
@JoinColumn(name = "country_code", referencedColumnName = "country_code")}, inverseJoinColumns = { private Set<PointOfInterest> pointOfInterestSet;
@JoinColumn(name = "external_resource_id", referencedColumnName = "external_resource_id")})
@ManyToMany
private Set<ExternalResource> externalResourceSet;
@OneToMany(mappedBy = "countryCode")
private Set<PointOfInterest> pointOfInterestSet;
public Country() { public Country() {
} }
...@@ -71,6 +65,9 @@ public class Country implements Serializable { ...@@ -71,6 +65,9 @@ public class Country implements Serializable {
this.countryCode = countryCode; this.countryCode = countryCode;
} }
@Id
@Basic(optional = false)
@Column(name = "country_code")
public String getCountryCode() { public String getCountryCode() {
return countryCode; return countryCode;
} }
...@@ -79,6 +76,10 @@ public class Country implements Serializable { ...@@ -79,6 +76,10 @@ public class Country implements Serializable {
this.countryCode = countryCode; this.countryCode = countryCode;
} }
@JoinTable(name = "external_resource_validity", joinColumns = {
@JoinColumn(name = "country_code", referencedColumnName = "country_code")}, inverseJoinColumns = {
@JoinColumn(name = "external_resource_id", referencedColumnName = "external_resource_id")})
@ManyToMany
@XmlTransient @XmlTransient
@JsonIgnore @JsonIgnore
public Set<ExternalResource> getExternalResourceSet() { public Set<ExternalResource> getExternalResourceSet() {
...@@ -89,6 +90,7 @@ public class Country implements Serializable { ...@@ -89,6 +90,7 @@ public class Country implements Serializable {
this.externalResourceSet = externalResourceSet; this.externalResourceSet = externalResourceSet;
} }
@OneToMany(mappedBy = "countryCode")
@XmlTransient @XmlTransient
@JsonIgnore @JsonIgnore
public Set<PointOfInterest> getPointOfInterestSet() { public Set<PointOfInterest> getPointOfInterestSet() {
...@@ -124,4 +126,10 @@ public class Country implements Serializable { ...@@ -124,4 +126,10 @@ public class Country implements Serializable {
return "no.bioforsk.vips.logic.entity.Country[ countryCode=" + countryCode + " ]"; return "no.bioforsk.vips.logic.entity.Country[ countryCode=" + countryCode + " ]";
} }
public String getCountryName(String language)
{
Locale locale = new Locale(language, this.countryCode);
return locale.getDisplayCountry();
}
} }
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package no.bioforsk.vips.logic.entity; package no.bioforsk.vips.logic.entity;
import com.vividsolutions.jts.geom.Point;
import java.io.Serializable; import java.io.Serializable;
import java.util.Set; import java.util.Set;
import javax.persistence.Basic; import javax.persistence.Basic;
...@@ -37,6 +38,7 @@ import javax.validation.constraints.Size; ...@@ -37,6 +38,7 @@ import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient; import javax.xml.bind.annotation.XmlTransient;
import org.codehaus.jackson.annotate.JsonIgnore; import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.annotations.Type;
/** /**
* @copyright 2013 <a href="http://www.bioforsk.no/">Bioforsk</a> * @copyright 2013 <a href="http://www.bioforsk.no/">Bioforsk</a>
...@@ -71,6 +73,14 @@ public class Organization implements Serializable { ...@@ -71,6 +73,14 @@ public class Organization implements Serializable {
@Size(max = 63) @Size(max = 63)
@Column(name = "postal_code") @Column(name = "postal_code")
private String postalCode; private String postalCode;
@Column(name = "default_map_zoom")
private Integer defaultMapZoom;
@Column(name = "default_time_zone")
private String defaultTimeZone;
@JsonIgnore
@Type(type = "org.hibernate.spatial.GeometryType")
@Column(name = "default_map_center", columnDefinition = "Geometry")
private Point defaultMapCenter;
@OneToMany(mappedBy = "parentOrganizationId") @OneToMany(mappedBy = "parentOrganizationId")
private Set<Organization> organizationSet; private Set<Organization> organizationSet;
@JoinColumn(name = "parent_organization_id", referencedColumnName = "organization_id") @JoinColumn(name = "parent_organization_id", referencedColumnName = "organization_id")
...@@ -207,4 +217,46 @@ public class Organization implements Serializable { ...@@ -207,4 +217,46 @@ public class Organization implements Serializable {
this.defaultLocale = defaultLocale; this.defaultLocale = defaultLocale;
} }
/**
* @return the defaultMapZoom
*/
public Integer getDefaultMapZoom() {
return defaultMapZoom;
}
/**
* @param defaultMapZoom the defaultMapZoom to set
*/
public void setDefaultMapZoom(Integer defaultMapZoom) {
this.defaultMapZoom = defaultMapZoom;
}
/**
* @return the defaultMapCenter
*/
public Point getDefaultMapCenter() {
return defaultMapCenter;
}
/**
* @param defaultMapCenter the defaultMapCenter to set
*/
public void setDefaultMapCenter(Point defaultMapCenter) {
this.defaultMapCenter = defaultMapCenter;
}
/**
* @return the defaultTimeZone
*/
public String getDefaultTimeZone() {
return defaultTimeZone;
}
/**
* @param defaultTimeZone the defaultTimeZone to set
*/
public void setDefaultTimeZone(String defaultTimeZone) {
this.defaultTimeZone = defaultTimeZone;
}
} }
...@@ -21,9 +21,7 @@ package no.bioforsk.vips.logic.entity; ...@@ -21,9 +21,7 @@ package no.bioforsk.vips.logic.entity;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.persistence.Basic; import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity; import javax.persistence.Entity;
...@@ -36,12 +34,10 @@ import javax.persistence.JoinColumn; ...@@ -36,12 +34,10 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries; import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient; import javax.persistence.Transient;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.codehaus.jackson.annotate.JsonIgnore; import org.codehaus.jackson.annotate.JsonIgnore;
/** /**
...@@ -60,7 +56,8 @@ import org.codehaus.jackson.annotate.JsonIgnore; ...@@ -60,7 +56,8 @@ import org.codehaus.jackson.annotate.JsonIgnore;
@NamedQuery(name = "PointOfInterest.findByName", query = "SELECT p FROM PointOfInterest p WHERE p.name = :name"), @NamedQuery(name = "PointOfInterest.findByName", query = "SELECT p FROM PointOfInterest p WHERE p.name = :name"),
@NamedQuery(name = "PointOfInterest.findByLongitude", query = "SELECT p FROM PointOfInterest p WHERE p.longitude = :longitude"), @NamedQuery(name = "PointOfInterest.findByLongitude", query = "SELECT p FROM PointOfInterest p WHERE p.longitude = :longitude"),
@NamedQuery(name = "PointOfInterest.findByLatitude", query = "SELECT p FROM PointOfInterest p WHERE p.latitude = :latitude"), @NamedQuery(name = "PointOfInterest.findByLatitude", query = "SELECT p FROM PointOfInterest p WHERE p.latitude = :latitude"),
@NamedQuery(name = "PointOfInterest.findByAltitude", query = "SELECT p FROM PointOfInterest p WHERE p.altitude = :altitude") @NamedQuery(name = "PointOfInterest.findByAltitude", query = "SELECT p FROM PointOfInterest p WHERE p.altitude = :altitude"),
@NamedQuery(name = "PointOfInterest.findByUserId", query = "SELECT p FROM PointOfInterest p WHERE p.userId = :userId")
}) })
public class PointOfInterest implements Serializable, Comparable { public class PointOfInterest implements Serializable, Comparable {
...@@ -83,8 +80,9 @@ public class PointOfInterest implements Serializable, Comparable { ...@@ -83,8 +80,9 @@ public class PointOfInterest implements Serializable, Comparable {
private Double latitude; private Double latitude;
@Column(name = "altitude") @Column(name = "altitude")
private Double altitude; private Double altitude;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "pointOfInterest") @JoinColumn(name = "user_id", referencedColumnName = "user_id")
private Set<UserPointOfInterest> userPointOfInterestSet; @ManyToOne
private VipsLogicUser userId;
@JoinColumn(name = "country_code", referencedColumnName = "country_code") @JoinColumn(name = "country_code", referencedColumnName = "country_code")
@ManyToOne @ManyToOne
private Country countryCode; private Country countryCode;
...@@ -144,16 +142,7 @@ public class PointOfInterest implements Serializable, Comparable { ...@@ -144,16 +142,7 @@ public class PointOfInterest implements Serializable, Comparable {
this.altitude = altitude; this.altitude = altitude;
} }
@XmlTransient
@JsonIgnore
public Set<UserPointOfInterest> getUserPointOfInterestSet() {
return userPointOfInterestSet;
}
public void setUserPointOfInterestSet(Set<UserPointOfInterest> userPointOfInterestSet) {
this.userPointOfInterestSet = userPointOfInterestSet;
}
public Country getCountryCode() { public Country getCountryCode() {
return countryCode; return countryCode;
} }
...@@ -249,4 +238,19 @@ public class PointOfInterest implements Serializable, Comparable { ...@@ -249,4 +238,19 @@ public class PointOfInterest implements Serializable, Comparable {
public void setProperties(Map<String,Object> properties) { public void setProperties(Map<String,Object> properties) {
this.properties = properties; this.properties = properties;
} }
/**
* @return the userId
*/
@JsonIgnore
public VipsLogicUser getUserId() {
return userId;
}
/**
* @param userId the userId to set
*/
public void setUserId(VipsLogicUser userId) {
this.userId = userId;
}
} }
...@@ -45,7 +45,8 @@ import org.codehaus.jackson.annotate.JsonIgnore; ...@@ -45,7 +45,8 @@ import org.codehaus.jackson.annotate.JsonIgnore;
@NamedQueries({ @NamedQueries({
@NamedQuery(name = "PointOfInterestWeatherStation.findAll", query = "SELECT p FROM PointOfInterest p WHERE p.pointOfInterestType.pointOfInterestTypeId=1"), @NamedQuery(name = "PointOfInterestWeatherStation.findAll", query = "SELECT p FROM PointOfInterest p WHERE p.pointOfInterestType.pointOfInterestTypeId=1"),
@NamedQuery(name = "PointOfInterestWeatherStation.findByPointOfInterestId", query = "SELECT p FROM PointOfInterest p WHERE p.pointOfInterestId = :pointOfInterestId AND p.pointOfInterestType.pointOfInterestTypeId=1"), @NamedQuery(name = "PointOfInterestWeatherStation.findByPointOfInterestId", query = "SELECT p FROM PointOfInterest p WHERE p.pointOfInterestId = :pointOfInterestId AND p.pointOfInterestType.pointOfInterestTypeId=1"),
@NamedQuery(name = "PointOfInterestWeatherStation.findByUserId", query = "SELECT p FROM PointOfInterest p WHERE p.pointOfInterestType.pointOfInterestTypeId=1 AND p.pointOfInterestId IN(SELECT up.pointOfInterest.pointOfInterestId FROM UserPointOfInterest up WHERE up.userPointOfInterestPK.userId = :userId)") @NamedQuery(name = "PointOfInterestWeatherStation.findByOrganizationId", query = "SELECT p FROM PointOfInterestWeatherStation p WHERE p.pointOfInterestType.pointOfInterestTypeId=1 AND p.userId IN(SELECT u.userId FROM VipsLogicUser u WHERE u.organizationId=:organizationId)"),
@NamedQuery(name = "PointOfInterestWeatherStation.findByUserId", query = "SELECT p FROM PointOfInterestWeatherStation p WHERE p.pointOfInterestType.pointOfInterestTypeId=1 AND p.userId = :userId")
}) })
public class PointOfInterestWeatherStation extends PointOfInterest implements Serializable { public class PointOfInterestWeatherStation extends PointOfInterest implements Serializable {
@Size(max = 255) @Size(max = 255)
......
...@@ -170,6 +170,15 @@ public class LogicService { ...@@ -170,6 +170,15 @@ public class LogicService {
return Response.ok().entity(latestResults).build(); return Response.ok().entity(latestResults).build();
} }
@GET
@Path("weatherstations/kml/{organizationId}")
@Produces("application/vnd.google-earth.kml+xml;charset=utf-8")
public Response getWeatherStations(@QueryParam("excludeWeatherStationId") Integer excludeWeatherStationId, @QueryParam("highlightWeatherStationId") Integer highlightWeatherStationId, @PathParam("organizationId") Integer organizationId)
{
Kml retVal = SessionControllerGetter.getPointOfInterestBean().getWeatherstationsForOrganization(organizationId, excludeWeatherStationId, highlightWeatherStationId, ServletUtil.getServerName(httpServletRequest), SessionLocaleUtil.getI18nBundle(httpServletRequest));
return Response.ok().entity(retVal).build();
}
@GET @GET
@Path("organism/list") @Path("organism/list")
@Produces("application/json;charset=UTF-8") @Produces("application/json;charset=UTF-8")
......
...@@ -210,3 +210,9 @@ informAdminOfConfirmedEmailSubject=New user has confirmed email and is now ready ...@@ -210,3 +210,9 @@ informAdminOfConfirmedEmailSubject=New user has confirmed email and is now ready
informAdminOfConfirmedEmailBody=The user''s last name is {0}. Follow this link to edit this user: {1} informAdminOfConfirmedEmailBody=The user''s last name is {0}. Follow this link to edit this user: {1}
sendUserApprovalConfirmationSubject=Your user account has been approved sendUserApprovalConfirmationSubject=Your user account has been approved
sendUserApprovalConfirmationBody=We are happy to confirm that your user account for VIPSLogic has been approved. Please log in here: {0} sendUserApprovalConfirmationBody=We are happy to confirm that your user account for VIPSLogic has been approved. Please log in here: {0}
dataSourceName=Data source name
newWeatherStation=New weather station
meter=Meter
country=Country
editWeatherStation=Edit weather station
toTheTop=To the top
...@@ -210,3 +210,9 @@ informAdminOfConfirmedEmailSubject=Ny bruker har bekreftet sin e-postadresse og ...@@ -210,3 +210,9 @@ informAdminOfConfirmedEmailSubject=Ny bruker har bekreftet sin e-postadresse og
informAdminOfConfirmedEmailBody=Brukerens etternavn er {0}. F\u00f8lg denne lenken for \u00e5 redigere/godkjenne: {1} informAdminOfConfirmedEmailBody=Brukerens etternavn er {0}. F\u00f8lg denne lenken for \u00e5 redigere/godkjenne: {1}
sendUserApprovalConfirmationSubject=Din brukerkonto har blitt godkjent sendUserApprovalConfirmationSubject=Din brukerkonto har blitt godkjent
sendUserApprovalConfirmationBody=Vi har gleden av \u00e5 bekrefte at din brukerkonto hos VIPSLogic er blitt godkjent. Vennligst logg in her: {0} sendUserApprovalConfirmationBody=Vi har gleden av \u00e5 bekrefte at din brukerkonto hos VIPSLogic er blitt godkjent. Vennligst logg in her: {0}
dataSourceName=Datakildenavn
newWeatherStation=Ny m\u00e5lestasjon
meter=Meter
country=Land
editWeatherStation=Rediger m\u00e5lestasjon
toTheTop=Helt til topps
...@@ -70,7 +70,7 @@ legend { ...@@ -70,7 +70,7 @@ legend {
display: block; display: block;
} }
#observationFormMap{ #observationFormMap, #weatherStationListMap, #weatherStationFormMap, #weatherStationViewMap{
height: 400px; height: 400px;
width: 100%; width: 100%;
} }
\ No newline at end of file
{
"_licenseNote": [
"Copyright (c) 2014 Bioforsk <http://www.bioforsk.no/>.",
"",
"This file is part of VIPSLogic.",
"VIPSLogic is free software: you can redistribute it and/or modify",
"it under the terms of the GNU Affero General Public License as published by",
"the Free Software Foundation, either version 3 of the License, or",
"(at your option) any later version.",
"",
"VIPSLogic is distributed in the hope that it will be useful,",
"but WITHOUT ANY WARRANTY; without even the implied warranty of",
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the",
"GNU Affero General Public License for more details.",
"",
"You should have received a copy of the GNU Affero General Public License",
"along with VIPSLogic. If not, see <http://www.gnu.org/licenses/>."
],
"_comment" : "Structure of the weatherStationForm and how to validate it",
"fields": [
{
"name" : "pointOfInterestId",
"dataType" : "INTEGER",
"required" : true
},
{
"name" : "name",
"dataType" : "STRING",
"required" : true
},
{
"name" : "weatherStationDataSourceId",
"dataType" : "INTEGER",
"fieldType" : "SELECT_SINGLE",
"required" : true,
"nullValue" : "-1"
},
{
"name" : "weatherStationRemoteId",
"dataType" : "STRING",
"required" : true
},
{
"name" : "location",
"dataType" : "POINT_WGS84",
"required" : true
},
{
"name" : "altitude",
"dataType" : "DOUBLE",
"required" : false
},
{
"name" : "timeZone",
"dataType" : "STRING",
"fieldType" : "SELECT_SINGLE",
"required" : true
},
{
"name" : "countryCode",
"dataType" : "STRING",
"fieldType" : "SELECT_SINGLE",
"required" : true
},
{
"name" : "userId",
"dataType" : "INTEGER",
"required" : false
}
]
}
/*
* Copyright (c) 2014 Bioforsk <http://www.bioforsk.no/>.
*
* This file is part of VIPSLogic.
* VIPSLogic is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VIPSLogic is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with VIPSLogic. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Constants for maps
*/
var mapConstants = {
// The attribution shown in the corner of the map
MAP_ATTRIBUTION : "&copy; <a href='http://www.openstreetmap.org'>OpenStreetMap</a> contributors"
};
\ No newline at end of file
...@@ -32,7 +32,13 @@ function initMap(center, zoomLevel, displayMarker) ...@@ -32,7 +32,13 @@ function initMap(center, zoomLevel, displayMarker)
{ {
// Background layer is OpenStreetMap // Background layer is OpenStreetMap
var backgroundLayer = new ol.layer.Tile({ var backgroundLayer = new ol.layer.Tile({
source: new ol.source.OSM() source: new ol.source.OSM({
attributions: [
new ol.Attribution({
html: mapConstants.MAP_ATTRIBUTION
})
]
})
}); });
......
...@@ -188,12 +188,12 @@ function validateField(fieldEl, formDefinitionKey) ...@@ -188,12 +188,12 @@ function validateField(fieldEl, formDefinitionKey)
$.getJSON( "/formdefinitions/" + theForm.id + ".json") $.getJSON( "/formdefinitions/" + theForm.id + ".json")
.done(function(json){ .done(function(json){
formDefinitions[theForm.id] = json; formDefinitions[theForm.id] = json;
validateFieldActual(fieldEl, theForm, formDefinitionKey); return validateFieldActual(fieldEl, theForm, formDefinitionKey);
}); });
} }
else else
{ {
validateFieldActual(fieldEl, theForm, formDefinitionKey); return validateFieldActual(fieldEl, theForm, formDefinitionKey);
} }
} }
...@@ -231,7 +231,7 @@ function getValidationOutputEl(fieldEl, theForm) ...@@ -231,7 +231,7 @@ function getValidationOutputEl(fieldEl, theForm)
* @param {Element} fieldEl the form element to be validated * @param {Element} fieldEl the form element to be validated
* @param {Element} theForm the form * @param {Element} theForm the form
* @param {String} formDefinitionKey optional key to a formdefinition for a part of the form that has been dynamically added to the main form * @param {String} formDefinitionKey optional key to a formdefinition for a part of the form that has been dynamically added to the main form
* @returns {void} * @returns {boolean}
*/ */
function validateFieldActual(fieldEl, theForm, formDefinitionKey) function validateFieldActual(fieldEl, theForm, formDefinitionKey)
{ {
......
/*
* Copyright (c) 2014 Bioforsk <http://www.bioforsk.no/>.
*
* This file is part of VIPSLogic.
* VIPSLogic is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VIPSLogic is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with VIPSLogic. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* KML layer map with weather station information
* @author Tor-Einar Skog <tor-einar.skog@bioforsk.no>
*/
// Keeping the map and station marker globally available
var map;
var stationMarker;
/**
*
* @param {ol.Coordinate} center - coordinates for the map's center (WGS84)
* @param {int} zoomLevel - the zoom level (1-15, 1 is world wide view, 15 is greatest zoom)
* * @param {int} currentWeatherStationId - the current weather station id
* @returns {void}
*/
function initMap(center, zoomLevel, currentWeatherStationId)
{
// Background layer is OpenStreetMap
var backgroundLayer = new ol.layer.Tile({
source: new ol.source.OSM({
attributions: [
new ol.Attribution({
html: mapConstants.MAP_ATTRIBUTION
})
]
})
});
// The weather station layer
var weatherStationLayer = new ol.layer.Vector({
source: new ol.source.KML({
url: "/rest/weatherstations/kml/2" + (currentWeatherStationId > 0 ? "?excludeWeatherStationId=" + currentWeatherStationId : ""),
projection: "EPSG:3857"
})
});
// Layer for popup
var popOverlay = new ol.Overlay({
element: document.getElementById("popover")
});
// Creating the map
map = new ol.Map({
target: 'weatherStationFormMap',
layers: [backgroundLayer,weatherStationLayer],
overlays: [popOverlay],
renderer: 'canvas'
});
var centerPosition = ol.proj.transform(center, 'EPSG:4326', map.getView().getProjection().getCode());
// 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({
center: centerPosition,
zoom:zoomLevel
});
map.setView(view);
// Marker overlay
stationMarker = new ol.Overlay({
position: currentWeatherStationId !== null ? centerPosition : undefined,
positioning: 'bottom-center',
element: document.getElementById('stationMarker'),
stopEvent: false
});
map.addOverlay(stationMarker);
// Listening for single clicks, position observation pin and updating form element
map.on(['singleclick'], function(evt) {
updateLocationPosition(evt.coordinate);
});
}
function updateLocationPosition(coordinate)
{
var locationPosition = ol.coordinate.toStringXY(ol.proj.transform(coordinate, map.getView().getProjection().getCode(), 'EPSG:4326'),4);
// Set/move location pin
stationMarker.setPosition(coordinate);
// Update form field "location"
var locationEl = document.getElementById("location");
//console.log(locationEl);
locationEl.value=locationPosition;
// Adding a little animation
$("#location").animate({borderWidth: "4"},500, function(){
$("#location").animate({borderWidth: "1"},500, function(){});
});
}
/**
* Places the station marker on the coordinates given in Location input field,
* and centers the map around these coordinates
*/
function updateMarkerPosition()
{
var locationEl = document.getElementById("location");
var coordinate = locationEl.value.split(",");
coordinate[0] = parseFloat(coordinate[0]);
coordinate[1] = parseFloat(coordinate[1]);
//console.log(coordinate);
var centerPosition = ol.proj.transform(coordinate, 'EPSG:4326', map.getView().getProjection().getCode());
stationMarker.setPosition(centerPosition);
// 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({
center: centerPosition,
zoom:10
});
map.setView(view);
}
/*
* Copyright (c) 2014 Bioforsk <http://www.bioforsk.no/>.
*
* This file is part of VIPSLogic.
* VIPSLogic is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VIPSLogic is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with VIPSLogic. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* KML layer map with weather station information
* @author Tor-Einar Skog <tor-einar.skog@bioforsk.no>
*/
/**
*
* @param {ol.Coordinate} center - coordinates for the map's center (WGS84)
* @param {int} zoomLevel - the zoom level (1-15, 1 is world wide view, 15 is greatest zoom)
* @returns {void}
*/
function initMap(center, zoomLevel)
{
// Background layer is OpenStreetMap
var backgroundLayer = new ol.layer.Tile({
source: new ol.source.OSM({
attributions: [
new ol.Attribution({
html: mapConstants.MAP_ATTRIBUTION
})
]
})
});
// The weather station layer
var weatherStationLayer = new ol.layer.Vector({
source: new ol.source.KML({
url: "/rest/weatherstations/kml/2",
projection: "EPSG:3857"
})
});
// Layer for popup
var popOverlay = new ol.Overlay({
element: document.getElementById("popover")
});
// Creating the map
var map = new ol.Map({
target: 'weatherStationListMap',
layers: [backgroundLayer,weatherStationLayer],
overlays: [popOverlay],
renderer: 'canvas'
});
var centerPosition = ol.proj.transform(center, 'EPSG:4326', map.getView().getProjection().getCode());
// 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({
center: centerPosition,
zoom:zoomLevel
});
map.setView(view);
// Using Bootstrap's popover plugin. See http://getbootstrap.com/javascript/#popovers
var poiDetails = $("#popover");
// Displays popup with forecasts for a given station
// (if there is a station where the click event is fired)
var displayFeatureDetails = function(pixel, coordinate) {
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());
poiDetails.popover('destroy');
// Create the popup, showing it
poiDetails.popover({
animation: true,
trigger: 'manual',
html: true,
placement: "auto top",
title: "<a href='/weatherStation?pointOfInterestId=" + feature.getId() + "'>" + feature.get("name") + "</a>",
content: feature.get("description")
});
poiDetails.popover('show');
} else {
poiDetails.popover('destroy');
}
};
// On click, display forecasts in popup
map.on('singleclick', function(evt) {
var pixel = map.getEventPixel(evt.originalEvent);
displayFeatureDetails(pixel);
});
}
/*
* Copyright (c) 2014 Bioforsk <http://www.bioforsk.no/>.
*
* This file is part of VIPSLogic.
* VIPSLogic is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VIPSLogic is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with VIPSLogic. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* KML layer map with weather station information
* @author Tor-Einar Skog <tor-einar.skog@bioforsk.no>
*/
/**
*
* @param {ol.Coordinate} center - coordinates for the map's center (WGS84)
* @param {int} zoomLevel - the zoom level (1-15, 1 is world wide view, 15 is greatest zoom)
* @returns {void}
*/
function initMap(center, zoomLevel, highlightWeatherStationId)
{
// Background layer is OpenStreetMap
var backgroundLayer = new ol.layer.Tile({
source: new ol.source.OSM({
attributions: [
new ol.Attribution({
html: mapConstants.MAP_ATTRIBUTION
})
]
})
});
// The weather station layer
var weatherStationLayer = new ol.layer.Vector({
source: new ol.source.KML({
url: "/rest/weatherstations/kml/2" + (highlightWeatherStationId !== null ? "?highlightWeatherStationId=" + highlightWeatherStationId : ""),
projection: "EPSG:3857"
})
});
// Layer for popup
var popOverlay = new ol.Overlay({
element: document.getElementById("popover")
});
// Creating the map
var map = new ol.Map({
target: 'weatherStationViewMap',
layers: [backgroundLayer,weatherStationLayer],
overlays: [popOverlay],
renderer: 'canvas'
});
var centerPosition = ol.proj.transform(center, 'EPSG:4326', map.getView().getProjection().getCode());
// 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({
center: centerPosition,
zoom:zoomLevel
});
map.setView(view);
// Using Bootstrap's popover plugin. See http://getbootstrap.com/javascript/#popovers
var poiDetails = $("#popover");
// Displays popup with forecasts for a given station
// (if there is a station where the click event is fired)
var displayFeatureDetails = function(pixel, coordinate) {
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());
poiDetails.popover('destroy');
// Create the popup, showing it
poiDetails.popover({
animation: true,
trigger: 'manual',
html: true,
placement: "auto top",
title: "<a href='/weatherStation?pointOfInterestId=" + feature.getId() + "'>" + feature.get("name") + "</a>",
content: feature.get("description")
});
poiDetails.popover('show');
} else {
poiDetails.popover('destroy');
}
};
// On click, display forecasts in popup
map.on('singleclick', function(evt) {
var pixel = map.getEventPixel(evt.originalEvent);
displayFeatureDetails(pixel);
});
}
src/main/webapp/public/images/anemometer_mono.png

1.22 KiB

...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
</script> </script>
</#macro> </#macro>
<#macro page_contents> <#macro page_contents>
<p><a href="/forecastConfiguration" class="btn btn-default back" role="button">${i18nBundle.back}</a></p>
<h1>${i18nBundle.viewForecastConfiguration}</h1> <h1>${i18nBundle.viewForecastConfiguration}</h1>
<div id="errorMsgEl" class="alert alert-danger" <#if !formValidation?has_content> style="display:none;"</#if>> <div id="errorMsgEl" class="alert alert-danger" <#if !formValidation?has_content> style="display:none;"</#if>>
<#if formValidation?has_content>${formValidation.validationMessages?replace("\n", "<br>")}</#if> <#if formValidation?has_content>${formValidation.validationMessages?replace("\n", "<br>")}</#if>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment