-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix GeoJSONOptions functions and removedependency on Function and Jav…
…aScriptObject
- Loading branch information
Showing
2 changed files
with
130 additions
and
67 deletions.
There are no files selected for viewing
187 changes: 120 additions & 67 deletions
187
src/main/java/com/gwidgets/api/leaflet/options/GeoJSONOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,131 @@ | ||
/** | ||
* Copyright 2016 G-Widgets | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.gwidgets.api.leaflet.options; | ||
|
||
import static jsinterop.annotations.JsPackage.GLOBAL; | ||
|
||
import com.google.gwt.core.client.JavaScriptObject; | ||
import com.google.gwt.core.client.JsArray; | ||
import com.gwidgets.api.leaflet.LatLng; | ||
import com.gwidgets.api.leaflet.Layer; | ||
import com.gwidgets.api.leaflet.Marker; | ||
import com.gwidgets.api.leaflet.utils.JsFn; | ||
|
||
import elemental2.core.Function; | ||
import elemental2.core.JsObject; | ||
import jsinterop.annotations.JsFunction; | ||
import jsinterop.annotations.JsOverlay; | ||
import jsinterop.annotations.JsProperty; | ||
import jsinterop.annotations.JsType; | ||
|
||
import static jsinterop.annotations.JsPackage.GLOBAL; | ||
|
||
/** | ||
* The Interface GeoJSONOptions. | ||
* | ||
* | ||
* @author <a href="mailto:zakaria.amine88@gmail.com">Zakaria Amine</a> | ||
*/ | ||
@JsType(isNative=true, namespace=GLOBAL, name="Object") | ||
public interface GeoJSONOptions { | ||
|
||
/** | ||
* Function that will be used for creating layers for GeoJSON points (if not specified, simple markers will be created). | ||
* | ||
* @param featureData the feature data | ||
* @param latlng the latlng | ||
* @return the function | ||
*/ | ||
public Function pointToLayer(JavaScriptObject featureData, LatLng latlng); | ||
|
||
/** | ||
* Function that will be used to get style options for vector layers created for GeoJSON features. | ||
* | ||
* @param featureData the feature data | ||
* @return the function | ||
*/ | ||
public Function style(JavaScriptObject featureData); | ||
|
||
/** | ||
* Function that will be called on each created feature layer. Useful for attaching events and popups to features. | ||
* | ||
* @param featureData the feature data | ||
* @param layer the layer | ||
* @return the function | ||
*/ | ||
public Function onEachFeature(JavaScriptObject featureData, Layer layer); | ||
|
||
/** | ||
* Function that will be used to decide whether to show a feature or not. | ||
* | ||
* @param featureData the feature data | ||
* @param layer the layer | ||
* @return the function | ||
*/ | ||
public Function filter(JavaScriptObject featureData, Layer layer); | ||
|
||
/** | ||
* Function that will be used for converting GeoJSON coordinates to LatLng points (if not specified, coords will be assumed to be WGS84 standard [longitude, latitude] values in degrees). | ||
* | ||
* @param coords the coords | ||
* @return the function | ||
*/ | ||
public Function coordsToLatLng(JsArray<JavaScriptObject> coords); | ||
|
||
} | ||
@JsType(isNative = true, namespace = GLOBAL, name = "Object") | ||
public class GeoJSONOptions { | ||
|
||
@JsProperty | ||
String attribution; | ||
|
||
@JsProperty | ||
String pane; | ||
|
||
|
||
/** | ||
* By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. | ||
* | ||
* @return the attribution | ||
*/ | ||
@JsOverlay | ||
public final String getAttribution() { | ||
return this.attribution; | ||
} | ||
|
||
/** | ||
* String to be shown in the attribution control, describes the layer data, e.g. "© Mapbox". | ||
* | ||
* @return the attribution | ||
*/ | ||
@JsOverlay public final String getPane() { | ||
return this.pane; | ||
} | ||
|
||
/** | ||
* Function that will be used for creating layers for GeoJSON points (if not specified, simple markers will be created). | ||
* | ||
* @param featureData the feature data | ||
* @param latlng the latlng | ||
* @return the function | ||
*/ | ||
@JsProperty | ||
public PointToLayerFunction pointToLayer; | ||
|
||
/** | ||
* Function that will be used to get style options for vector layers created for GeoJSON features. | ||
* | ||
* @param featureData the feature data | ||
* @return the function | ||
*/ | ||
@JsProperty | ||
public StyleFunction style; | ||
|
||
/** | ||
* Function that will be called on each created feature layer. Useful for attaching events and popups to features. | ||
* | ||
* @param featureData the feature data | ||
* @param layer the layer | ||
* @return the function | ||
*/ | ||
@JsProperty | ||
public OnEachFeatureFunction onEachFeature; | ||
|
||
/** | ||
* Function that will be used to decide whether to show a feature or not. | ||
* | ||
* @param featureData the feature data | ||
* @param layer the layer | ||
* @return the function | ||
*/ | ||
@JsProperty | ||
public FilterFunction filter; | ||
|
||
/** | ||
* Function that will be used for converting GeoJSON coordinates to LatLng points (if not specified, coords will be assumed to be WGS84 standard [longitude, latitude] values in degrees). | ||
* | ||
* @param coords the coords | ||
* @return the function | ||
*/ | ||
@JsProperty | ||
public CoordsToLatLngFunction coordsToLatLng; | ||
|
||
@JsFunction | ||
public interface PointToLayerFunction { | ||
|
||
Marker apply(JsObject feature, LatLng latLng); | ||
|
||
} | ||
|
||
@JsFunction | ||
public interface StyleFunction { | ||
|
||
JsObject apply(JsObject feature); | ||
|
||
} | ||
|
||
@JsFunction | ||
public interface OnEachFeatureFunction { | ||
|
||
JsObject apply(JsObject feature, Layer layer); | ||
|
||
} | ||
|
||
@JsFunction | ||
public interface FilterFunction { | ||
|
||
JsObject apply(JsObject feature, Layer layer); | ||
|
||
} | ||
|
||
@JsFunction | ||
public interface CoordsToLatLngFunction { | ||
LatLng apply(JsObject feature, Layer layer); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.gwidgets.api.leaflet.utils; | ||
|
||
import jsinterop.annotations.JsFunction; | ||
|
||
@JsFunction | ||
public interface JsFn { | ||
|
||
Object apply(Object ... arg1); | ||
|
||
} |