aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/client/controller/MapController.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-02-16 16:55:44 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2013-02-16 16:55:44 +1300
commit6d48729efb4bd1ac34bba003a8a4313a70a02cce (patch)
treeb834c03b8aeb3302bedb949a63f6b6d0ed4f2600 /src/org/traccar/web/client/controller/MapController.java
parent11b7037755c08654fba3b3781f83445244582d59 (diff)
downloadtrackermap-web-6d48729efb4bd1ac34bba003a8a4313a70a02cce.tar.gz
trackermap-web-6d48729efb4bd1ac34bba003a8a4313a70a02cce.tar.bz2
trackermap-web-6d48729efb4bd1ac34bba003a8a4313a70a02cce.zip
Handle clicks on markers (fix #8)
Diffstat (limited to 'src/org/traccar/web/client/controller/MapController.java')
-rw-r--r--src/org/traccar/web/client/controller/MapController.java50
1 files changed, 47 insertions, 3 deletions
diff --git a/src/org/traccar/web/client/controller/MapController.java b/src/org/traccar/web/client/controller/MapController.java
index 44094f71..13c736f5 100644
--- a/src/org/traccar/web/client/controller/MapController.java
+++ b/src/org/traccar/web/client/controller/MapController.java
@@ -17,8 +17,10 @@ package org.traccar.web.client.controller;
import java.util.Collections;
import java.util.Comparator;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import org.traccar.web.client.Application;
import org.traccar.web.client.view.MapView;
@@ -29,14 +31,22 @@ import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.sencha.gxt.widget.core.client.ContentPanel;
-public class MapController implements ContentController {
+public class MapController implements ContentController, MapView.MapHandler {
private static final int UPDATE_INTERVAL = 15000;
+ public interface MapHandler {
+ public void onDeviceSelected(Device device);
+ public void onArchivePositionSelected(Position position);
+ }
+
+ private MapHandler mapHandler;
+
private MapView mapView;
- public MapController() {
- mapView = new MapView();
+ public MapController(MapHandler mapHandler) {
+ this.mapHandler = mapHandler;
+ mapView = new MapView(this);
}
@Override
@@ -57,12 +67,20 @@ public class MapController implements ContentController {
update();
}
+ private Map<Long, Position> latestPositionMap = new HashMap<Long, Position>();
+
public void update() {
updateTimer.cancel();
Application.getDataService().getLatestPositions(new AsyncCallback<List<Position>>() {
@Override
public void onSuccess(List<Position> result) {
mapView.showLatestPositions(result);
+ for (Position position : result) {
+ latestPositionMap.put(position.getDevice().getId(), position);
+ }
+ for (Map.Entry<Long, PositionUpdateHandler> entry : positionUpdateMap.entrySet()) {
+ entry.getValue().onUpdate(latestPositionMap.get(entry.getKey()));
+ }
updateTimer.schedule(UPDATE_INTERVAL);
}
@Override
@@ -91,4 +109,30 @@ public class MapController implements ContentController {
mapView.selectArchivePosition(position);
}
+ public interface PositionUpdateHandler {
+ public void onUpdate(Position position);
+ }
+
+ private Map<Long, PositionUpdateHandler> positionUpdateMap = new HashMap<Long, PositionUpdateHandler>();
+
+
+ public void registerPositionUpdate(Device device, PositionUpdateHandler handler) {
+ positionUpdateMap.put(device.getId(), handler);
+ handler.onUpdate(latestPositionMap.get(device.getId()));
+ }
+
+ public void unregisterPositionUpdate(Device device) {
+ positionUpdateMap.remove(device.getId());
+ }
+
+ @Override
+ public void onPositionSelected(Position position) {
+ mapHandler.onDeviceSelected(position.getDevice());
+ }
+
+ @Override
+ public void onArchivePositionSelected(Position position) {
+ mapHandler.onArchivePositionSelected(position);
+ }
+
}