aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.settings/com.google.gwt.eclipse.core.prefs1
-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
7 files changed, 70 insertions, 37 deletions
diff --git a/.settings/com.google.gwt.eclipse.core.prefs b/.settings/com.google.gwt.eclipse.core.prefs
index 077314c..2adad03 100644
--- a/.settings/com.google.gwt.eclipse.core.prefs
+++ b/.settings/com.google.gwt.eclipse.core.prefs
@@ -1,2 +1,3 @@
eclipse.preferences.version=1
filesCopiedToWebInfLib=gwt-servlet.jar
+gwtCompileSettings=PGd3dC1jb21waWxlLXNldHRpbmdzPjxsb2ctbGV2ZWw+SU5GTzwvbG9nLWxldmVsPjxvdXRwdXQtc3R5bGU+T0JGVVNDQVRFRDwvb3V0cHV0LXN0eWxlPjxleHRyYS1hcmdzPjwhW0NEQVRBW11dPjwvZXh0cmEtYXJncz48dm0tYXJncz48IVtDREFUQVstWG14NTEybV1dPjwvdm0tYXJncz48ZW50cnktcG9pbnQtbW9kdWxlPm9yZy50cmFjY2FyLndlYi5UcmFjY2FyPC9lbnRyeS1wb2ludC1tb2R1bGU+PC9nd3QtY29tcGlsZS1zZXR0aW5ncz4\=
diff --git a/src/org/traccar/web/Traccar.gwt.xml b/src/org/traccar/web/Traccar.gwt.xml
index 0081372..4ae8870 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 2166237..c802995 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 bbe932a..f1bf57c 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 35ae886..bc850bd 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 47e313d..0b2a80b 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 c0e2b44..df4afb4 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) {