]>
git.argeo.org Git - gpl/argeo-suite.git/blob - swt/org.argeo.app.geo.swt/src/org/argeo/app/geo/swt/SwtJsMapPart.java
1 package org
.argeo
.app
.geo
.swt
;
3 import java
.util
.function
.Consumer
;
4 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.js/geo.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 executeMapMethod("addPoint(%f, %f, %s)", lng
, lat
, style
== null ?
"'default'" : style
);
42 public void addUrlLayer(String url
, GeoFormat format
, String style
) {
43 executeMapMethod("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 executeMapMethod("addUrlLayer('%s', '%s', '%s', true)", url
, format
.name(), style
);
51 public void addLayer() {
52 //executeMapMethod("addLayer(\"return new argeo.app.geo.TileLayer({source: new argeo.app.geo.OSM()})\")");
53 executeMapMethod("getMap().addLayer(new argeo.tp.ol.TileLayer({source: new argeo.tp.ol.OSM()}))");
57 public void setZoom(int zoom
) {
58 executeMapMethod("setZoom(%d)", zoom
);
62 public void setCenter(double lng
, double lat
) {
63 executeMapMethod("setCenter(%f, %f)", lng
, lat
);
66 protected Object
callMapMethod(String methodCall
, Object
... args
) {
67 return callMethod(getJsMapVar(), methodCall
, args
);
70 protected void executeMapMethod(String methodCall
, Object
... args
) {
71 executeMethod(getJsMapVar(), methodCall
, args
);
74 private String
getJsMapVar() {
75 return getJsVarName(mapName
);
81 public void onFeatureSelected(Consumer
<FeatureSelectedEvent
> toDo
) {
82 addCallback("FeatureSelected", (arr
) -> {
83 toDo
.accept(new FeatureSelectedEvent((String
) arr
[0]));
88 public void onFeatureSingleClick(Consumer
<FeatureSingleClickEvent
> toDo
) {
89 addCallback("FeatureSingleClick", (arr
) -> {
90 toDo
.accept(new FeatureSingleClickEvent((String
) arr
[0]));
95 public void onFeaturePopup(Function
<FeaturePopupEvent
, String
> toDo
) {
96 addCallback("FeaturePopup", (arr
) -> {
97 return toDo
.apply(new FeaturePopupEvent((String
) arr
[0]));
101 protected void addCallback(String suffix
, Function
<Object
[], Object
> toDo
) {
102 getReadyStage().thenAccept((ready
) -> {
103 String functionName
= createJsFunction(mapName
+ "__on" + suffix
, toDo
);
104 doExecute(getJsMapVar() + ".callbacks['on" + suffix
+ "']=" + functionName
+ ";");
105 executeMethod(mapName
, "enable" + suffix
+ "()");