-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15a2927
commit 944ca92
Showing
7 changed files
with
346 additions
and
1 deletion.
There are no files selected for viewing
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,69 @@ | ||
/******************************************************************************* | ||
* Copyright 2014, 2021 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.layer; | ||
|
||
import jsinterop.annotations.JsType; | ||
|
||
/** | ||
* Layer for rendering vector data as a heatmap. Note that any property set in the | ||
* options is set as a {@link ol.Object} property on the layer object; | ||
* for example, setting title: 'My Title' in the options means that title is | ||
* observable, and has get/set accessors. | ||
* | ||
* @author Tino Desjardins | ||
* | ||
*/ | ||
@JsType(isNative = true) | ||
public class Heatmap extends Vector { | ||
|
||
public Heatmap() {} | ||
|
||
public Heatmap(HeatmapOptions vectorLayerOptions) {} | ||
|
||
/** | ||
* @return blur size in pixels. | ||
*/ | ||
public native double getBlur(); | ||
|
||
/** | ||
* @param blur blur size in pixels. | ||
*/ | ||
public native void setBlur(double blur); | ||
|
||
/** | ||
* @return gradient colors. | ||
*/ | ||
public native String[] getGradient(); | ||
|
||
/** | ||
* Default gradient: {"#00f", "#0ff", "#0f0", "#ff0", "#f00"} | ||
* | ||
* @param gradient gradient colors. | ||
*/ | ||
public native void setGradient(String[] gradient); | ||
|
||
/** | ||
* @return radius size in pixels. | ||
*/ | ||
public native double getRadius(); | ||
|
||
|
||
/** | ||
* @param radius radius size in pixels. | ||
*/ | ||
public native void setRadius(double radius); | ||
|
||
} |
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,62 @@ | ||
/******************************************************************************* | ||
* Copyright 2014, 2021 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.layer; | ||
|
||
import jsinterop.annotations.JsPackage; | ||
import jsinterop.annotations.JsProperty; | ||
import jsinterop.annotations.JsType; | ||
|
||
/** | ||
* Heatmap options. | ||
* | ||
*/ | ||
@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object") | ||
public class HeatmapOptions extends VectorLayerOptions { | ||
|
||
/** | ||
* @param gradient The color gradient of the heatmap, specified as | ||
* an array of CSS color strings. | ||
*/ | ||
@JsProperty | ||
public native void setGradient(String[] gradient); | ||
|
||
/** | ||
* @param radius radius size in pixels. | ||
*/ | ||
@JsProperty | ||
public native void setRadius(double radius); | ||
|
||
/** | ||
* @param blur blur size in pixels. | ||
*/ | ||
@JsProperty | ||
public native void setBlur(double blur); | ||
|
||
/** | ||
* @param weightAttribute The feature attribute to use for the weight | ||
*/ | ||
@JsProperty | ||
public native void setWeight(String weightAttribute); | ||
|
||
/** | ||
* @param heatmapWeightFunction function that calculates a weight | ||
* from a feature. Weight values should range from 0 to 1 (and values | ||
* outside will be clamped to that range). | ||
*/ | ||
@JsProperty | ||
public native void setWeight(HeatmapWeightFunction heatmapWeightFunction); | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
gwt-ol3-client/src/main/java/ol/layer/HeatmapWeightFunction.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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/******************************************************************************* | ||
* Copyright 2014, 2021 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.layer; | ||
|
||
import jsinterop.annotations.JsFunction; | ||
import ol.Feature; | ||
|
||
/** | ||
* A function that returns a weight from a feature. Weight values should range | ||
* from 0 to 1 (and values outside will be clamped to that range) | ||
*/ | ||
@FunctionalInterface | ||
@JsFunction | ||
public interface HeatmapWeightFunction { | ||
|
||
/** | ||
* @param feature feature for calculating the weight | ||
* @return weight | ||
*/ | ||
double getWeight(Feature feature); | ||
|
||
} |
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
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,66 @@ | ||
/******************************************************************************* | ||
* Copyright 2014, 2021 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.layer; | ||
|
||
import ol.Feature; | ||
import ol.GwtOLBaseTestCase; | ||
import ol.format.Kml; | ||
import ol.source.VectorOptions; | ||
|
||
/** | ||
* A test case for {@link ol.layer.Heatmap}. | ||
* | ||
* @author Tino Desjardins | ||
* | ||
*/ | ||
public class HeatmapTest extends GwtOLBaseTestCase { | ||
|
||
public void testVectorLayer() { | ||
|
||
injectUrlAndTest(() -> { | ||
|
||
HeatmapOptions heatmapOptions = new HeatmapOptions(); | ||
assertNotNull(heatmapOptions); | ||
|
||
VectorOptions vectorOptions = new VectorOptions(); | ||
vectorOptions.setUrl("https://openlayers.org/en/latest/examples/data/kml/2012_Earthquakes_Mag5.kml"); | ||
vectorOptions.setFormat(new Kml()); | ||
ol.source.Vector vector = new ol.source.Vector(vectorOptions); | ||
|
||
heatmapOptions.setSource(vector); | ||
heatmapOptions.setBlur(2); | ||
heatmapOptions.setRadius(15); | ||
heatmapOptions.setWeight((Feature feature) -> { | ||
|
||
String magnitudeValue = feature.get("name"); | ||
String parsedMagnitude = magnitudeValue.substring(2); | ||
parsedMagnitude = parsedMagnitude.substring(0, parsedMagnitude.indexOf(" ")); | ||
|
||
return Double.parseDouble(parsedMagnitude) - 5; | ||
|
||
}); | ||
|
||
/*Heatmap heatmap = new Heatmap(heatmapOptions); | ||
assertNotNull(heatmap); | ||
assertTrue(heatmap instanceof Base); | ||
assertTrue(heatmap instanceof Layer); | ||
assertTrue(heatmap instanceof Vector);*/ | ||
|
||
}); | ||
|
||
} | ||
|
||
} |
111 changes: 111 additions & 0 deletions
111
...ol3-demo/src/main/java/com/github/tdesjardins/ol3/demo/client/example/HeatmapExample.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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/******************************************************************************* | ||
* Copyright 2014, 2021 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 com.github.tdesjardins.ol3.demo.client.example; | ||
|
||
import ol.Coordinate; | ||
import ol.Feature; | ||
import ol.source.Stamen; | ||
import ol.source.StamenOptions; | ||
import ol.source.VectorOptions; | ||
import ol.Map; | ||
import ol.MapOptions; | ||
import ol.OLFactory; | ||
import ol.View; | ||
import ol.control.MousePosition; | ||
import ol.format.Kml; | ||
import ol.format.KmlOptions; | ||
import ol.layer.Heatmap; | ||
import ol.layer.HeatmapOptions; | ||
import ol.layer.LayerOptions; | ||
import ol.layer.Tile; | ||
|
||
/** | ||
* Example with heatmap. | ||
* | ||
* @author Tino Desjardins | ||
* | ||
*/ | ||
public class HeatmapExample implements Example { | ||
|
||
/* (non-Javadoc) | ||
* @see de.desjardins.ol3.demo.client.example.Example#show() | ||
*/ | ||
@Override | ||
public void show(String exampleId) { | ||
|
||
StamenOptions stamenOptions = new StamenOptions(); | ||
stamenOptions.setLayer("toner"); | ||
|
||
Stamen stamen = new Stamen(stamenOptions); | ||
|
||
LayerOptions rasterLayerOptions = OLFactory.createOptions(); | ||
rasterLayerOptions.setSource(stamen); | ||
|
||
VectorOptions vectorOptions = new VectorOptions(); | ||
vectorOptions.setUrl("https://openlayers.org/en/latest/examples/data/kml/2012_Earthquakes_Mag5.kml"); | ||
KmlOptions kmlOptions = new KmlOptions(); | ||
kmlOptions.setExtractStyles(false); | ||
Kml kml = new Kml(kmlOptions); | ||
vectorOptions.setFormat(kml); | ||
|
||
ol.source.Vector vectorSource = new ol.source.Vector(vectorOptions); | ||
|
||
Tile stamenLayer = new Tile(rasterLayerOptions); | ||
|
||
HeatmapOptions heatmapOptions = new HeatmapOptions(); | ||
heatmapOptions.setSource(vectorSource); | ||
heatmapOptions.setBlur(15); | ||
heatmapOptions.setRadius(8); | ||
heatmapOptions.setWeight((Feature feature) -> { | ||
|
||
String magnitudeValue = feature.get("name"); | ||
String parsedMagnitude = magnitudeValue.substring(2); | ||
parsedMagnitude = parsedMagnitude.substring(0, parsedMagnitude.indexOf(" ")); | ||
|
||
return Double.parseDouble(parsedMagnitude) - 5; | ||
|
||
}); | ||
|
||
Heatmap heatmapLayer = new Heatmap(heatmapOptions); | ||
|
||
// create a view | ||
View view = new View(); | ||
|
||
Coordinate centerCoordinate = new Coordinate(0, 0); | ||
view.setCenter(centerCoordinate); | ||
view.setZoom(2); | ||
|
||
// create the map | ||
MapOptions mapOptions = OLFactory.createOptions(); | ||
mapOptions.setTarget(exampleId); | ||
mapOptions.setView(view); | ||
|
||
Map map = new Map(mapOptions); | ||
|
||
ol.control.Attribution attributionControl = new ol.control.Attribution(); | ||
attributionControl.setCollapsed(false); | ||
|
||
map.addControl(attributionControl); | ||
MousePosition mousePosition = new MousePosition(); | ||
mousePosition.setCoordinateFormat(Coordinate.createStringXY(2)); | ||
map.addControl(mousePosition); | ||
map.addLayer(stamenLayer); | ||
map.addLayer(heatmapLayer); | ||
|
||
} | ||
|
||
} | ||
|
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