Skip to content

Commit

Permalink
Add FeatureUrlFunction and LoadingStrategy support
Browse files Browse the repository at this point in the history
  • Loading branch information
TDesjardins committed Jun 27, 2023
1 parent 813ae6e commit a60f5b4
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright 2014, 2023 gwt-ol
*
* 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 ol.loadingstrategy;

import jsinterop.annotations.JsOverlay;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;


@JsType(isNative = true)
public class LoadingStrategy {

@JsOverlay
private static final String PACKAGE_LOADING_STRATEGY = "ol.loadingstrategy";

/**
* @return Strategy function for loading all features with a single request.
*/
@JsProperty(name = "all", namespace = PACKAGE_LOADING_STRATEGY)
public static native LoadingStrategyFunction getAll();

/**
* @return Strategy function for loading features based on the view's extent and
* resolution.
*/
@JsProperty(name = "bbox", namespace = PACKAGE_LOADING_STRATEGY)
public static native LoadingStrategyFunction getBbox();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright 2014, 2023 gwt-ol
*
* 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 ol.loadingstrategy;

import jsinterop.annotations.JsFunction;
import ol.Extent;

@FunctionalInterface
@JsFunction
public interface LoadingStrategyFunction {

/**
*
* @param extent
* @param resolution
* @return
*/
Extent[] getExtents(Extent extent, double resolution);

}
38 changes: 38 additions & 0 deletions gwt-ol3-client/src/main/java/ol/source/FeatureUrlFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright 2014, 2023 gwt-ol
*
* 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 ol.source;

import jsinterop.annotations.JsFunction;
import ol.Extent;
import ol.proj.Projection;

/**
*
*
* {@link ol.source.Vector} sources use a function of this type to get the url to load features from.
*/
@FunctionalInterface
@JsFunction
public interface FeatureUrlFunction {

/**
* @param extent area to be loaded
* @param resolution resolution (map units per pixel)
* @param projection projection
* @return URL
*/
String getUrl(Extent extent, double resolution, Projection projection);
}
13 changes: 13 additions & 0 deletions gwt-ol3-client/src/main/java/ol/source/VectorOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import ol.Collection;
import ol.Feature;
import ol.featureloader.FeatureLoader;
import ol.loadingstrategy.LoadingStrategyFunction;

/**
* Vector source options.
Expand All @@ -43,6 +44,9 @@ public class VectorOptions extends SourceOptions {
@JsProperty
public native void setUrl(String url);

@JsProperty
public native void setUrl(FeatureUrlFunction featureUrlFunction);

@JsProperty
public native void setFormat(ol.format.Feature format);

Expand Down Expand Up @@ -75,4 +79,13 @@ public class VectorOptions extends SourceOptions {
*/
@JsProperty
public native void setLoader(FeatureLoader featureLoader);

/**
* The loading strategy to use. By default an all strategy is used, a one-off strategy which loads all features at once.
*
* @param loadingStrategy
*/
@JsProperty
public native void setStrategy(LoadingStrategyFunction loadingStrategy);

}
3 changes: 3 additions & 0 deletions gwt-ol3-client/src/test/java/ol/GwtOLTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import ol.interaction.SnapTest;
import ol.interaction.TranslateTest;
import ol.layer.LayerGroupTest;
import ol.loadingstrategy.LoadingStrategyTest;
import ol.proj.ProjectionTest;
import ol.source.BingMapsTest;
import ol.source.ClusterTest;
Expand Down Expand Up @@ -172,6 +173,8 @@ public static TestSuite suite() {
suite.addTestSuite(ol.layer.VectorTest.class);
suite.addTestSuite(ol.layer.VectorTileTest.class);

suite.addTestSuite(LoadingStrategyTest.class);

// source
suite.addTestSuite(BingMapsTest.class);
suite.addTestSuite(ClusterTest.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright 2014, 2023 gwt-ol
*
* 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 ol.loadingstrategy;

import ol.GwtOLBaseTestCase;

/**
* Test for loading strategies.
*
* @author TDesjardins
*
*/
public class LoadingStrategyTest extends GwtOLBaseTestCase {

public void testLoadinStrategy() {

this.injectUrlAndTest(() -> {

assertNotNull(LoadingStrategy.getAll());
assertNotNull(LoadingStrategy.getBbox());

});

}

}

0 comments on commit a60f5b4

Please sign in to comment.