Commit 3babf724 authored by Matija Obreza's avatar Matija Obreza
Browse files

Download KML from /explore/map

parent df356f9b
......@@ -340,9 +340,17 @@ public class ExplorerController extends BaseController {
public String map(ModelMap model, @RequestParam(value = "crop", required = false, defaultValue = "") String cropName,
@RequestParam(value = "filter", required = false, defaultValue = "{}") String jsonFilter) {
Crop crop = null;
if (StringUtils.isNotBlank(cropName)) {
crop = cropService.getCrop(cropName);
if (crop == null) {
throw new ResourceNotFoundException("No crop " + cropName);
}
}
ObjectNode jsonTree = updateFilterWithCrop(cropName, jsonFilter);
model.addAttribute("jsonFilter", jsonTree.toString());
model.addAttribute("crop", crop);
return "/accession/map";
}
......@@ -396,11 +404,15 @@ public class ExplorerController extends BaseController {
return jsonTree;
}
@RequestMapping(value = "/explore/kml", produces = "application/vnd.google-earth.kml+xml")
@RequestMapping(value = "/explore/kml", produces = "application/vnd.google-earth.kml+xml", method = RequestMethod.POST)
@ResponseBody
public String kml(@RequestParam(value = "crop", required = false, defaultValue = "") String cropName,
@RequestParam(value = "filter", required = true) String jsonFilter) {
@RequestParam(value = "filter", required = true) String jsonFilter, HttpServletResponse response) {
ObjectNode jsonTree = updateFilterWithCrop(cropName, jsonFilter);
response.setContentType("application/vnd.google-earth.kml+xml");
response.addHeader("Content-Disposition", String.format("attachment; filename=\"genesys-kml-filtered.kml\""));
return mappingService.filteredKml(jsonTree.toString());
}
......
......@@ -496,3 +496,5 @@ article.classPk=Object
session.expiry-warning-title=Session expiration warning
session.expiry-warning=Your current session is about to expire. Do you wish to extend this session?
session.expiry-extend=Extend session
download.kml=Download KML
......@@ -11,10 +11,26 @@
<spring:message code="maps.accession-map" />
</h1>
<div class="main-col-header">
<a href="javascript: window.history.go(-1);"><spring:message code="navigate.back" /></a>
<a class="" href="<c:url value="/explore" />" id="selectArea">View accessions</a>
<div class="main-col-header clearfix">
<div class="nav-header">
<form class="pull-right form-horizontal" method="post" action="/explore/kml">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<input type="hidden" name="crop" value="${crop.shortName}" />
<input type="hidden" name="filter" value="<c:out value="${jsonFilter}" />" />
<div class="row">
<div class="col-sm-4">
<button class="btn btn-default" type="submit"><spring:message code="download.kml" /></button>
</div>
</div>
</form>
<div class="results">
<a href="javascript: window.history.go(-1);"><spring:message code="navigate.back" /></a>
<a class="" href="<c:url value="/explore" />" id="selectArea">View accessions</a>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div id="map" class="gis-map gis-map-square"></div>
......
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