Skip to content

Commit

Permalink
fix GeoJSONOptions functions and removedependency on Function and Jav…
Browse files Browse the repository at this point in the history
…aScriptObject
  • Loading branch information
zak905 committed Jun 28, 2021
1 parent 267810b commit dd02c08
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 67 deletions.
187 changes: 120 additions & 67 deletions src/main/java/com/gwidgets/api/leaflet/options/GeoJSONOptions.java
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);
}

}
10 changes: 10 additions & 0 deletions src/main/java/com/gwidgets/api/leaflet/utils/JsFn.java
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);

}

0 comments on commit dd02c08

Please sign in to comment.