Commit b25083b9 authored by Matija Obreza's avatar Matija Obreza
Browse files

Include crop parameter in maps

parent b46d8004
......@@ -335,14 +335,43 @@ public class ExplorerController extends BaseController {
}
@RequestMapping(value = "/explore/map", method = RequestMethod.GET)
public String map(ModelMap model, @RequestParam(value = "filter", required = true) String jsonFilter) {
model.addAttribute("jsonFilter", jsonFilter);
public String map(ModelMap model, @RequestParam(value = "crop", required = false, defaultValue = "") String cropName,
@RequestParam(value = "filter", required = true) String jsonFilter) {
Crop crop = null;
if (StringUtils.isNotBlank(cropName)) {
crop = cropService.getCrop(cropName);
if (crop == null) {
throw new ResourceNotFoundException("No crop " + cropName);
}
}
ObjectNode jsonTree = null;
try {
jsonTree = (ObjectNode) mapper.readTree(jsonFilter);
_logger.debug(jsonTree.toString());
if (crop != null) {
jsonTree.remove("crop");
// Replace any other crop filters...
ArrayNode oneCrop = jsonTree.arrayNode();
oneCrop.add(crop.getShortName());
jsonTree.put("crop", oneCrop);
}
} catch (IOException e) {
_logger.error(e.getMessage(), e);
}
model.addAttribute("jsonFilter", jsonTree.toString());
return "/accession/map";
}
@RequestMapping(value = "/explore/kml", produces = "application/vnd.google-earth.kml+xml")
@ResponseBody
public String kml(@RequestParam(value = "filter", required = true) String jsonFilter) {
public String kml(@RequestParam(value = "crop", required = false, defaultValue = "") String cropName,
@RequestParam(value = "filter", required = true) String jsonFilter) {
return mappingService.filteredKml(jsonFilter);
}
......
......@@ -14,7 +14,7 @@
<div class="main-col-header clearfix">
<div class="nav-header pull-left">
<div class="results"><spring:message code="accessions.number" arguments="${pagedData.totalElements}" />
<a href="<c:url value="/explore/map"><c:param name="filter">${jsonFilter}</c:param></c:url>">Map</a></div>
<a href="<c:url value="/explore/map"><c:param name="crop" value="${crop.shortName}" /><c:param name="filter">${jsonFilter}</c:param></c:url>">Map</a></div>
<div class="pagination">
<spring:message code="paged.pageOfPages" arguments="${pagedData.number+1},${pagedData.totalPages}" />
<a href="<spring:url value=""><spring:param name="page" value="${pagedData.number eq 0 ? 1 : pagedData.number}" /><spring:param name="filter" value="${jsonFilter}" /><spring:param name="pick" value="${jsonPick}" /></spring:url>"><spring:message code="pagination.previous-page" /></a>
......
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