aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/org/traccar/web/Traccar.gwt.xml4
-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
-rw-r--r--src/org/traccar/web/server/model/DataServiceImpl.java2
-rw-r--r--src/org/traccar/web/shared/model/Device.java1
6 files changed, 69 insertions, 37 deletions
diff --git a/src/org/traccar/web/Traccar.gwt.xml b/src/org/traccar/web/Traccar.gwt.xml
index 00813723..4ae88707 100644
--- a/src/org/traccar/web/Traccar.gwt.xml
+++ b/src/org/traccar/web/Traccar.gwt.xml
@@ -6,8 +6,12 @@
<module rename-to='traccar'>
<inherits name='com.google.gwt.user.User'/>
+ <inherits name="com.google.gwt.logging.Logging"/>
<inherits name='com.sencha.gxt.ui.GXT'/>
<inherits name='org.gwtopenmaps.openlayers.OpenLayers' />
+
+ <set-property name="gwt.logging.enabled" value="FALSE"/>
+ <set-property name="gwt.logging.consoleHandler" value="DISABLED"/>
<entry-point class='org.traccar.web.client.Traccar'/>
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);
+ }
+
}
diff --git a/src/org/traccar/web/server/model/DataServiceImpl.java b/src/org/traccar/web/server/model/DataServiceImpl.java
index 47e313d2..0b2a80ba 100644
--- a/src/org/traccar/web/server/model/DataServiceImpl.java
+++ b/src/org/traccar/web/server/model/DataServiceImpl.java
@@ -126,8 +126,8 @@ public class DataServiceImpl extends RemoteServiceServlet implements DataService
@Override
public List<Device> getDevices() {
- User user = getUser();
List<Device> devices = new LinkedList<Device>();
+ User user = getUser();
devices.addAll(user.getDevices());
return devices;
}
diff --git a/src/org/traccar/web/shared/model/Device.java b/src/org/traccar/web/shared/model/Device.java
index c0e2b440..df4afb4b 100644
--- a/src/org/traccar/web/shared/model/Device.java
+++ b/src/org/traccar/web/shared/model/Device.java
@@ -57,7 +57,6 @@ public class Device implements Serializable {
return uniqueId;
}
- @Column(unique = true)
private String name;
public void setName(String name) {