Project

General

Profile

Feature #1219 » wt-wgooglemap-marker_info_3.2.1.patch

Antonio Mancina, 04/05/2012 03:13 PM

View differences:

wt-3.2.1-rc3-mod/src/Wt/WGoogleMap 2012-04-03 16:23:06.922752459 +0200
/*! \brief Adds a marker overlay to the map.
*/
void addMarker(const Coordinate &pos);
void addMarker(const Coordinate &pos, const WString& aMessage = "");
/*! \brief Adds a polyline overlay to the map.
*
......
/*! \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& aMessage = "");
/*! \brief Removes all overlays from the map.
*/
......
void setMapOption(const std::string &option,
const std::string &state);
static volatile boost::uint32_t markerIndex_;
private:
ApiVersion apiVersion_;
};
wt-3.2.1-rc3-mod/src/Wt/WGoogleMap.C 2012-04-03 16:35:41.582752247 +0200
#include <boost/bind.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/interprocess/detail/atomic.hpp>
#include <string>
#include <utility>
......
// example javascript code from :
// http://code.google.com/apis/maps/documentation/
volatile boost::uint32_t WGoogleMap::markerIndex_ = 0;
WGoogleMap::WGoogleMap(ApiVersion version, WContainerWidget *parent)
: clicked_(this, "click"),
doubleClicked_(this, "dblclick"),
......
additions_.push_back(jscode);
}
void WGoogleMap::addMarker(const Coordinate& pos)
void WGoogleMap::addMarker(const Coordinate& pos, const WString& aMessage)
{
std::stringstream strm;
......
<< pos.latitude() << ", " << pos.longitude() << "));"
<< jsRef() << ".map.addOverlay(marker);";
} else {
strm << "var position = new google.maps.LatLng("
<< pos.latitude() << ", " << pos.longitude() << ");"
<< "var marker = new google.maps.Marker({"
<< "position: position,"
<< "map: " << jsRef() << ".map"
<< "});"
<< jsRef() << ".map.overlays.push(marker);";
// Atomically increment the index and returns the pre-increment variable value
std::string mySuffixString = boost::lexical_cast<std::string>(boost::interprocess::detail::atomic_inc32(&markerIndex_));
strm << "var position = new google.maps.LatLng("
<< pos.latitude() << ", " << pos.longitude() << ");"
<< "var marker_" + mySuffixString + " = new google.maps.Marker({"
<< "position: position,"
<< "map: " << jsRef() << ".map"
<< "});";
if (not aMessage.empty()) {
strm << "var infowindow_" + mySuffixString + " = new google.maps.InfoWindow({"
<< "content: " << WWebWidget::jsStringLiteral(aMessage) << ","
<< "size: new google.maps.Size(50,50) });"
<< "google.maps.event.addListener(marker_" + mySuffixString + ", 'click', function() {"
<< "infowindow_" + mySuffixString + ".open(" << jsRef() << ".map" << ", marker_" + mySuffixString + ");"
<< "});";
}
strm << jsRef() << ".map.overlays.push(marker_" + mySuffixString + ");";
}
doGmJavaScript(strm.str());
}
void WGoogleMap::addIconMarker(const Coordinate &pos,
const std::string& iconURL)
const std::string& iconURL,
const WString& aMessage)
{
std::stringstream strm;
......
throw std::logic_error("WGoogleMap::addIconMarker is not supported "
"in the Google Maps API v2.");
} else {
strm << "var position = new google.maps.LatLng("
<< pos.latitude() << ", " << pos.longitude() << ");"
<< "var marker = new google.maps.Marker({"
<< "position: position,"
<< "icon: \"" << iconURL << "\","
<< "map: " << jsRef() << ".map"
<< "});"
<< jsRef() << ".map.overlays.push(marker);";
// Atomically increment the index and returns the pre-increment variable value
std::string mySuffixString = boost::lexical_cast<std::string>(boost::interprocess::detail::atomic_inc32(&markerIndex_));
strm << "var position = new google.maps.LatLng("
<< pos.latitude() << ", " << pos.longitude() << ");"
<< "var marker_" + mySuffixString + " = new google.maps.Marker({"
<< "position: position,"
<< "icon: \"" << iconURL << "\","
<< "map: " << jsRef() << ".map"
<< "});";
if (not aMessage.empty()) {
strm << "var infowindow_" + mySuffixString + " = new google.maps.InfoWindow({"
<< "content: " << WWebWidget::jsStringLiteral(aMessage) << ","
<< "size: new google.maps.Size(50,50) });"
<< "google.maps.event.addListener(marker_" + mySuffixString + ", 'click', function() {"
<< "infowindow_" + mySuffixString + ".open(" << jsRef() << ".map" << ", marker_" + mySuffixString + ");"
<< "});";
}
strm << jsRef() << ".map.overlays.push(marker_" + mySuffixString + ");";
}
doGmJavaScript(strm.str());
(2-2/2)