Zn2O / gwt-google-apis

Automatically exported from code.google.com/p/gwt-google-apis
0 stars 0 forks source link

Add support for Google Earth object #133

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Found in Release:
0.0.29, trunk

Detailed description:
The GEarth object GMap2.getEarthInstance() is not supported in gwt-maps. 
It should be a simple matter to start working on a JSFlyweightWrapper class
to expose GEarth methods.  It is currently believed that the MapWidget
should own an Earth instance, just as the GoogleMapsAPI GMap2 owns its
GEarth instance.

Workaround if you have one:
Working on an Earth.java and an EarthImpl.java right now, in the same
JSFlyweightWrapper vein followed by the MapWidget/MapImpl classes.  Main
issue already encountered is the necessity of having a good way of knowing
if the earthInstance has already been instantiated to avoid executing
GMap2.getEarthInstance(getEarthInstanceCB) more than once.  The (slightly
ugly) code-around thus far is to add a hasEarthInstance() method to the
gwt-maps MapWidget and using a Timer in the external accessing code keep
checking for the presence of the earthInstance to avoid calling
getEarthInstance more than once.  Better would be to have
MapWidget.getEarthInstance() only call MapImpl.impl.getEarthInstance(cb)
once.  In Java, I would want to synchronize the MapWidget.getEarthInstance
method; does that have any effect in GWT?  If not, then a boolean
gettingEarthInstance flag could be used.

(bad) example access code:

    mapWidget.addMapTypeChangedHandler(new MapTypeChangedHandler() {
      public void onTypeChanged(MapTypeChangedEvent event) {
        if
(event.getSender().getCurrentMapType().equals(MapType.getEarthMap())) {
          // only do this once?
          if (!mapWidget.hasEarthInstance()) {
            // call getEarthInstance once to init it
            mapWidget.getEarthInstance();
            final Timer earthTimer = new Timer() {
              public void run() {
                if (mapWidget.hasEarthInstance()) {
                  this.cancel();
                  // do some earth init
                  // maybe do earth-specific overlays and kml?
                } else {
                  // still waiting for earth instance
                }
              }
            };
            earthTimer.scheduleRepeating(3333);
          }
        }
      }
    });

Original issue reported on code.google.com by jesse.cr...@gmail.com on 12 Jun 2008 at 5:51

GoogleCodeExporter commented 9 years ago
this should be marked as an Enhancement.

Original comment by jesse.cr...@gmail.com on 12 Jun 2008 at 5:56

GoogleCodeExporter commented 9 years ago

Original comment by galgwt.reviews@gmail.com on 12 Jun 2008 at 7:54

GoogleCodeExporter commented 9 years ago
w/r/t the use of a timer to detect when the load is complete:  See the 
Directions
class for how we've handled similar situations in the past.  

What we've done is to use a static method to initiate the load, and when the 
load
completes, pass back the instance in the callback.  I am willing to bet there 
is a
"load" event that fires when the Earth instance is ready (the Maps team isn't 
really
great about documenting all these niceties).

Original comment by galgwt.reviews@gmail.com on 14 Jun 2008 at 10:57

GoogleCodeExporter commented 9 years ago
Since the Earth instance intializing works,  the getEarthInstanceCallback has 
yet to
benefit from other Callback patterns in gwt-maps and I've pushed forward to 
other
problems.

The current sticky wicket is what to do with the ge constants 
(ALTITUDE_ABSOLUTE,
ALTITUDE_CLAMP_TO_GROUND, etc.) and how to properly expose them.  It would 
appear
that the constants are part of the ge object itself (see
http://code.google.com/apis/earth/documentation/advanced.html#ground_overlay,
specifically this line: 
var center = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);

I don't see a clear pattern to follow anywhere else in the gwt-maps code base.  
Most
constants and enums are static classes (MapPaneType is an actual enum, but it 
uses
static JavaScript constants from the $wnd object) but I'm not sure how to handle
constants that are fields of an instance (not static).

The quick-and-dirty workaround i'm going to try is creating public final ints or
strings on the Earth java object using the values panned out of the JavaScript 
ge
object.  I'll try changing method signatures that use the *Enum objects listed 
in the
Earth API Reference to use plain ints and Strings.

Original comment by jesse.cr...@gmail.com on 16 Jun 2008 at 9:27

GoogleCodeExporter commented 9 years ago
Peeking under the skirts and using the constants directly should be a last 
resort.

Take a look at MapType.java.  You could use that pattern, and just change the 
getters from static to class members.  Or, we could create static members, but 
lazy 
init them after the getEarthInstanceCallback() is invoked.  My preference is 
for 
getters().

Original comment by ericzun...@gmail.com on 16 Jun 2008 at 11:07

GoogleCodeExporter commented 9 years ago
The attached patch updates the MapWidget to return a JavaScriptObject. There is 
no 
wrapping attempted for the GEPlugin object.  Any work you do with maps must be
done in JavaScript in a JSNI method (or write your own bindings)

The patch adds a demo of using the plugin that sets a marker using JSNI.

Original comment by galgwt.reviews@gmail.com on 18 Sep 2008 at 6:43

Attachments:

GoogleCodeExporter commented 9 years ago
The MapType for GoogleEarth is in (will be released in Maps 1.0RC1) and a method
to retrieve the Google Earth plugin object was committed as r803.

Original comment by galgwt.reviews@gmail.com on 18 Sep 2008 at 8:25

GoogleCodeExporter commented 9 years ago

Original comment by galgwt.reviews@gmail.com on 13 Oct 2008 at 8:54

GoogleCodeExporter commented 9 years ago

Original comment by galgwt.reviews@gmail.com on 11 Dec 2008 at 3:08

GoogleCodeExporter commented 9 years ago

Original comment by zundel@google.com on 21 Dec 2009 at 1:57