diff options
Diffstat (limited to 'src/org/traccar')
-rw-r--r-- | src/org/traccar/web/Traccar.gwt.xml | 4 | ||||
-rw-r--r-- | src/org/traccar/web/client/Application.java | 9 | ||||
-rw-r--r-- | src/org/traccar/web/client/view/MapPositionRenderer.java | 80 | ||||
-rw-r--r-- | src/org/traccar/web/client/view/MarkerIconFactory.java | 10 | ||||
-rw-r--r-- | src/org/traccar/web/server/model/DataServiceImpl.java | 2 | ||||
-rw-r--r-- | src/org/traccar/web/shared/model/Device.java | 1 |
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 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) { |