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 google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to