diff options
-rw-r--r-- | default.cfg | 8 | ||||
-rw-r--r-- | src/org/traccar/database/DataManager.java | 12 | ||||
-rw-r--r-- | src/org/traccar/http/AsyncServlet.java | 3 | ||||
-rw-r--r-- | src/org/traccar/http/JsonConverter.java | 10 | ||||
-rw-r--r-- | web/MapView.js | 30 |
5 files changed, 51 insertions, 12 deletions
diff --git a/default.cfg b/default.cfg index 5401b93da..3bc523bf1 100644 --- a/default.cfg +++ b/default.cfg @@ -16,7 +16,7 @@ imei - String <--> <entry key='database.selectDevice'> - SELECT id, unique_id as imei + SELECT id, uniqueId as imei FROM device; </entry> @@ -32,8 +32,8 @@ extended_info - String (XML) <--> <entry key='database.insertPosition'> - INSERT INTO position (device_id, server_time, device_time, fix_time, valid, latitude, longitude, altitude, speed, course, address, other) - VALUES (:device_id, NOW(), :time, :time, :valid, :latitude, :longitude, :altitude, :speed, :course, :address, :extended_info); + INSERT INTO position (deviceId, serverTime, deviceTime, fixTime, valid, latitude, longitude, altitude, speed, course, address, other) + VALUES (:deviceId, NOW(), :time, :time, :valid, :latitude, :longitude, :altitude, :speed, :course, :address, :other); </entry> <!--> @@ -41,7 +41,7 @@ id - Long <--> <entry key='database.updateLatestPosition'> - UPDATE device SET position_id = :id WHERE id = :device_id; + UPDATE device SET positionId = :id WHERE id = :deviceId; </entry> <!-- Web interface --> diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 2aca1ff87..3a34be2d7 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -187,8 +187,9 @@ public class DataManager { private NamedParameterStatement.Params assignVariables(NamedParameterStatement.Params params, Position position) throws SQLException { params.setString("protocol", position.getProtocol()); - params.setLong("device_id", position.getDeviceId()); - params.setTimestamp("time", position.getFixTime()); + params.setLong("deviceId", position.getDeviceId()); + params.setTimestamp("deviceTime", position.getDeviceTime()); + params.setTimestamp("fixTime", position.getFixTime()); params.setBoolean("valid", position.getValid()); params.setDouble("altitude", position.getAltitude()); params.setDouble("latitude", position.getLatitude()); @@ -196,8 +197,13 @@ public class DataManager { params.setDouble("speed", position.getSpeed()); params.setDouble("course", position.getCourse()); params.setString("address", position.getAddress()); + params.setString("other", position.getOther()); + + // temporary + params.setTimestamp("time", position.getFixTime()); + params.setLong("device_id", position.getDeviceId()); + params.setLong("power", null); params.setString("extended_info", position.getOther()); - params.setLong("power", null); // temporary return params; } diff --git a/src/org/traccar/http/AsyncServlet.java b/src/org/traccar/http/AsyncServlet.java index aeab5855b..f00257f80 100644 --- a/src/org/traccar/http/AsyncServlet.java +++ b/src/org/traccar/http/AsyncServlet.java @@ -34,7 +34,6 @@ import org.traccar.Context; import org.traccar.GlobalTimer; import org.traccar.database.DataCache; import org.traccar.helper.Log; -import org.traccar.model.Event; import org.traccar.model.Position; public class AsyncServlet extends HttpServlet { @@ -51,7 +50,7 @@ public class AsyncServlet extends HttpServlet { private static final boolean DEBUG_ASYNC = true; private static final long SESSION_TIMEOUT = 30; - private static final long REQUEST_TIMEOUT = 30; + private static final long REQUEST_TIMEOUT = 10; private boolean destroyed; private final long userId; diff --git a/src/org/traccar/http/JsonConverter.java b/src/org/traccar/http/JsonConverter.java index 48fd934b7..0802fb9ea 100644 --- a/src/org/traccar/http/JsonConverter.java +++ b/src/org/traccar/http/JsonConverter.java @@ -93,9 +93,15 @@ public class JsonConverter { } else if (method.getReturnType().equals(double.class)) { json.add(name, (Double) method.invoke(object)); } else if (method.getReturnType().equals(String.class)) { - json.add(name, (String) method.invoke(object)); + String value = (String) method.invoke(object); + if (value != null) { + json.add(name, value); + } } else if (method.getReturnType().equals(Date.class)) { - json.add(name, dateFormat.format((Date) method.invoke(object))); + Date value = (Date) method.invoke(object); + if (value != null) { + json.add(name, dateFormat.format(value)); + } } } catch (IllegalAccessException error) { } catch (InvocationTargetException error) { diff --git a/web/MapView.js b/web/MapView.js index 33e0b348a..5c20dba9d 100644 --- a/web/MapView.js +++ b/web/MapView.js @@ -20,6 +20,29 @@ Ext.define('MapView', { title: Strings.map_title, layout: 'fit', + + update: function() { + Ext.Ajax.request({ + scope: this, + url: '/api/async', + success: function(response) { + var data = Ext.decode(response.responseText).data; + + var i; + for (i = 0; i < data.length; i++) { + var iconFeature = new ol.Feature({ + geometry: new ol.geom.Point([30, 30]) + }); + this.vectorSource.addFeature(iconFeature); + } + + this.update(); + }, + failure: function() { + // error + } + }); + }, listeners: { afterrender: function() { @@ -38,6 +61,9 @@ Ext.define('MapView', { var layer = new ol.layer.Tile({ source: new ol.source.OSM({ })});*/ + + this.vectorSource = new ol.source.Vector({}); + var vectorLayer = new ol.layer.Vector({ source: this.vectorSource }); var view = new ol.View({ center: ol.proj.transform(Styles.map_center, 'EPSG:4326', 'EPSG:3857'), @@ -47,9 +73,11 @@ Ext.define('MapView', { this.map = new ol.Map({ target: this.body.dom.id, - layers: [ layer ], + layers: [ layer, vectorLayer ], view: view }); + + this.update(); }, resize: function() { |