Commit 59b2d25d authored by Matija Obreza's avatar Matija Obreza
Browse files

Selected accessions displayed on map

parent 4b0b492d
......@@ -16,12 +16,19 @@
package org.genesys2.server.persistence.domain;
import java.util.List;
import java.util.Set;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface AccessionGeoRepository extends JpaRepository<AccessionGeo, Long> {
AccessionGeo findByAccession(Accession accession);
@Query("select ag from AccessionGeo ag join fetch ag.accession a where a.id in ?1")
List<AccessionGeo> findForAccessions(Set<Long> accessionIds);
}
......@@ -153,4 +153,6 @@ public interface GenesysService {
void removeAliases(Set<Long> toRemove);
List<AccessionGeo> listAccessionsGeo(Set<Long> copy);
}
......@@ -239,6 +239,12 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
return null;
return accessionGeoRepository.findByAccession(accession);
}
@Override
public List<AccessionGeo> listAccessionsGeo(Set<Long> copy) {
if (copy==null || copy.isEmpty()) return null;
return accessionGeoRepository.findForAccessions(copy);
}
@Override
public SvalbardData getSvalbardData(Accession accession) {
......
......@@ -16,7 +16,11 @@
package org.genesys2.server.servlet.controller;
import java.util.ArrayList;
import java.util.List;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.service.GenesysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
......@@ -53,6 +57,12 @@ public class SelectionController extends BaseController {
return "/selection/index";
}
@RequestMapping(value = "/map")
public String map(ModelMap model) {
model.addAttribute("selection", selectionBean);
return "/selection/map";
}
@RequestMapping(value = "/order")
public String order(ModelMap model) {
return "redirect:/request";
......@@ -93,6 +103,22 @@ public class SelectionController extends BaseController {
return "redirect:/sel/";
}
@RequestMapping(value = "/json/geo", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
@ResponseBody
public List<AccessionGeoJson> selectionGeo() {
List<AccessionGeoJson> geo = new ArrayList<AccessionGeoJson>();
for (AccessionGeo acnGeo : genesysService.listAccessionsGeo(selectionBean.copy())) {
AccessionGeoJson g = new AccessionGeoJson();
g.id = acnGeo.getAccession().getId();
g.lat = acnGeo.getLatitude();
g.lng = acnGeo.getLongitude();
g.accessionName = acnGeo.getAccession().getAccessionName();
g.instCode = acnGeo.getAccession().getInstituteCode();
geo.add(g);
}
return geo;
}
@RequestMapping(value = "/json", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE })
@ResponseBody
public JsonResponse jsonOp(@RequestBody JsonAction action) {
......@@ -118,4 +144,12 @@ public class SelectionController extends BaseController {
public int count;
public boolean included;
}
public static class AccessionGeoJson {
public long id;
public Double lat;
public Double lng;
public String accessionName;
public String instCode;
}
}
......@@ -66,6 +66,7 @@ public class UserControllerAdvice extends BaseController {
@ExceptionHandler(value = { Throwable.class })
// @ResponseBody
public ModelAndView handleAll(Throwable e) {
_logger.error(e.getMessage(), e);
ModelAndView mav = new ModelAndView("/errors/error");
mav.addObject("exception", e);
return mav;
......
......@@ -66,6 +66,7 @@
<a href="<c:url value="/sel/" />"><button class="btn" type="button">Refresh</button></a>
<button class="btn btn-primary" type="submit">Send request for germplasm</button>
<a href="<c:url value="/sel/clear" />"><button class="btn" type="button">Clear list</button></a>
<a href="<c:url value="/sel/map" />"><button class="btn" type="button">Display on map</button></a>
</div>
</form>
......
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<html>
<head>
<title><spring:message code="selection.page.title" /></title>
</head>
<body>
<h1>
<spring:message code="selection.page.title" />
</h1>
<div class="row" style="">
<div class="col-sm-12">
<div id="map" class="gis-map gis-map-square"><spring:message code="maps.loading-map" /></div>
</div>
</div>
<content tag="javascript">
<script type="text/javascript">
jQuery(document).ready(function() {
var map = GoogleMaps.map("${pageContext.response.locale.language}", $("#map"), {
center: new GoogleMaps.LatLng(0, 0)
}, function(el, map) {
var infowindow = new google.maps.InfoWindow({
content: "",
maxWidth: 500
});
$.ajax('<c:url value="/sel/json/geo" />', {
type : 'get',
dataType : 'json',
success : function(respObject) {
respObject.forEach(function(acn) {
var m=new google.maps.Marker({
position: new google.maps.LatLng(acn.lat, acn.lng),
title: acn.accessionName,
map: map
});
});
map.fitBounds(GoogleMaps.boundingBox(respObject));
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus);
console.log(errorThrown);
}
});
});
});
</script>
</content>
</body>
</html>
\ No newline at end of file
......@@ -1797,6 +1797,10 @@ html[dir="rtl"] ul.statistics .stats-number {
margin-top: 1em;
}
.gis-map-square {
height: 600px;
}
.audit-info {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment