diff --git a/src/app/positionmanager.cpp b/src/app/positionmanager.cpp index c4c23007980b381aa1cd90bbf0225afa73d7f6c3..b9d97f08ed2f42fff9d133e269bea001119832bc 100644 --- a/src/app/positionmanager.cpp +++ b/src/app/positionmanager.cpp @@ -389,7 +389,13 @@ PositionManager::showNotification(const QString& accountId, const QString& convId, const QString& from) { - auto bestName = lrcInstance_->getAccountInfo(accountId).contactModel->bestNameForContact(from); + QString bestName; + if (from == lrcInstance_->getAccountInfo(accountId).profileInfo.uri) + bestName = lrcInstance_->getAccountInfo(accountId).accountModel->bestNameForAccount( + accountId); + else + bestName = lrcInstance_->getAccountInfo(accountId).contactModel->bestNameForContact(from); + auto body = tr("%1 is sharing it's location").arg(bestName); #ifdef Q_OS_LINUX auto contactPhoto = Utils::contactPhoto(lrcInstance_, from, QSize(50, 50), accountId); @@ -469,6 +475,22 @@ PositionManager::addPositionToMap(PositionKey key, QVariantMap position) { // avatar only sent one time to qml, when a new position is added position["avatar"] = getAvatar(key.first, key.second); + auto accountId = key.first; + auto uri = key.second; + auto& accountInfo = lrcInstance_->getAccountInfo(accountId); + QString bestName; + + if (uri == accountInfo.profileInfo.uri) { + bestName = accountInfo.accountModel->bestNameForAccount(accountId); + } else + bestName = accountInfo.contactModel->bestNameForContact(uri); + + QString shorterAuthorName = bestName; + shorterAuthorName.truncate(10); + if (bestName != shorterAuthorName) { + shorterAuthorName = shorterAuthorName + "…"; + } + position["authorName"] = shorterAuthorName; Q_EMIT positionShareAdded(position); } diff --git a/src/app/webengine/map/MapPosition.qml b/src/app/webengine/map/MapPosition.qml index 6f5ea5b0536218b865e4fb24c788c6e22aeeba9a..3b03e96c8cea26361dd3b3e7fb9845608b680a3c 100644 --- a/src/app/webengine/map/MapPosition.qml +++ b/src/app/webengine/map/MapPosition.qml @@ -178,7 +178,8 @@ Item { if (shareInfo.account === attachedAccountId) { var curLong = shareInfo.long var curLat = shareInfo.lat - webView.runJavaScript("newPosition([" + curLong + "," + curLat + "], '" + shareInfo.author + "', '" + shareInfo.avatar + "' )" ); + webView.runJavaScript("newPosition([" + curLong + "," + curLat + "], '" + + shareInfo.author + "', '" + shareInfo.avatar + "', '" + shareInfo.authorName + "' )" ); webView.runJavaScript("zoomTolayersExtent()" ); } } @@ -214,7 +215,7 @@ Item { attachedAccountId = CurrentAccount.id runJavaScript(UtilsAdapter.getStyleSheet("olcss",UtilsAdapter.qStringFromFile(olCss))) webView.isLoaded = true - runJavaScript("setMapView([" + 0 + ","+ 0 + "], " + 1 + " );" ); + webView.runJavaScript("setMapView([" + 0 + ","+ 0 + "], " + 1 + " );" ); PositionManager.startPositioning() //load locations that were received before this conversation was opened PositionManager.loadPreviousLocations(attachedAccountId); diff --git a/src/app/webengine/map/map.js b/src/app/webengine/map/map.js index 7d53f293f9b04ac8ee0a5a5d7ab621e6e6d997e0..144a6cbb88f6d2b01b483d2fa6a923e729fc904d 100644 --- a/src/app/webengine/map/map.js +++ b/src/app/webengine/map/map.js @@ -61,7 +61,7 @@ var proj = new ol.proj.Projection({ extent: extent }) -function setSource (coordos, avatar) { +function setSource (coordos, avatar, authorName) { var coord = ol.proj.fromLonLat(coordos) var pointFeature = new ol.Feature({ geometry: new ol.geom.Point(coord), @@ -71,14 +71,14 @@ function setSource (coordos, avatar) { var preStyle = new ol.style.Icon({ src: "data:image/png;base64," + avatar}) - //resize the image to 35 px + //resize the image to 40 px var image = preStyle.getImage() if (!image.width) { image.addEventListener('load', function () { - preStyle.setScale([35 / image.width, 35 / image.height]) + preStyle.setScale([40 / image.width, 40 / image.height]) }) } else { - preStyle.setScale([35 / image.width, 35 / image.height]) + preStyle.setScale([40 / image.width, 40 / image.height]) } var iconStyle = new ol.style.Style({ @@ -86,21 +86,45 @@ function setSource (coordos, avatar) { }) pointFeature.setStyle(iconStyle) + + // create a text label + var textLabel = new ol.Feature({ + geometry: new ol.geom.Point(coord), + text: authorName + }); + + // set the style for the text label + textLabel.setStyle(new ol.style.Style({ + text: new ol.style.Text({ + text: textLabel.get('text'), + font: '20px Arial', + fill: new ol.style.Fill({ + color: 'black' + }), + stroke: new ol.style.Stroke({ + color: 'white', + width: 3 + }), + offsetY: 30 + }) + })); + var vectorSource = new ol.source.Vector({ - features: [pointFeature], + features: [pointFeature,textLabel], }) return vectorSource } -function newPosition (coordos, authorUri, avatar) { + +function newPosition (coordos, authorUri, avatar, authorName) { var layerArray = map.getLayers().getArray(); for (var i = 0; i < layerArray.length; i++ ){ if(layerArray[i].layer_type === authorUri) { return } } - vectorSource = setSource(coordos, avatar) + vectorSource = setSource(coordos, avatar, authorName) var iconLayer = new ol.layer.Vector({source: vectorSource}) iconLayer.layer_type = authorUri map.addLayer(iconLayer) @@ -112,6 +136,7 @@ function updatePosition (coordos, authorUri) { for (var i = 0; i < layerArray.length; i++ ){ if(layerArray[i].layer_type === authorUri) { layerArray[i].getSource().getFeatures()[0].getGeometry().setCoordinates(coord) + layerArray[i].getSource().getFeatures()[1].getGeometry().setCoordinates(coord) return } }