Commit 1115a13a authored by Maxym Borodenko's avatar Maxym Borodenko
Browse files

Auto-center accessions map

parent 31e8a7d3
......@@ -41,4 +41,6 @@ public interface GenesysFilterService {
void listGeoTile(boolean distinct, AppliedFilters filters, Integer limit, int zoom, int xtile, int ytile, RowCallbackHandler rowHandler);
void listGeoForBoundingBox(AppliedFilters filters, RowCallbackHandler rowHandler);
}
......@@ -68,6 +68,15 @@ public interface MappingService {
*/
byte[] getTile(AppliedFilters filters, int zoom, int xtile, int ytile);
/**
* Gets coordinates of bounding box
*
* @param filters
* the filters
* @return coordinates
*/
String getBoundingBox(AppliedFilters filters);
/**
* Coordinate utilities
*/
......
......@@ -426,4 +426,28 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
}, rowHandler);
}
@Override
public void listGeoForBoundingBox(final AppliedFilters filters, final RowCallbackHandler rowHandler) {
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accessiongeo", "geo");
if (!filters.isEmpty()) {
// Join accession table when we have filters or looking at details
directQuery.innerJoin("accession", "a", "a.id=geo.accessionId");
}
if (!filters.isEmpty()) {
directQuery.join(filters);
directQuery.filter(filters, methodId -> methodRepository.findOne(methodId));
}
this.jdbcTemplate.query(connection -> {
final PreparedStatement stmt = connection.prepareStatement(
directQuery.getQuery("Max(geo.longitude), Min(geo.longitude), Max(geo.latitude), Min(geo.latitude)"));
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
new ArgumentPreparedStatementSetter(directQuery.getParameters()).setValues(stmt);
return stmt;
}, rowHandler);
}
}
......@@ -222,4 +222,19 @@ public class MappingServiceImpl implements MappingService {
throw new RuntimeException("Could not render image", e);
}
}
public String getBoundingBox(final AppliedFilters filters) {
final String[] result = {""};
filterService.listGeoForBoundingBox(filters, resultSet -> {
final ObjectNode geoJson = mapper.createObjectNode();
geoJson.put("west", String.valueOf(resultSet.getDouble("Min(geo.latitude)")));
geoJson.put("south", String.valueOf(resultSet.getDouble("Min(geo.longitude)")));
geoJson.put("east", String.valueOf(resultSet.getDouble("Max(geo.latitude)")));
geoJson.put("north", String.valueOf(resultSet.getDouble("Max(geo.longitude)")));
result[0] = geoJson.toString();
});
return result[0];
}
}
......@@ -806,6 +806,14 @@ public class ExplorerController extends BaseController implements InitializingBe
return mappingService.filteredGeoJson(appliedFilters, limit);
}
@RequestMapping(value = "/explore/bounding-box", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public String getBoundingBox(@RequestParam(value = "filter", required = true) String jsonFilter) throws IOException {
AppliedFilters appliedFilters = mapper.readValue(jsonFilter, AppliedFilters.class);
return mappingService.getBoundingBox(appliedFilters);
}
@RequestMapping(value = "/explore/tile/{zoom}/{x}/{y}", produces = MediaType.IMAGE_PNG_VALUE)
public void tile(
@PathVariable("zoom") int zoom,
......
......@@ -3244,9 +3244,6 @@ table.accessions {
.map-container {
position: relative;
}
#map {
height: 1200px;
}
.filters {
overflow-y: auto;
}
......
......@@ -183,58 +183,32 @@
</div>
<content tag="javascript">
<script>
function setHeight(isClosed) {
if ($(window).innerWidth() > 960) {
$('.filters').css('height', 'auto');
console.log('auto');
var windowHeight = $(window).innerHeight();
var offsetMap = $('#map').offset().top;
var offsetFilters = $('.filters').offset().top;
$('#map').css('height', windowHeight - offsetMap, +'px');
<script type="text/javascript">
var jsonData = ${jsonFilter};
localStorage.setItem("historyStep", 1);
var mapProviders = getMapProviders();
var cookieUtils = getCookieUtils();
var map = null;
var layer = null;
if(typeof isClosed == 'undefined'){
isClosed = !$('#collapseFilters').hasClass('in')
}
$(document).ready(function () {
if($('#collapseFilters').hasClass('in') || !isClosed) {
$('.filters').css('height', windowHeight - offsetFilters, +'px');
console.log('height');
}
}
else {
$(".filters").css('height', 'auto');
$('#map').css('height', 600, +'px');
}
}
$(document).ready(function() {
setHeight();
map = L.map('map').setView([30, 0], 3);
$(window).resize(function() {
console.log("resize");
setHeight();
});
$(document).on('click', 'a[href*=#collapseFilters]', function() {
$(this).toggleClass('closed');
setHeight($(this).hasClass('closed'));
});
});
</script>
<script type="text/javascript">
var jsonData = ${jsonFilter};
localStorage.setItem("historyStep", 1);
var mapProviders = getMapProviders();
var cookieUtils = getCookieUtils();
var map = L.map('map').setView([30, 0], 3);
var layer = null;
if(JSON.stringify(jsonData) !== "{}") {
centerMap();
}
$(document).ready(function () {
BrowseUtil.applySuggestions(jsonData, messages);
$("#panel_additional_id").hide();
......@@ -693,6 +667,30 @@
});
});
function setHeight(isClosed) {
if ($(window).innerWidth() > 960) {
$('.filters').css('height', 'auto');
var windowHeight = $(window).innerHeight();
var offsetMap = $('#map').offset().top;
var offsetFilters = $('.filters').offset().top;
$('#map').css('height', windowHeight - offsetMap, +'px');
if(typeof isClosed == 'undefined'){
isClosed = !$('#collapseFilters').hasClass('in')
}
if($('#collapseFilters').hasClass('in') || !isClosed) {
$('.filters').css('height', windowHeight - offsetFilters, +'px');
}
}
else {
$(".filters").css('height', 'auto');
$('#map').css('height', 600, +'px');
}
}
function isExistAdditionalFilters() {
for(var filter in jsonData) {
if(filter.toString().startsWith("gm:")) {
......@@ -805,9 +803,37 @@
function refreshData() {
reloadTiles();
if(JSON.stringify(jsonData) !== "{}") {
centerMap();
}
refreshLinks();
}
function centerMap() {
$.ajax("<c:url value="/explore/bounding-box"/>", {
type: 'GET',
data: "filter=" + JSON.stringify(jsonData),
success: function (respObject) {
var west = respObject.west;
var south = respObject.south;
var east = respObject.east;
var north = respObject.north;
if (west == 0 && south == 0 && east == 0 && north == 0)
return;
var bounds = new GenesysMaps.BoundingBox();
bounds.add([west, south]);
bounds.add([east, north]);
map.fitBounds(bounds.getBounds());
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(textStatus);
console.log(errorThrown);
}
});
}
function applyFilters() {
var stepValue = (parseInt(localStorage.getItem("historyStep")) + 1);
localStorage.setItem("historyStep", stepValue);
......
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