X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=swt%2Forg.argeo.app.geo.swt%2Fsrc%2Forg%2Fargeo%2Fapp%2Fgeo%2Fswt%2FSwtJsMapPart.java;h=c7e915651311176c9f2f08f749b7b9b10e7bf68c;hb=720e78163faf96ccc966d155a516487af52ccec2;hp=5e90d3991943eea49c4a091cab5b3d78ff3fd7a1;hpb=f9b3af44af6897b286de0674bc9a919c689ff64e;p=gpl%2Fargeo-suite.git diff --git a/swt/org.argeo.app.geo.swt/src/org/argeo/app/geo/swt/SwtJsMapPart.java b/swt/org.argeo.app.geo.swt/src/org/argeo/app/geo/swt/SwtJsMapPart.java index 5e90d39..c7e9156 100644 --- a/swt/org.argeo.app.geo.swt/src/org/argeo/app/geo/swt/SwtJsMapPart.java +++ b/swt/org.argeo.app.geo.swt/src/org/argeo/app/geo/swt/SwtJsMapPart.java @@ -1,8 +1,8 @@ package org.argeo.app.geo.swt; -import java.util.concurrent.CompletionStage; import java.util.function.Consumer; import java.util.function.Function; + import org.argeo.app.geo.GeoUtils; import org.argeo.app.geo.ux.JsImplementation; import org.argeo.app.geo.ux.MapPart; @@ -35,33 +35,42 @@ public class SwtJsMapPart extends SwtBrowserJsPart implements MapPart { @Override public void addPoint(double lng, double lat, String style) { - callMapMethod("addPoint(%f, %f, %s)", lng, lat, style == null ? "'default'" : style); + executeMapMethod("addPoint(%f, %f, %s)", lng, lat, style == null ? "'default'" : style); } @Override public void addUrlLayer(String url, GeoFormat format, String style) { - callMapMethod("addUrlLayer('%s', '%s', %s, false)", url, format.name(), style); + executeMapMethod("addUrlLayer('%s', '%s', %s, false)", url, format.name(), style); } public void addCssUrlLayer(String url, GeoFormat format, String css) { String style = GeoUtils.createSldFromCss("layer", "Layer", css); - callMapMethod("addUrlLayer('%s', '%s', '%s', true)", url, format.name(), style); + executeMapMethod("addUrlLayer('%s', '%s', '%s', true)", url, format.name(), style); + } + + public void addLayer() { + //executeMapMethod("addLayer(\"return new argeo.app.geo.TileLayer({source: new argeo.app.geo.OSM()})\")"); + executeMapMethod("getMap().addLayer(new argeo.tp.ol.TileLayer({source: new argeo.tp.ol.OSM()}))"); } @Override public void setZoom(int zoom) { - callMapMethod("setZoom(%d)", zoom); + executeMapMethod("setZoom(%d)", zoom); } @Override public void setCenter(double lng, double lat) { - callMapMethod("setCenter(%f, %f)", lng, lat); + executeMapMethod("setCenter(%f, %f)", lng, lat); } - protected CompletionStage callMapMethod(String methodCall, Object... args) { + protected Object callMapMethod(String methodCall, Object... args) { return callMethod(getJsMapVar(), methodCall, args); } + protected void executeMapMethod(String methodCall, Object... args) { + executeMethod(getJsMapVar(), methodCall, args); + } + private String getJsMapVar() { return getJsVarName(mapName); } @@ -93,7 +102,7 @@ public class SwtJsMapPart extends SwtBrowserJsPart implements MapPart { getReadyStage().thenAccept((ready) -> { String functionName = createJsFunction(mapName + "__on" + suffix, toDo); doExecute(getJsMapVar() + ".callbacks['on" + suffix + "']=" + functionName + ";"); - callMethod(mapName, "enable" + suffix + "()"); + executeMethod(mapName, "enable" + suffix + "()"); }); } }