[Qt-interest] Qt Webkit and Google Earth Plugin?
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Thu May 20 18:11:45 CEST 2010
Knoll Oliver, ITS-CMT-SUI-SL-SFR-FIN-DEV wrote on Thursday, May 20, 2010 5:30 PM:
Let's assume for now that the Google Earth Plugin would work within Qt/WebKit:
> So if I had a Html page with the Google Earth Plugin embedded and a
> JavaScript method "getView" defined therein (in the HTML) [...]
> How would I invoke such a JavaScript method from the C++ world?
As to make my previous confuse questions more precise, I have a working example, see below HTML code: it invokes the Google Earth Plugin and provides a button, which triggers a dialog displaying the current coordinates (latitude/longitude) - easy.
So my goal would be to call/evaluate my custom JavaScript function 'getLookAt' (which currently does not return anything, but just assume it /would/ return whatever is returned by "copyAsLookAt") which is currently triggered within a browser when clicking the button.
Question: so how would I invoke such a "JavaScript function within a HTML page" and extract the returned value into the "C++ world"?
I do see that I can get access to the elements (nodes) of a given page in QWebView, I do understand that with QScriptEnginve::evaluate() I can evaluate a given JavaScript code. But "how does it play together"? I mean, I can't just say e.g.
QScriptEngine *engine = ...;
// Let's assume this would extract the "getLookAt" function, see example code below
QString javaScript = extractJavaScriptFunctionFromWebPage("getLookAt", ...);
QScriptValue res = engine->evaluate(javaScript);
because that JavaScript snippet would be totally "out of context"? Even if I would load the entire JavaScript <script>....</script> part and then evaluate the getLookAt() function, how would the QScriptEngine know about the Google Earth Plugin instance in the HTML page - well, it wouldn't, right?
Here is the example HTML (adapted from http://earth-api-samples.googlecode.com/svn/trunk/demos/helloearth/index.html), you can open it in a browser (and are likely to be asked to download the Google Earth Plugin, if you don't have it):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<head>
<title>Get LookAt</title>
<!-- *** Replace the key below below with your own API key, available at http://code.google.com/apis/maps/signup.html *** -->
<script src="http://www.google.com/jsapi?key=ABQIAAAAwbkbZLyhsmTCWXbTcjbgbRSzHs7K5SvaUdm8ua-Xxy_-2dYwMxQMhnagaawTo7L1FE1-amhuQxIlXw"></script>
<script>
google.load("earth", "1");
var ge = null;
function init() {
google.earth.createInstance("map3d", initCallback, failureCallback);
}
function initCallback(object) {
ge = object;
ge.getWindow().setVisibility(true);
}
function getLookAt() {
var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
alert('Latitude: ' + lookAt.getLatitude() + ' Longitude: ' + lookAt.getLongitude());
}
function failureCallback(object) {}
</script>
</head>
<body onload='init()' id='body'>
<div id='map3d' style='border: 1px solid silver; height: 600px; width: 800px;'></div>
<form>
<div>
<button name="LookAtButton" type="button" value="" onclick="getLookAt();">
<p>Get LookAt</p>
</button>
</div>
</form>
</body>
</html>
Thanks,
Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list