diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-01-24 23:26:04 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-01-24 23:26:04 +1300 |
commit | 3f959ddcd1bea187deaed720cc9036b67e80f348 (patch) | |
tree | 7a148eab313f77e8896be4df647ca5e251f03b26 /web/simple/app.js | |
parent | deee0476d2e5257c57f0ef1642fa379c93d8ba23 (diff) | |
download | trackermap-web-3f959ddcd1bea187deaed720cc9036b67e80f348.tar.gz trackermap-web-3f959ddcd1bea187deaed720cc9036b67e80f348.tar.bz2 trackermap-web-3f959ddcd1bea187deaed720cc9036b67e80f348.zip |
Add label to the simple map
Diffstat (limited to 'web/simple/app.js')
-rw-r--r-- | web/simple/app.js | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/web/simple/app.js b/web/simple/app.js index a37d9d5c..f43d537e 100644 --- a/web/simple/app.js +++ b/web/simple/app.js @@ -17,18 +17,32 @@ var url = window.location.protocol + '//' + window.location.host; var token = (window.location.search.match(/token=([^&#]+)/) || [])[1]; -var style = new ol.style.Style({ - image: new ol.style.Circle({ - fill: new ol.style.Fill({ - color: 'teal' +var style = function (label) { + return new ol.style.Style({ + image: new ol.style.Circle({ + fill: new ol.style.Fill({ + color: 'teal' + }), + stroke: new ol.style.Stroke({ + color: 'black', + width: 2 + }), + radius: 7 }), - stroke: new ol.style.Stroke({ - color: 'navy', - width: 2 - }), - radius: 7 - }) -}); + text: new ol.style.Text({ + text: label, + fill: new ol.style.Fill({ + color: 'black' + }), + stroke: new ol.style.Stroke({ + color: 'white', + width: 2 + }), + font: 'bold 12px sans-serif', + offsetY: -16 + }) + }); +}; var source = new ol.source.Vector(); @@ -82,8 +96,9 @@ ajax('GET', url + '/api/session?token=' + token, function(user) { var marker = markers[position.deviceId]; var point = new ol.geom.Point(ol.proj.fromLonLat([position.longitude, position.latitude])); if (!marker) { + var device = devices.find(function (device) { return device.id === position.deviceId }); marker = new ol.Feature(point); - marker.setStyle(style); + marker.setStyle(style(device.name)); markers[position.deviceId] = marker; source.addFeature(marker); } else { |