public void applyAndSync( Bbox bounds, TileFunction<RasterTile> onDelete, TileFunction<RasterTile> onUpdate) { MapViewState viewState = rasterLayer.getMapModel().getMapView().getViewState(); boolean panning = lastViewState == null || viewState.isPannableFrom(lastViewState); if (!panning || isDirty()) { for (RasterTile tile : tiles.values()) { onDelete.execute(tile); } tiles.clear(); tileBounds = null; dirty = false; } lastViewState = rasterLayer.getMapModel().getMapView().getViewState(); if (tileBounds == null || !tileBounds.contains(bounds)) { fetchAndUpdateTiles(bounds, onUpdate); } else { updateTiles(bounds, onUpdate); } }
private void fetchAndUpdateTiles(Bbox bounds, final TileFunction<RasterTile> onUpdate) { // fetch a bigger area to avoid server requests while panning tileBounds = bounds.scale(3); // Calculate tiles // double scale = lastViewState.getScale(); // addTiles(rasterLayer.getTiles(tileBounds, scale > 1 ? scale : 1 / scale)); addTiles(rasterLayer.getTiles(tileBounds, 1 / lastViewState.getScale())); Bbox panBounds = worldToPan(bounds); // for each tile: for (RasterTile tile : tiles.values()) { if (panBounds.intersects(tile.getBounds())) { onUpdate.execute(tile); } } }