001    package com.google.gwt.maps.client.services;
002    
003    import com.google.gwt.core.client.JavaScriptObject;
004    import com.google.gwt.core.client.JsArray;
005    import com.google.gwt.maps.client.workaround.WorkAroundUtils;
006    
007    /**
008     * Defines a service class that talks directly to Google servers for requesting elevation data.
009     * <br><br>
010     * See <a href="https://developers.google.com/maps/documentation/javascript/reference#ElevationService">ElevationService API Doc</a>
011     */
012    public class ElevationService extends JavaScriptObject {
013      
014      /**
015       * use newInstance();
016       */
017      protected ElevationService() {}
018    
019      /**
020       * Creates a new instance of a ElevationService that sends elevation queries to Google servers.
021       */
022      public static final ElevationService newInstance() {
023        JavaScriptObject jso = createJso();
024        WorkAroundUtils.removeGwtObjectId(jso);
025        return jso.cast();
026      }
027    
028      private static final native JavaScriptObject createJso() /*-{
029        return new $wnd.google.maps.ElevationService();
030      }-*/;
031    
032      /**
033       * Makes an elevation request along a path, where the elevation data are returned as distance-based samples along that path.
034       * @param request
035       * @param handler
036       */
037      public final native void getElevationAlongPath(PathElevationRequest request, ElevationServiceHandler handler) /*-{
038        var callback = function(result, status) {
039          @com.google.gwt.maps.client.services.ElevationService::processHandler(Lcom/google/gwt/core/client/JsArray;Ljava/lang/String;Lcom/google/gwt/maps/client/services/ElevationServiceHandler;)(result, status, handler);
040        };
041        this.getElevationAlongPath(request, callback);
042      }-*/;
043        
044      /**
045       * Makes an elevation request for a list of discrete locations.
046       * @param request
047       * @param handler
048       */
049      public final native void getElevationForLocations(LocationElevationRequest request, ElevationServiceHandler handler) /*-{
050        var callback = function(result, status) {
051          @com.google.gwt.maps.client.services.ElevationService::processHandler(Lcom/google/gwt/core/client/JsArray;Ljava/lang/String;Lcom/google/gwt/maps/client/services/ElevationServiceHandler;)(result, status, handler);
052        };
053        this.getElevationForLocations(request, callback);
054      }-*/;
055      
056      private final static void processHandler(JsArray<ElevationResult> result, String status, ElevationServiceHandler handler) {
057        handler.onCallback(result, ElevationStatus.fromValue(status));
058      }
059      
060    }