Skip to content

Commit

Permalink
#7792 Make tile server used for map configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Levente Gal committed Feb 11, 2022
1 parent 09fbb0a commit 51722c2
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
Expand Up @@ -100,6 +100,10 @@ public interface ConfigFacade {

boolean isMapUseCountryCenter();

String getMapTilersUrl();

String getMapTilersAttribution();

int getMapZoom();

String getGeocodingServiceUrlTemplate();
Expand Down
Expand Up @@ -63,6 +63,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 @@ -289,6 +291,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
23 changes: 21 additions & 2 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 @@ -88,6 +97,16 @@ public void call(JsonArray arguments) {
String attribution = FacadeProvider.getGeoShapeProvider().loadShapefileAttributions();
this.addShapefileAttribution(attribution);

/*
* var Stamen_Toner = L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/toner/{z}/{x}/{y}{r}.{ext}', {
* attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC
* BY 3.0</a> &mdash; Map data &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
* subdomains: 'abcd',
* minZoom: 0,
* maxZoom: 20,
* ext: 'png'
* });
*/
}

/**
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 51722c2

Please sign in to comment.