Skip to content

Commit

Permalink
use JsObject instead of JavaScriptObject and use custom @JsFunction i…
Browse files Browse the repository at this point in the history
…nstead of elemental2.core.Function
  • Loading branch information
zak905 committed Jun 28, 2021
1 parent dd02c08 commit 642fc01
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 80 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/gwidgets/api/leaflet/CircleMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.google.gwt.core.client.JavaScriptObject;
import com.gwidgets.api.leaflet.events.EventCallback;
import com.gwidgets.api.leaflet.options.PopupOptions;
import com.gwidgets.api.leaflet.options.TooltipOptions;

import elemental2.core.JsObject;
import elemental2.dom.HTMLElement;
import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsType;
Expand Down Expand Up @@ -82,7 +82,7 @@ protected CircleMarker() {
* @return the object
*/
@JsMethod
public native JavaScriptObject toGeoJSON();
public native JsObject toGeoJSON();


/* (non-Javadoc)
Expand Down
25 changes: 12 additions & 13 deletions src/main/java/com/gwidgets/api/leaflet/GeoJSON.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.gwidgets.api.leaflet;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;

import elemental2.core.Function;
/**
* Copyright 2016 G-Widgets
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,6 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.gwidgets.api.leaflet.options.GeoJSONOptions;

import elemental2.core.JsObject;
import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsType;

Expand All @@ -41,7 +40,7 @@ private GeoJSON() {
* @return the L class
*/
@JsMethod
public native L addData(JavaScriptObject data);
public native L addData(JsObject data);

/**
* Changes styles of GeoJSON vector layers with the given style function.
Expand All @@ -50,7 +49,7 @@ private GeoJSON() {
* @return the L class
*/
@JsMethod
public native L setStyle(Function style);
public native L setStyle(GeoJSONOptions.StyleFunction style);

/**
* Resets the given vector layer's style to the original GeoJSON style, useful for resetting style after hover events.
Expand All @@ -69,8 +68,8 @@ private GeoJSON() {
* @return the layer
*/
@JsMethod
public native static Layer geometryToLayer(JavaScriptObject featureData,
Function pointToLayer);
public native static Layer geometryToLayer(JsObject featureData,
GeoJSONOptions.PointToLayerFunction pointToLayer);

/**
* Creates a LatLng object from an array of 2 numbers (latitude, longitude) used in GeoJSON for points. If reverse is set to true, the numbers will be interpreted as (longitude, latitude).
Expand All @@ -90,8 +89,8 @@ public native static Layer geometryToLayer(JavaScriptObject featureData,
* @return js array of coordinates
*/
@JsMethod
public native static JsArray<JavaScriptObject> coordsToLatlngs(JsArray<JavaScriptObject> coords, double levelsDeep,
Function coordsToLatlngs);
public native static JsObject[] coordsToLatlngs(JsObject[] coords, double levelsDeep,
GeoJSONOptions.CoordsToLatLngFunction coordsToLatlngs);


/**
Expand All @@ -101,7 +100,7 @@ public native static JsArray<JavaScriptObject> coordsToLatlngs(JsArray<JavaScrip
* @return the js array
*/
@JsMethod
public native JsArray<JavaScriptObject> latLngToCoords(LatLng latlng);
public native JsObject[] latLngToCoords(LatLng latlng);


/**
Expand All @@ -113,7 +112,7 @@ public native static JsArray<JavaScriptObject> coordsToLatlngs(JsArray<JavaScrip
* @return the js array
*/
@JsMethod
public native JsArray<JavaScriptObject> latLngsToCoords(JsArray<JavaScriptObject> latlngs, double levelsDeep, Boolean closed);
public native JsObject[] latLngsToCoords(JsObject[] latlngs, double levelsDeep, Boolean closed);


/**
Expand All @@ -123,7 +122,7 @@ public native static JsArray<JavaScriptObject> coordsToLatlngs(JsArray<JavaScrip
* @return the java script object
*/
@JsMethod
public native JavaScriptObject asFeature(JavaScriptObject geojson);
public native JsObject asFeature(JsObject geojson);



Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/gwidgets/api/leaflet/GridLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import com.gwidgets.api.leaflet.events.EventCallback;
import com.gwidgets.api.leaflet.options.PopupOptions;
import com.gwidgets.api.leaflet.options.TooltipOptions;
import com.gwidgets.api.leaflet.utils.JsFn;

import elemental2.core.JsObject;
import elemental2.dom.HTMLElement;
import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsType;
import jsinterop.base.JsForEachCallbackFn;

@JsType(isNative=true)
public class GridLayer implements Layer, Evented{
Expand Down Expand Up @@ -78,10 +81,9 @@ protected GridLayer() {
*/
@JsMethod
public native Point getTileSize();


//looking for a solution
//public HTMLElement createTile(Object coords, Function done);

@JsMethod
public native HTMLElement createTile(JsObject coords, JsFn doneCallback);


/**
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/gwidgets/api/leaflet/L.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.gwidgets.api.leaflet;

import com.google.gwt.core.client.JavaScriptObject;
import com.gwidgets.api.leaflet.options.CircleOptions;
import com.gwidgets.api.leaflet.options.ControlAttributionOptions;
import com.gwidgets.api.leaflet.options.ControlLayersOptions;
Expand All @@ -22,6 +21,7 @@
import com.gwidgets.api.leaflet.options.TileLayerWMSOptions;
import com.gwidgets.api.leaflet.options.TooltipOptions;

import elemental2.core.JsObject;
import elemental2.dom.HTMLElement;
import jsinterop.annotations.JsConstructor;

Expand Down Expand Up @@ -200,7 +200,7 @@ public static native CircleMarker circleMarker(LatLng latlng,
* @param options the GeoJSON options
* @return a new GeoJSON object
*/
public static native GeoJSON geoJSON(JavaScriptObject geojson, GeoJSONOptions options);
public static native GeoJSON geoJSON(JsObject geojson, GeoJSONOptions options);

/**
* Represents a geographical point with a certain latitude and longitude.
Expand Down Expand Up @@ -363,8 +363,8 @@ public static native Attribution attribution(
* @return a new Layers object
*/
@JsMethod
public static native Layers layers(JavaScriptObject baseLayers,
JavaScriptObject overlays, ControlLayersOptions options);
public static native Layers layers(JsObject baseLayers,
JsObject overlays, ControlLayersOptions options);

/**
* A simple scale control that shows the scale of the current center of screen in metric (m/km) and imperial (mi/ft) systems. Extends Control.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/gwidgets/api/leaflet/LayerGroup.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.gwidgets.api.leaflet;

import com.google.gwt.core.client.JavaScriptObject;
import com.gwidgets.api.leaflet.events.EventCallback;
import com.gwidgets.api.leaflet.options.PopupOptions;
import com.gwidgets.api.leaflet.options.TooltipOptions;

import elemental2.core.Function;
import elemental2.core.JsObject;
import elemental2.dom.HTMLElement;
/**
* Copyright 2016 G-Widgets
Expand Down Expand Up @@ -102,15 +102,15 @@ public class LayerGroup implements Layer, Evented {
* @return the l
*/
@JsMethod
public native L eachLayer(Function fn, JavaScriptObject context);
public native L eachLayer(Function fn, JsObject context);

/**
* Returns a GeoJSON representation of the layer group (GeoJSON FeatureCollection).
*
* @return the object
*/
@JsMethod
public native JavaScriptObject toGeoJSON();
public native JsObject toGeoJSON();


/**
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/com/gwidgets/api/leaflet/Map.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.gwidgets.api.leaflet;

import com.google.gwt.core.client.JavaScriptObject;
import com.gwidgets.api.leaflet.events.EventCallback;
import com.gwidgets.api.leaflet.events.MouseEvent;
import com.gwidgets.api.leaflet.options.FitBoundsOptions;
Expand All @@ -9,8 +8,9 @@
import com.gwidgets.api.leaflet.options.PopupOptions;
import com.gwidgets.api.leaflet.options.ZoomOptions;
import com.gwidgets.api.leaflet.options.ZoomPanOptions;
import com.gwidgets.api.leaflet.utils.JsFn;

import elemental2.core.Function;
import elemental2.core.JsObject;
import elemental2.dom.HTMLElement;
/**
* Copyright 2016 G-Widgets
Expand All @@ -26,6 +26,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import jsinterop.annotations.JsFunction;
import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;
Expand Down Expand Up @@ -357,7 +358,7 @@ public native L setZoomAround(LatLng latlng, double zoom,
* @return true/false
*/
@JsMethod
public native Boolean eachLayer(Function action, JavaScriptObject context);
public native Boolean eachLayer(EachLayerFunction action, JsObject context);

/**
* Opens the specified popup while closing the previously opened (to make sure only one is opened at one time for usability).
Expand Down Expand Up @@ -564,7 +565,7 @@ public native L openPopup(HTMLElement el, LatLng latlng,
* @return the L class
*/
@JsMethod
public native L whenReady(Function fn, Object context);
public native L whenReady(JsFn fn, Object context);

// Events
/* (non-Javadoc)
Expand Down Expand Up @@ -626,5 +627,12 @@ public native L openPopup(HTMLElement el, LatLng latlng,
*/
public native L removeEventParent(Evented obj);

@JsFunction
public interface EachLayerFunction {

void apply(Layer layer);

}


}
4 changes: 2 additions & 2 deletions src/main/java/com/gwidgets/api/leaflet/Marker.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.gwidgets.api.leaflet;

import com.google.gwt.core.client.JavaScriptObject;
import com.gwidgets.api.leaflet.events.EventCallback;
import com.gwidgets.api.leaflet.options.PopupOptions;
import com.gwidgets.api.leaflet.options.TooltipOptions;

import elemental2.core.JsObject;
import elemental2.dom.HTMLElement;
/**
* Copyright 2016 G-Widgets
Expand Down Expand Up @@ -136,7 +136,7 @@ private Marker() {
* @return the object
*/
@JsMethod
public native JavaScriptObject toGeoJSON();
public native JsObject toGeoJSON();


// Events
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/gwidgets/api/leaflet/Polygon.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.gwidgets.api.leaflet;

import com.google.gwt.core.client.JavaScriptObject;

/**
* Copyright 2016 G-Widgets
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import elemental2.core.JsObject;
import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsType;

Expand All @@ -38,6 +37,6 @@ protected Polygon() {
* @see com.gwidgets.api.leaflet.Polyline#toGeoJSON()
*/
@JsMethod
public native JavaScriptObject toGeoJSON();
public native JsObject toGeoJSON();

}
4 changes: 2 additions & 2 deletions src/main/java/com/gwidgets/api/leaflet/Polyline.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.google.gwt.core.client.JavaScriptObject;
import com.gwidgets.api.leaflet.events.EventCallback;
import com.gwidgets.api.leaflet.options.PopupOptions;
import com.gwidgets.api.leaflet.options.TooltipOptions;

import elemental2.core.JsObject;
import elemental2.dom.HTMLElement;
import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsType;
Expand Down Expand Up @@ -87,7 +87,7 @@ public native LatLng[] spliceLatLngs(double index, double pointsToRemove,
* @return the object
*/
@JsMethod
public native JavaScriptObject toGeoJSON();
public native JsObject toGeoJSON();

/* (non-Javadoc)
* @see com.gwidgets.api.leaflet.Layer#bindPopup(com.gwidgets.api.leaflet.elemental.HTMLElement, com.gwidgets.api.leaflet.options.PopupOptions)
Expand Down
Loading

0 comments on commit 642fc01

Please sign in to comment.