1 package org.simantics.maps.prefs;
3 import java.net.MalformedURLException;
6 import org.eclipse.core.runtime.preferences.InstanceScope;
7 import org.osgi.service.prefs.Preferences;
9 public class MapsClientPreferences {
11 public static final String P_NODE = "org.simantics.district.maps";
13 public static final String P_TILESERVER_URL = "org.simantics.district.maps.prefs.tileserverURL";
14 public static final String P_USE_BUILTIN = "org.simantics.district.maps.prefs.tileserverURL";
16 // TODO: fix this, currently copied from MapsServerPreferences
17 public static final String P_DEFAULT_PORT = "org.simantics.maps.server.defaultPort";
18 public static final String P_CURRENT_TM2STYLE = "org.simantics.maps.server.currentTM2Style";
19 public static final String P_SERVER_NODE = "org.simantics.maps.server";
20 public static Preferences getServerPreferences() {
21 return InstanceScope.INSTANCE.getNode(P_SERVER_NODE);
24 public static Preferences getPreferences() {
25 return InstanceScope.INSTANCE.getNode(P_NODE);
28 public static String tileserverURL() {
29 return getPreferences().get(P_TILESERVER_URL, "");
32 public static boolean useBuiltinServer() {
33 return getPreferences().getBoolean(P_USE_BUILTIN, true);
36 public static String possibleBuiltinServerURL() {
37 int port = getServerPreferences().getInt(P_DEFAULT_PORT, 8585);
38 String style = getServerPreferences().get(P_CURRENT_TM2STYLE, "mapbox-studio-osm-bright.tm2");
39 if (port != -1 && style != null) {
41 return new URL("http", "localhost", port, "/" + style).toString();
42 } catch (MalformedURLException e) {
43 throw new RuntimeException(e);