From 95d702862cf3958c7d5203accd0a06814a55b49c Mon Sep 17 00:00:00 2001 From: Raphael Bergamini Date: Tue, 18 Dec 2018 19:24:19 -0200 Subject: [PATCH] Add tooltip to GoogleMap Markers --- src/Wt/WGoogleMap | 4 ++-- src/Wt/WGoogleMap.C | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Wt/WGoogleMap b/src/Wt/WGoogleMap index 1fe02d36cd..6aee63842c 100644 --- a/src/Wt/WGoogleMap +++ b/src/Wt/WGoogleMap @@ -129,7 +129,7 @@ public: /*! \brief Adds a marker overlay to the map. */ - void addMarker(const Coordinate &pos); + void addMarker(const Coordinate &pos, const WString &toolTip = WString()); /*! \brief Adds a polyline overlay to the map. * @@ -152,7 +152,7 @@ public: /*! \brief Adds a icon marker overlay to the map. */ - void addIconMarker(const Coordinate &pos, const std::string& iconURL); + void addIconMarker(const Coordinate &pos, const std::string& iconURL, const WString &toolTip = WString()); /*! \brief Removes all overlays from the map. */ diff --git a/src/Wt/WGoogleMap.C b/src/Wt/WGoogleMap.C index 6d484657c4..e30595c3fa 100644 --- a/src/Wt/WGoogleMap.C +++ b/src/Wt/WGoogleMap.C @@ -294,7 +294,7 @@ void WGoogleMap::doGmJavaScript(const std::string& jscode) additions_.push_back(jscode); } -void WGoogleMap::addMarker(const Coordinate& pos) +void WGoogleMap::addMarker(const Coordinate& pos, const WString &toolTip) { std::stringstream strm; @@ -309,16 +309,19 @@ void WGoogleMap::addMarker(const Coordinate& pos) strm << ";" << "var marker = new google.maps.Marker({" << "position: position," - << "map: " << jsRef() << ".map" - << "});" - << jsRef() << ".map.overlays.push(marker);"; + << "map: " << jsRef() << ".map"; + if (!toolTip.empty()) + strm << ", title: " << WWebWidget::jsStringLiteral(toolTip); + + strm << "});" + << jsRef() << ".map.overlays.push(marker);"; } doGmJavaScript(strm.str()); } void WGoogleMap::addIconMarker(const Coordinate &pos, - const std::string& iconURL) + const std::string& iconURL, const WString &toolTip) { std::stringstream strm; @@ -332,10 +335,11 @@ void WGoogleMap::addIconMarker(const Coordinate &pos, << "var marker = new google.maps.Marker({" << "position: position," << "icon: \"" << iconURL << "\"," - << "map: " << jsRef() << ".map" - << "});" - - << jsRef() << ".map.overlays.push(marker);"; + << "map: " << jsRef() << ".map"; + if (!toolTip.empty()) + strm << ", title: " << WWebWidget::jsStringLiteral(toolTip); + strm << "});" + << jsRef() << ".map.overlays.push(marker);"; } doGmJavaScript(strm.str());