Hi David, I suspect that you aren't getting much help because there are a bunch of issues with your code and it would take a while to identify them all and produce a working example. Here are a few things that might get you going in the right direction:
1) References to globals like google.earth... need to begin with $wnd because GWT javascript is loaded into a separate iframe. Any global APIs that you use will need $wnd in front of them like $wnd.google.earth.createInstance. 2) Your native function takes a JavaScriptObject ge and then declares a var ge that you set to null. I'm not sure what your plan is for this object, but setting it to null is probably not what you want. 3) Your method contains some var declarations and a bunch of function declarations, but as far as I can tell it doesn't do anything with them. Something needs to call your init() function. What I would suggest to get things going quickly is to move all of this Javascript into a separate javascript file included in your html page and then use $wnd.init() to call your init() method from a native JSNI method in your GWT code. Hope that helps, Andy On Jan 16, 6:27 pm, Daivd Lamm <[email protected]> wrote: > Hi guys, > > I am working on a GWT project that when the application starts up, > Google Earth is automatically loaded onto the page. After that, I want > it that the user clicks a button that says "enable polygon drawing", > the application will allow the user to be able to draw polygons on > Google Earth. > > I found an example online for creating polygons on Google Earth using > JavaScript. (http://earth-api-samples.googlecode.com/svn/trunk/demos/ > draw/index.html) However, now I need to add the JavaScript code in > that example into a GWT class (which I'm trying to do with JSNI). > > The problem is, I'm not sure how to correctly do it, I've tried adding > the JavaScript code from the example into GWT (see below) and then > just opening Google Earth in the HTML document but it doesn't seem to > work. > > If anyone can help me at all, that would be greatly appreciated! > > Thanks in advance, > David > > CODE: > > private native void polygondraw(JavaScriptObject ge) > /*-{ > var ge = null; > var isMouseDown = false; > var lineStringPlacemark = null; > var coords = null; > var pointCount = 0; > var doc = null; > > function init() { > google.earth.createInstance("map3d", initCB, failureCB); > } > function initCB(object) { > ge = object; > ge.getWindow().setVisibility(true); > > doc = ge.createDocument(''); > ge.getFeatures().appendChild(doc); > > google.earth.addEventListener(ge.getGlobe(), 'mousemove', > onmousemove); > google.earth.addEventListener(ge.getGlobe(), 'mousedown', > onmousedown); > } > > function onmousemove(event) { > if (isMouseDown) { > coords.pushLatLngAlt(event.getLatitude(), > event.getLongitude(), 0); > } > } > > function convertLineStringToPolygon(placemark) { > var polygon = > ge.createPolygon(''); > var outer = ge.createLinearRing(''); > polygon.setOuterBoundary(outer); > > var lineString = placemark.getGeometry(); > for (var i = 0; i < lineString.getCoordinates().getLength(); > i++) { > var coord = lineString.getCoordinates().get(i); > > outer.getCoordinates().pushLatLngAlt(coord.getLatitude(), > coord.getLongitude(), > coord.getAltitude()); > } > placemark.setGeometry(polygon); > } > > function onmousedown(event) { > if (isMouseDown) { > isMouseDown = false; > coords.pushLatLngAlt(event.getLatitude(), > event.getLongitude(), 0); > > convertLineStringToPolygon(lineStringPlacemark); > } else { > isMouseDown = true; > lineStringPlacemark = ge.createPlacemark(''); > var lineString = ge.createLineString(''); > lineStringPlacemark.setGeometry(lineString); > > lineString.setTessellate(true); > lineString.setAltitudeMode(ge.ALTITUDE_CLAMP_TO_GROUND); > > lineStringPlacemark.setStyleSelector(ge.createStyle('')); > var lineStyle = > lineStringPlacemark.getStyleSelector().getLineStyle(); > lineStyle.setWidth(4); > > lineStyle.getColor().set('ddffffff'); // aabbggrr > formatx > lineStyle.setColorMode(ge.COLOR_RANDOM); > var polyStyle = > lineStringPlacemark.getStyleSelector().getPolyStyle(); > polyStyle.getColor().set('ddffffff'); // aabbggrr format > polyStyle.setColorMode(ge.COLOR_RANDOM); > > coords = lineString.getCoordinates(); > coords.pushLatLngAlt(event.getLatitude(), > event.getLongitude(), 0); > > doc.getFeatures().appendChild(lineStringPlacemark); > } > } > function failureCB(object) { > } > }-*/; -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
