]>
git.argeo.org Git - gpl/argeo-suite.git/blob - SwtJSMapPart.java
ece95085a9b0b002bcbad9f0b832a5a2baab445e
1 package org
.argeo
.app
.geo
.swt
;
3 import java
.util
.concurrent
.CompletionStage
;
4 import java
.util
.function
.Consumer
;
5 import java
.util
.function
.Function
;
6 import org
.argeo
.app
.geo
.GeoUtils
;
7 import org
.argeo
.app
.geo
.ux
.JsImplementation
;
8 import org
.argeo
.app
.geo
.ux
.MapPart
;
9 import org
.argeo
.app
.swt
.js
.SwtBrowserJsPart
;
10 import org
.eclipse
.swt
.widgets
.Composite
;
13 * An SWT implementation of {@link MapPart} based on JavaScript.
15 public class SwtJSMapPart
extends SwtBrowserJsPart
implements MapPart
{
16 static final long serialVersionUID
= 2713128477504858552L;
18 private String jsImplementation
= JsImplementation
.OPENLAYERS_MAP_PART
.getJsClass();
19 private final String mapName
;// = "argeoMap";
21 public SwtJSMapPart(String mapName
, Composite parent
, int style
) {
22 super(parent
, style
, "/pkg/org.argeo.app.geo.js/index.html");
23 this.mapName
= mapName
;
27 protected void init() {
29 doExecute(getJsMapVar() + " = new " + jsImplementation
+ "('" + mapName
+ "');");
37 public void addPoint(double lng
, double lat
, String style
) {
38 callMapMethod("addPoint(%f, %f, %s)", lng
, lat
, style
== null ?
"'default'" : style
);
42 public void addUrlLayer(String url
, GeoFormat format
, String style
) {
43 callMapMethod("addUrlLayer('%s', '%s', %s, false)", url
, format
.name(), style
);
46 public void addCssUrlLayer(String url
, GeoFormat format
, String css
) {
47 String style
= GeoUtils
.createSldFromCss("layer", "Layer", css
);
48 callMapMethod("addUrlLayer('%s', '%s', '%s', true)", url
, format
.name(), style
);
52 public void setZoom(int zoom
) {
53 callMapMethod("setZoom(%d)", zoom
);
57 public void setCenter(double lng
, double lat
) {
58 callMapMethod("setCenter(%f, %f)", lng
, lat
);
61 protected CompletionStage
<Object
> callMapMethod(String methodCall
, Object
... args
) {
62 return callMethod(getJsMapVar(), methodCall
, args
);
65 private String
getJsMapVar() {
66 return getJsVarName(mapName
);
72 public void onFeatureSelected(Consumer
<FeatureSelectedEvent
> toDo
) {
73 addCallback("FeatureSelected", (arr
) -> {
74 toDo
.accept(new FeatureSelectedEvent((String
) arr
[0]));
79 public void onFeatureSingleClick(Consumer
<FeatureSingleClickEvent
> toDo
) {
80 addCallback("FeatureSingleClick", (arr
) -> {
81 toDo
.accept(new FeatureSingleClickEvent((String
) arr
[0]));
86 public void onFeaturePopup(Function
<FeaturePopupEvent
, String
> toDo
) {
87 addCallback("FeaturePopup", (arr
) -> {
88 return toDo
.apply(new FeaturePopupEvent((String
) arr
[0]));
92 protected void addCallback(String suffix
, Function
<Object
[], Object
> toDo
) {
93 getReadyStage().thenAccept((ready
) -> {
94 String functionName
= createJsFunction(mapName
+ "__on" + suffix
, toDo
);
95 doExecute(getJsMapVar() + ".callbacks['on" + suffix
+ "']=" + functionName
+ ";");
96 callMethod(mapName
, "enable" + suffix
+ "()");