Hi Koen,

> My fault, the version below fixes that (you should not pass on the
> parent widget to the base class if you are relying on the virtual
> load() method to be called when the widget is inserted in the widget
> hierarchy).
This works now everywhere I tested.

> I've modified the test case so that the variable will be available as
> jsRef() + ".map".
That's great news. But I couldn't figure out how to use it correctly.
Here is what I tried:

void WGoogleMap::refresh()
{
    // initialize the map
    std::ostringstream strm;
    strm << "function initialize() {"
         << "    var map = new google.maps.Map2(" << jsRef() << ");"
         << "    map.setCenter(new google.maps.LatLng(47.01887777,
8.651888), 13);"
         << "    map.enableScrollWheelZoom();"
         << "    map.addControl(new
google.maps.HierarchicalMapTypeControl());"
         <<      jsRef() << ".map = map;";
    copy(additions_.begin(), additions_.end(),
std::ostream_iterator<string>(strm));
    strm << "}";
    strm << "google.load(\"maps\", \"2\", {other_params:\"sensor=false
\", callback: initialize});";

    WApplication::instance()->doJavaScript(strm.str());
}

void WGoogleMap::addMarker(const pair<double, double> &pos)
{
    std::ostringstream strm;
    strm << "var marker = new google.maps.Marker(new
google.maps.LatLng(47.01887777, 8.651888));"
         <<  jsRef() << ".map.addOverlay(marker);";

    const string jsstr = strm.str();

    additions_.push_back(jsstr);

    WApplication::instance()->doJavaScript(jsstr);
}

void WGoogleMap::addPolyline(const vector<pair<double, double> >
&points, const string &color, int width, float opacity)
{
    opacity = std::max(std::min(opacity, 1.0), 0.0); // opacity has to
be between 0.0 and 1.0

    std::ostringstream strm;
    strm << "var waypoints = [];";
    for(size_t i=0; i<points.size(); ++i)
        strm << "waypoints[" << i << "] = new google.maps.LatLng(" <<
points[i].first << ", " << points[i].second << ");";
    strm << "var poly = new google.maps.Polyline(waypoints, \"" << color
<< "\", " << width << ", " << opacity << ");";
    strm << jsRef() << ".map.addOverlay(poly);";

    const string jsstr = "if(true){" + strm.str() + "}"; // to keep the
variables inside a scope where they don't interfere

    additions_.push_back(jsstr);

    WApplication::instance()->doJavaScript(jsstr);
} 

WApplication *createApplication( const WEnvironment& env )
{
  WApplication *app = new WApplication(env);

    Wt::WGoogleMap *gmap = new Wt::WGoogleMap(app->root());
    gmap->resize(700, 500);

    gmap->addMarker(std::make_pair(47.01887777, 8.651888));

    std::vector<std::pair<double, double> > points;
    points.push_back(std::make_pair(47.06354722, 8.647369)); 
    points.push_back(std::make_pair(47.01887777, 8.651888));
    gmap->addPolyline(points, "#FF0000", 2, 0.9);

  return app;
}

It displays the map, but instead of displaying the overlays, I get a
message saying that google.maps.LatLng is not a constructor.

I tried to do something similar in html, but didn't succeed either.

Rgds
Richard



------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to