aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/client
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-01-11 22:25:38 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2013-01-11 22:25:38 +1300
commit7cdc2fbdb4cbb1b55274278e51222bbb874dcf13 (patch)
tree6c4a9e775a5f370b93f5c614b9652bb8eccec740 /src/org/traccar/web/client
parent230ff57c8880aa8d2f749c76b77b89a4eb3818d8 (diff)
downloadtrackermap-web-7cdc2fbdb4cbb1b55274278e51222bbb874dcf13.tar.gz
trackermap-web-7cdc2fbdb4cbb1b55274278e51222bbb874dcf13.tar.bz2
trackermap-web-7cdc2fbdb4cbb1b55274278e51222bbb874dcf13.zip
Polish map panel and fix few bugs
Diffstat (limited to 'src/org/traccar/web/client')
-rw-r--r--src/org/traccar/web/client/Application.java9
-rw-r--r--src/org/traccar/web/client/view/MapPositionRenderer.java80
-rw-r--r--src/org/traccar/web/client/view/MarkerIconFactory.java10
3 files changed, 64 insertions, 35 deletions
diff --git a/src/org/traccar/web/client/Application.java b/src/org/traccar/web/client/Application.java
index 2166237f..c8029959 100644
--- a/src/org/traccar/web/client/Application.java
+++ b/src/org/traccar/web/client/Application.java
@@ -15,6 +15,8 @@
*/
package org.traccar.web.client;
+import java.util.logging.Logger;
+
import org.traccar.web.client.controller.ArchiveController;
import org.traccar.web.client.controller.DeviceController;
import org.traccar.web.client.controller.MapController;
@@ -39,6 +41,12 @@ public class Application {
return dataService;
}
+ private static Logger logger = Logger.getLogger("");
+
+ public static Logger getLogger() {
+ return logger;
+ }
+
private final DeviceController deviceController;
private final MapController mapController;
private final ArchiveController archiveController;
@@ -47,6 +55,7 @@ public class Application {
public Application() {
deviceController = new DeviceController(deviceHandler);
+ deviceController.getDeviceStore().addStoreHandlers(deviceStoreHandler);
mapController = new MapController();
archiveController = new ArchiveController(archiveHanlder, deviceController.getDeviceStore());
archiveController.getPositionStore().addStoreHandlers(archiveStoreHandler);
diff --git a/src/org/traccar/web/client/view/MapPositionRenderer.java b/src/org/traccar/web/client/view/MapPositionRenderer.java
index bbe932a4..f1bf57ca 100644
--- a/src/org/traccar/web/client/view/MapPositionRenderer.java
+++ b/src/org/traccar/web/client/view/MapPositionRenderer.java
@@ -33,40 +33,38 @@ import org.traccar.web.shared.model.Position;
public class MapPositionRenderer {
private final MapView mapView;
- private final Vector vectorLayer;
- private final Markers markerLayer;
private final MarkerIconFactory.IconType iconType;
+ protected Vector getVectorLayer() {
+ return mapView.getVectorLayer();
+ }
+
+ protected Markers getMarkerLayer() {
+ return mapView.getMarkerLayer();
+ }
+
public MapPositionRenderer(MapView mapView, MarkerIconFactory.IconType iconType) {
this.mapView = mapView;
- vectorLayer = mapView.getVectorLayer();
- markerLayer = mapView.getMarkerLayer();
this.iconType = iconType;
}
- /*
- * TODO: a lot of mess here
- * 1. changeMarkerIcon doesn't save new marker
- * 2. if device selected save device instead of position
- * 3. find way to change marker icon
- * 4. shorter cleaner methods
- * ... maybe something else
- */
-
- private void changeMarkerIcon(Marker marker, Icon icon) {
- Marker newMarker = new Marker(marker.getLonLat(), icon);
- markerLayer.removeMarker(marker);
- markerLayer.addMarker(newMarker);
+ private void changeMarkerIcon(Long positionId, Icon icon) {
+ Marker oldMarker = markerMap.get(positionId);
+ Marker newMarker = new Marker(oldMarker.getLonLat(), icon);
+ markerMap.put(positionId, newMarker);
+ getMarkerLayer().addMarker(newMarker);
+ getMarkerLayer().removeMarker(oldMarker);
}
private Map<Long, Marker> markerMap = new HashMap<Long, Marker>(); // Position.id -> Marker
private Map<Long, Long> deviceMap = new HashMap<Long, Long>(); // Device.id -> Position.id
private Long selectedPositionId;
+ private Long selectedDeviceId;
public void showPositions(List<Position> positions) {
for (Marker marker : markerMap.values()) {
- markerLayer.removeMarker(marker);
+ getMarkerLayer().removeMarker(marker);
}
markerMap.clear();
deviceMap.clear();
@@ -77,16 +75,24 @@ public class MapPositionRenderer {
MarkerIconFactory.getIcon(iconType, false));
markerMap.put(position.getId(), marker);
deviceMap.put(position.getDevice().getId(), position.getId());
- markerLayer.addMarker(marker);
+ getMarkerLayer().addMarker(marker);
}
if (selectedPositionId != null) {
- selectPosition(null, selectedPositionId, false);
+ if (!selectPosition(null, selectedPositionId, false)) {
+ selectedPositionId = null;
+ }
+ }
+
+ if (selectedDeviceId != null) {
+ if (!selectPosition(null, deviceMap.get(selectedDeviceId), false)) {
+ selectedDeviceId = null;
+ }
}
}
public void showTrack(List<Position> positions) {
- vectorLayer.destroyFeatures();
+ getVectorLayer().destroyFeatures();
if (!positions.isEmpty()) {
Point[] linePoints = new Point[positions.size()];
@@ -97,33 +103,43 @@ public class MapPositionRenderer {
}
LineString lineString = new LineString(linePoints);
- vectorLayer.addFeature(new VectorFeature(lineString));
+ getVectorLayer().addFeature(new VectorFeature(lineString));
//mapView.getMap().zoomToExtent(lineString.getBounds());
}
}
public void selectPosition(Position position, boolean center) {
- selectPosition(selectedPositionId, position.getId(), center);
+ Long oldPositionId = selectedPositionId;
+ Long newPositionId = (position != null) ? position.getId() : null;
+ if (selectPosition(oldPositionId, newPositionId, center)) {
+ selectedPositionId = position.getId();
+ } else {
+ selectedPositionId = null;
+ }
}
public void selectDevice(Device device, boolean center) {
- Long positionId = (device != null) ? deviceMap.get(device.getId()) : null;
- selectPosition(selectedPositionId, positionId, center);
+ Long oldPositionId = (selectedDeviceId != null) ? deviceMap.get(selectedDeviceId) : null;
+ Long newPositionId = (device != null) ? deviceMap.get(device.getId()) : null;
+ if (selectPosition(oldPositionId, newPositionId, center)) {
+ selectedDeviceId = device.getId();
+ } else {
+ selectedDeviceId = null;
+ }
}
- private void selectPosition(Long oldPositionId, Long newPositionId, boolean center) {
+ private boolean selectPosition(Long oldPositionId, Long newPositionId, boolean center) {
if (oldPositionId != null && markerMap.containsKey(oldPositionId)) {
- changeMarkerIcon(markerMap.get(oldPositionId), MarkerIconFactory.getIcon(iconType, false));
- selectedPositionId = null;
+ changeMarkerIcon(oldPositionId, MarkerIconFactory.getIcon(iconType, false));
}
if (newPositionId != null && markerMap.containsKey(newPositionId)) {
- Marker marker = markerMap.get(newPositionId);
- changeMarkerIcon(marker, MarkerIconFactory.getIcon(iconType, true));
+ changeMarkerIcon(newPositionId, MarkerIconFactory.getIcon(iconType, true));
if (center) {
- mapView.getMap().panTo(marker.getLonLat());
+ mapView.getMap().panTo(markerMap.get(newPositionId).getLonLat());
}
- selectedPositionId = newPositionId;
+ return true;
}
+ return false;
}
}
diff --git a/src/org/traccar/web/client/view/MarkerIconFactory.java b/src/org/traccar/web/client/view/MarkerIconFactory.java
index 35ae8869..bc850bdd 100644
--- a/src/org/traccar/web/client/view/MarkerIconFactory.java
+++ b/src/org/traccar/web/client/view/MarkerIconFactory.java
@@ -35,13 +35,17 @@ class MarkerIconFactory {
iconArchive
};
- public static Icon getIcon(IconType type, boolean selected) {
+ public static String getIconUrl(IconType type, boolean selected) {
if (type == IconType.iconLatest) {
- return new Icon(selected ? iconGreen : iconRed, iconSize, iconOffset);
+ return selected ? iconGreen : iconRed;
} else if (type == IconType.iconArchive) {
- return new Icon(selected ? iconGold : iconBlue, iconSize, iconOffset);
+ return selected ? iconGold : iconBlue;
}
return null;
}
+ public static Icon getIcon(IconType type, boolean selected) {
+ return new Icon(getIconUrl(type, selected), iconSize, iconOffset);
+ }
+
}