diff --git a/src/main/java/org/traccar/web/shared/model/Device.java b/src/main/java/org/traccar/web/shared/model/Device.java index 2bacb8c3..e765cf69 100644 --- a/src/main/java/org/traccar/web/shared/model/Device.java +++ b/src/main/java/org/traccar/web/shared/model/Device.java @@ -171,6 +171,7 @@ public void setIconType(DeviceIconType iconType) { this.iconType = iconType; } + @Expose @ManyToOne @JoinColumn(foreignKey = @ForeignKey(name = "devices_fkey_icon_id")) private DeviceIcon icon; diff --git a/src/main/webapp/m/js/traccar-mobile.js b/src/main/webapp/m/js/traccar-mobile.js index 2579c2e5..cfc24a0a 100644 --- a/src/main/webapp/m/js/traccar-mobile.js +++ b/src/main/webapp/m/js/traccar-mobile.js @@ -597,8 +597,7 @@ function drawMarker(position) { anchorXUnits: 'fraction', anchorYUnits: 'fraction', opacity: 0.9, - src: position.offline ? position.device.iconType.OFFLINE.urls[position.selected ? 1 : 0] : - position.device.iconType.LATEST.urls[position.selected ? 1 : 0] + src: getIconURL(position) }), text: new ol.style.Text({ text: position.device.name, @@ -625,6 +624,21 @@ function drawMarker(position) { vectorLayer.getSource().addFeature(markerFeature); } +function getIconURL(position) { + if (position.device.icon == null) { + return position.offline ? position.device.iconType.OFFLINE.urls[position.selected ? 1 : 0] : + position.device.iconType.LATEST.urls[position.selected ? 1 : 0]; + } else { + var pictureId; + if (position.selected) { + pictureId = position.device.icon.selectedIcon.id; + } else { + pictureId = position.offline ? position.device.icon.offlineIcon.id : position.device.icon.defaultIcon.id; + } + return '/traccar/p/' + pictureId; + } +} + function callGet(options) { options.httpMethod = 'GET' invoke(options);