Skip to content

Commit

Permalink
#7792 Make tile server used for map configurable (#7963)
Browse files Browse the repository at this point in the history
  • Loading branch information
leventegal-she committed Feb 17, 2022
1 parent 25098dd commit ee97977
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
Expand Up @@ -100,6 +100,10 @@ public interface ConfigFacade {

boolean isMapUseCountryCenter();

String getMapTilersUrl();

String getMapTilersAttribution();

int getMapZoom();

String getGeocodingServiceUrlTemplate();
Expand Down
Expand Up @@ -64,6 +64,8 @@ public class ConfigFacadeEjb implements ConfigFacade {
private static final String COUNTRY_CENTER_LAT = "country.center.latitude";
private static final String COUNTRY_CENTER_LON = "country.center.longitude";
private static final String MAP_USE_COUNTRY_CENTER = "map.usecountrycenter";
private static final String MAP_TILES_URL = "map.tiles.url";
private static final String MAP_TILES_ATTRIBUTION = "map.tiles.attribution";
private static final String MAP_ZOOM = "map.zoom";

public static final String VERSION_PLACEHOLER = "%version";
Expand Down Expand Up @@ -291,6 +293,16 @@ public boolean isMapUseCountryCenter() {
return getBoolean(MAP_USE_COUNTRY_CENTER, false);
}

@Override
public String getMapTilersUrl() {
return getProperty(MAP_TILES_URL, null);
}

@Override
public String getMapTilersAttribution() {
return getProperty(MAP_TILES_ATTRIBUTION, null);
}

@Override
public int getMapZoom() {
return getInt(MAP_ZOOM, 1);
Expand Down
7 changes: 7 additions & 0 deletions sormas-base/setup/sormas.properties
Expand Up @@ -50,6 +50,13 @@ country.center.longitude=0
# Default: 1
#map.zoom=1

# Tileset of the map
# Example: https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png
map.tiles.url=
# Attribution of the tileset, required for tiles from OpenStreatMap @see https://www.openstreetmap.org/copyright
# Example: &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors
map.tiles.attribution=

# The character used in .csv files to separate columns from each other. Should match the separator that is commonly used in the locale specified in country.locale.
# Default: ,
# Examples: , or ; - you can use \u0020 for a whitespace or \u0009 for a horizontal tab
Expand Down
14 changes: 11 additions & 3 deletions sormas-ui/src/main/java/de/symeda/sormas/ui/map/LeafletMap.java
Expand Up @@ -22,6 +22,10 @@
import java.util.EventObject;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.vaadin.annotations.JavaScript;
import com.vaadin.annotations.StyleSheet;
import com.vaadin.ui.AbstractJavaScriptComponent;
Expand All @@ -32,8 +36,6 @@
import de.symeda.sormas.api.geo.GeoLatLon;
import elemental.json.Json;
import elemental.json.JsonArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* JS and CSS files are in the VAADIN folder, so we can also access required
Expand Down Expand Up @@ -75,6 +77,13 @@ public LeafletMap() {
getState().setTileLayerVisible(true);
getState().setTileLayerOpacity(1);

String tilesUrl = FacadeProvider.getConfigFacade().getMapTilersUrl();
if(StringUtils.isNoneBlank(tilesUrl)) {
callFunction(
"setTileLayer",
tilesUrl,
FacadeProvider.getConfigFacade().getMapTilersAttribution());
}
addFunction("onClick", new JavaScriptFunction() {

@Override
Expand All @@ -87,7 +96,6 @@ public void call(JsonArray arguments) {
// credit where credit's due
String attribution = FacadeProvider.getGeoShapeProvider().loadShapefileAttributions();
this.addShapefileAttribution(attribution);

}

/**
Expand Down
9 changes: 9 additions & 0 deletions sormas-ui/src/main/webapp/VAADIN/map/leaflet-connector.js
Expand Up @@ -74,6 +74,15 @@ window.de_symeda_sormas_ui_map_LeafletMap = function () {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors. Tiles courtesy of Humanitarian OpenStreetMap Team'
});

this.setTileLayer = function(layerUri, attribution){
openStreetMapsLayer.remove();
openStreetMapsLayer = L.tileLayer(layerUri, {
attribution: attribution
});

this.onStateChange();
}

this.onStateChange = function () {

map.setView([this.getState().centerLatitude, this.getState().centerLongitude], this.getState().zoom);
Expand Down

0 comments on commit ee97977

Please sign in to comment.