aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/Context.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-02-24 15:12:26 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-02-24 15:12:26 -0800
commitd610b1ab5135503d1d39aa291190a860ddb952a9 (patch)
tree9742ce6f0fede6bb9bfa523d4ab5f59a9945dcc1 /src/org/traccar/Context.java
parent78e8a550b66691bd61204698d43e82d958fce517 (diff)
downloadtrackermap-server-d610b1ab5135503d1d39aa291190a860ddb952a9.tar.gz
trackermap-server-d610b1ab5135503d1d39aa291190a860ddb952a9.tar.bz2
trackermap-server-d610b1ab5135503d1d39aa291190a860ddb952a9.zip
Refactor geocoder handler
Diffstat (limited to 'src/org/traccar/Context.java')
-rw-r--r--src/org/traccar/Context.java65
1 files changed, 1 insertions, 64 deletions
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index e507406e8..2f8432645 100644
--- a/src/org/traccar/Context.java
+++ b/src/org/traccar/Context.java
@@ -43,20 +43,7 @@ import org.traccar.database.PermissionsManager;
import org.traccar.database.UsersManager;
import org.traccar.events.MotionEventHandler;
import org.traccar.events.OverspeedEventHandler;
-import org.traccar.geocoder.AddressFormat;
-import org.traccar.geocoder.BanGeocoder;
-import org.traccar.geocoder.BingMapsGeocoder;
-import org.traccar.geocoder.FactualGeocoder;
-import org.traccar.geocoder.GeocodeFarmGeocoder;
-import org.traccar.geocoder.GeocodeXyzGeocoder;
import org.traccar.geocoder.Geocoder;
-import org.traccar.geocoder.GisgraphyGeocoder;
-import org.traccar.geocoder.GoogleGeocoder;
-import org.traccar.geocoder.HereGeocoder;
-import org.traccar.geocoder.MapQuestGeocoder;
-import org.traccar.geocoder.MapmyIndiaGeocoder;
-import org.traccar.geocoder.NominatimGeocoder;
-import org.traccar.geocoder.OpenCageGeocoder;
import org.traccar.helper.Log;
import org.traccar.helper.SanitizerModule;
import org.traccar.model.Attribute;
@@ -164,10 +151,8 @@ public final class Context {
return permissionsManager;
}
- private static Geocoder geocoder;
-
public static Geocoder getGeocoder() {
- return geocoder;
+ return Main.getInjector() != null ? Main.getInjector().getInstance(Geocoder.class) : null;
}
private static WebServer webServer;
@@ -292,50 +277,6 @@ public final class Context {
}
- public static Geocoder initGeocoder() {
- String type = config.getString("geocoder.type", "google");
- String url = config.getString("geocoder.url");
- String id = config.getString("geocoder.id");
- String key = config.getString("geocoder.key");
- String language = config.getString("geocoder.language");
-
- String formatString = config.getString("geocoder.format");
- AddressFormat addressFormat;
- if (formatString != null) {
- addressFormat = new AddressFormat(formatString);
- } else {
- addressFormat = new AddressFormat();
- }
-
- int cacheSize = config.getInteger("geocoder.cacheSize");
- switch (type) {
- case "nominatim":
- return new NominatimGeocoder(url, key, language, cacheSize, addressFormat);
- case "gisgraphy":
- return new GisgraphyGeocoder(url, cacheSize, addressFormat);
- case "mapquest":
- return new MapQuestGeocoder(url, key, cacheSize, addressFormat);
- case "opencage":
- return new OpenCageGeocoder(url, key, cacheSize, addressFormat);
- case "bingmaps":
- return new BingMapsGeocoder(url, key, cacheSize, addressFormat);
- case "factual":
- return new FactualGeocoder(url, key, cacheSize, addressFormat);
- case "geocodefarm":
- return new GeocodeFarmGeocoder(key, language, cacheSize, addressFormat);
- case "geocodexyz":
- return new GeocodeXyzGeocoder(key, cacheSize, addressFormat);
- case "ban":
- return new BanGeocoder(cacheSize, addressFormat);
- case "here":
- return new HereGeocoder(id, key, language, cacheSize, addressFormat);
- case "mapmyindia":
- return new MapmyIndiaGeocoder(url, key, cacheSize, addressFormat);
- default:
- return new GoogleGeocoder(key, language, cacheSize, addressFormat);
- }
- }
-
public static void init(String configFile) throws Exception {
try {
@@ -381,10 +322,6 @@ public final class Context {
identityManager = deviceManager;
- if (config.getBoolean("geocoder.enable")) {
- geocoder = initGeocoder();
- }
-
if (config.getBoolean("web.enable")) {
webServer = new WebServer(config);
}