Hey Richard,

2009/2/2 Richard Ulrich <[email protected]>:
> Hi Koen,
>
> thanks for your help.
>
> The WGoogleMap widget works for me only with a simple test application
> where it sits directly on the app root.

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).

> Then another question: If I later want to modify the map. How do I
> reference the google maps javascript object from within c++ code?

What I find the useful method is to set the variable in the DOM node
of the widget. In that way, when the widget is deleted, the JavaScript
garbage collector will also dispose of the additional javascript
structures.

I've modified the test case so that the variable will be available as
jsRef() + ".map".

Regards,
koen

(only the WGoogleMap implementation changed):

WGoogleMap::WGoogleMap(WContainerWidget *parent)
  : WContainerWidget()
{
  WApplication *app = WApplication::instance();

  // if there is no google api key configured, use the one
  // for http://localhost:8080/
  const std::string localhost_key =
    "ABQIAAAAWqrN5o4-ISwj0Up_depYvhTwM0brOpm-All5BF6PoaKBxRWWERS"
    "-S9gPtCri-B6BZeXV8KpT4F80DQ";

  std::string googlekey;
  if (!app->readConfigurationProperty("google_api_key", googlekey))
    googlekey = localhost_key;

  // load the google javascript api script
  const std::string gmuri = "http://www.google.com/jsapi?key="; + googlekey;
  app->require(gmuri, "google");

  if (parent)
    parent->addWidget(this);
}

void WGoogleMap::load()
{
  refresh();
}

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

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

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to