]>
git.argeo.org Git - gpl/argeo-suite.git/blob - geo/ux/OpenLayersMapPart.java
1 package org
.argeo
.app
.geo
.ux
;
4 import java
.util
.function
.Consumer
;
5 import java
.util
.function
.Function
;
7 import org
.argeo
.app
.geo
.ux
.MapPart
.FeaturePopupEvent
;
8 import org
.argeo
.app
.geo
.ux
.MapPart
.FeatureSelectedEvent
;
9 import org
.argeo
.app
.geo
.ux
.MapPart
.FeatureSingleClickEvent
;
10 import org
.argeo
.app
.ol
.AbstractOlObject
;
11 import org
.argeo
.app
.ol
.Layer
;
12 import org
.argeo
.app
.ol
.OlMap
;
13 import org
.argeo
.app
.ol
.TileLayer
;
14 import org
.argeo
.app
.ol
.VectorLayer
;
15 import org
.argeo
.app
.ux
.js
.JsClient
;
16 import org
.locationtech
.jts
.geom
.Envelope
;
19 * A wrapper around an OpenLayers map, adding specific features, such as SLD
22 public class OpenLayersMapPart
extends AbstractGeoJsObject
{
23 private final String mapPartName
;
25 public OpenLayersMapPart(JsClient jsClient
, String mapPartName
) {
27 this.mapPartName
= mapPartName
;
28 create(jsClient
, mapPartName
);
31 public OlMap
getMap() {
32 return new OlMap(getJsClient(), getReference() + ".getMap()");
35 public void setSld(String xml
) {
36 executeMethod(getMethodName(), JsClient
.escapeQuotes(xml
));
39 public void setCenter(Double lat
, Double lon
) {
40 executeMethod(getMethodName(), lat
, lon
);
43 public void fit(double[] extent
, Map
<String
, Object
> options
) {
44 executeMethod(getMethodName(), extent
, options
);
47 public void fit(Envelope extent
, Map
<String
, Object
> options
) {
48 fit(new double[] { extent
.getMinX(), extent
.getMinY(), extent
.getMaxX(), extent
.getMaxY() }, options
);
51 public void applyStyle(String layerName
, String styledLayerName
) {
52 executeMethod(getMethodName(), layerName
, styledLayerName
);
55 public Layer
getLayer(String name
) {
56 // TODO deal with not found
57 String reference
= getReference() + ".getLayerByName('" + name
+ "')";
58 if (getJsClient().isInstanceOf(reference
, AbstractOlObject
.getJsClassName(VectorLayer
.class))) {
59 return new VectorLayer(getJsClient(), reference
);
60 } else if (getJsClient().isInstanceOf(reference
, AbstractOlObject
.getJsClassName(TileLayer
.class))) {
61 return new TileLayer(getJsClient(), reference
);
63 return new Layer(getJsClient(), reference
);
67 public String
getMapPartName() {
71 public void selectFeatures(String layerName
, Object
... ids
) {
72 executeMethod(getMethodName(), layerName
, (Object
[]) ids
);
78 public void onFeatureSelected(Consumer
<FeatureSelectedEvent
> toDo
) {
79 addCallback("FeatureSelected", (arr
) -> {
80 toDo
.accept(new FeatureSelectedEvent((String
) arr
[0]));
85 public void onFeatureSingleClick(Consumer
<FeatureSingleClickEvent
> toDo
) {
86 addCallback("FeatureSingleClick", (arr
) -> {
87 toDo
.accept(new FeatureSingleClickEvent((String
) arr
[0]));
92 public void onFeaturePopup(Function
<FeaturePopupEvent
, String
> toDo
) {
93 addCallback("FeaturePopup", (arr
) -> {
94 return toDo
.apply(new FeaturePopupEvent((String
) arr
[0]));
98 protected void addCallback(String suffix
, Function
<Object
[], Object
> toDo
) {
99 getJsClient().getReadyStage().thenAccept((ready
) -> {
100 String functionName
= getJsClient().createJsFunction(getMapPartName() + "__on" + suffix
, toDo
);
101 getJsClient().execute(getJsReference() + ".callbacks['on" + suffix
+ "']=" + functionName
+ ";");
102 executeMethod("enable" + suffix
);