diff --git a/.github/workflows/checkBuild.yml b/.github/workflows/checkBuild.yml index db37d020..2026708e 100644 --- a/.github/workflows/checkBuild.yml +++ b/.github/workflows/checkBuild.yml @@ -21,14 +21,14 @@ jobs: strategy: matrix: - java: [17] + java: [17, 21] distribution: [temurin] steps: - uses: actions/checkout@v4 - name: Set up JDK - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: ${{ matrix.distribution }} java-version: ${{ matrix.java }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 98628ecd..b5a5ff61 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,7 +19,7 @@ jobs: - uses: actions/checkout@v4 - name: Set up JDK - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' @@ -105,6 +105,9 @@ jobs: ${{ env.PRIMARY_MAVEN_MODULE }} ${{ steps.version.outputs.release }} + + ### Additional notes + * [Spring-Boot] You may have to include ``software/xdev`` inside [``vaadin.whitelisted-packages``](https://vaadin.com/docs/latest/integrations/spring/configuration#configure-the-scanning-of-packages) ``` publish_central: # Publish the code to central @@ -120,7 +123,7 @@ jobs: git pull - name: Set up JDK Apache Maven Central - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: # running setup-java again overwrites the settings.xml java-version: '17' distribution: 'temurin' @@ -152,7 +155,7 @@ jobs: git pull - name: Setup - Java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index f7c82af5..7c3e3440 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -31,7 +31,7 @@ jobs: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - name: Set up JDK - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: 17 diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index d2a8e2fd..0bf57796 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v4 - name: Set up JDK OSSRH - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: # running setup-java again overwrites the settings.xml distribution: 'temurin' java-version: '17' diff --git a/.github/workflows/update-from-template.yml b/.github/workflows/update-from-template.yml index ed77ae69..2bd1095a 100644 --- a/.github/workflows/update-from-template.yml +++ b/.github/workflows/update-from-template.yml @@ -86,9 +86,8 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh_pr_up() { - gh pr create "$@" || gh pr edit "$@" + gh pr create -H "${{ env.UPDATE_BRANCH }}" "$@" || (git checkout "${{ env.UPDATE_BRANCH }}" && gh pr edit "$@") } gh_pr_up -B "${{ steps.main.outputs.current_branch }}" \ - -H "${{ env.UPDATE_BRANCH }}" \ --title "Update from template" \ --body "An automated PR to sync changes from the template into this repo" diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b3b38a4..dce56b99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.1.0 +* Provide a workaround that fixes a problem where certain methods didn't work instantly after the map was created #305 +* Moved some container specific methods to ``MapContainer`` + ## 4.0.1 * Added shortcut method ``invokeSelfReturn`` #282 * Updated dependencies diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 92997139..dd107a99 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,7 +19,7 @@ We also encourage you to read the [contribution instructions by GitHub](https:// ### Software Requirements You should have the following things installed: * Git -* Java 17 - should be as unmodified as possible (Recommended: [Eclipse Adoptium](https://adoptium.net/temurin/releases/)) +* Java 21 - should be as unmodified as possible (Recommended: [Eclipse Adoptium](https://adoptium.net/temurin/releases/)) * Maven ### Recommended setup diff --git a/pom.xml b/pom.xml index 8158a699..ce99c306 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.xdev-software vaadin-maps-leaflet-flow-root - 4.0.2-SNAPSHOT + 4.1.0-SNAPSHOT pom diff --git a/vaadin-maps-leaflet-flow-demo/pom.xml b/vaadin-maps-leaflet-flow-demo/pom.xml index 872d122e..a35514c2 100644 --- a/vaadin-maps-leaflet-flow-demo/pom.xml +++ b/vaadin-maps-leaflet-flow-demo/pom.xml @@ -6,7 +6,7 @@ com.xdev-software vaadin-maps-leaflet-flow-demo - 4.0.2-SNAPSHOT + 4.1.0-SNAPSHOT jar 2019 @@ -26,9 +26,9 @@ software.xdev.vaadin.Application - 24.1.12 + 24.2.5 - 3.1.4 + 3.2.0 diff --git a/vaadin-maps-leaflet-flow-demo/src/main/java/software/xdev/vaadin/maps/leaflet/flow/DemoView.java b/vaadin-maps-leaflet-flow-demo/src/main/java/software/xdev/vaadin/maps/leaflet/flow/DemoView.java index 3060384a..937b162f 100644 --- a/vaadin-maps-leaflet-flow-demo/src/main/java/software/xdev/vaadin/maps/leaflet/flow/DemoView.java +++ b/vaadin-maps-leaflet-flow-demo/src/main/java/software/xdev/vaadin/maps/leaflet/flow/DemoView.java @@ -15,6 +15,7 @@ import software.xdev.vaadin.maps.leaflet.flow.demo.ComplexDemo; import software.xdev.vaadin.maps.leaflet.flow.demo.FreeingUpResourceBenchmarkDemo; +import software.xdev.vaadin.maps.leaflet.flow.demo.InitialResizeDemo; import software.xdev.vaadin.maps.leaflet.flow.demo.MinimalisticDemo; @@ -55,6 +56,12 @@ protected void onAttach(final AttachEvent attachEvent) "Minimalistic", "Showcasing the simplest form of using the API" ), + new Example( + InitialResizeDemo.NAV, + "Initial resize", + "Some map methods - when called instantly after the map is created - will not work correctly." + + " This example shows how to workaround this restriction." + ), new Example( ComplexDemo.NAV, "Complex", diff --git a/vaadin-maps-leaflet-flow-demo/src/main/java/software/xdev/vaadin/maps/leaflet/flow/demo/InitialResizeDemo.java b/vaadin-maps-leaflet-flow-demo/src/main/java/software/xdev/vaadin/maps/leaflet/flow/demo/InitialResizeDemo.java new file mode 100644 index 00000000..5dfbf304 --- /dev/null +++ b/vaadin-maps-leaflet-flow-demo/src/main/java/software/xdev/vaadin/maps/leaflet/flow/demo/InitialResizeDemo.java @@ -0,0 +1,53 @@ +package software.xdev.vaadin.maps.leaflet.flow.demo; + +import com.vaadin.flow.component.orderedlayout.VerticalLayout; +import com.vaadin.flow.router.Route; + +import software.xdev.vaadin.maps.leaflet.MapContainer; +import software.xdev.vaadin.maps.leaflet.basictypes.LLatLng; +import software.xdev.vaadin.maps.leaflet.basictypes.LLatLngBounds; +import software.xdev.vaadin.maps.leaflet.layer.raster.LTileLayer; +import software.xdev.vaadin.maps.leaflet.layer.vector.LPolylineOptions; +import software.xdev.vaadin.maps.leaflet.layer.vector.LRectangle; +import software.xdev.vaadin.maps.leaflet.map.LMap; +import software.xdev.vaadin.maps.leaflet.registry.LComponentManagementRegistry; +import software.xdev.vaadin.maps.leaflet.registry.LDefaultComponentManagementRegistry; + + +@Route(InitialResizeDemo.NAV) +public class InitialResizeDemo extends VerticalLayout +{ + public static final String NAV = "/initial-resize"; + + public InitialResizeDemo() + { + this.setSizeFull(); + + final LComponentManagementRegistry reg = new LDefaultComponentManagementRegistry(this); + + // We want to show this area initially + final LLatLngBounds bounds = new LLatLngBounds( + reg, + new LLatLng(reg, 49, 12), + new LLatLng(reg, 50, 11) + ); + + final MapContainer mapContainer = new MapContainer(reg, map -> { + // This needs to be done after the map was initially resized + // otherwise the view is calculated incorrectly + map.fitBounds(bounds); + }); + mapContainer.setSizeFull(); + this.add(mapContainer); + + final LMap map = mapContainer.getlMap(); + map.addLayer(LTileLayer.createDefaultForOpenStreetMapTileServer(reg)); + + // Still required as the map refuses to work otherwise + map.setView(new LLatLng(reg, 0, 0), 1); + + // Create rectangle for reference + new LRectangle(reg, bounds, new LPolylineOptions()) + .addTo(map); + } +} diff --git a/vaadin-maps-leaflet-flow/pom.xml b/vaadin-maps-leaflet-flow/pom.xml index 968bba72..3277f4ab 100644 --- a/vaadin-maps-leaflet-flow/pom.xml +++ b/vaadin-maps-leaflet-flow/pom.xml @@ -6,7 +6,7 @@ com.xdev-software vaadin-maps-leaflet-flow - 4.0.2-SNAPSHOT + 4.1.0-SNAPSHOT jar LeafletMap for Vaadin @@ -49,7 +49,7 @@ UTF-8 - 24.1.12 + 24.2.5 @@ -108,13 +108,13 @@ com.fasterxml.jackson.core jackson-databind - 2.15.3 + 2.16.0 org.apache.commons commons-text - 1.10.0 + 1.11.0 @@ -178,7 +178,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.6.0 + 3.6.3 attach-javadocs diff --git a/vaadin-maps-leaflet-flow/src/main/java/software/xdev/vaadin/maps/leaflet/MapContainer.java b/vaadin-maps-leaflet-flow/src/main/java/software/xdev/vaadin/maps/leaflet/MapContainer.java index 0eddb105..8339256c 100644 --- a/vaadin-maps-leaflet-flow/src/main/java/software/xdev/vaadin/maps/leaflet/MapContainer.java +++ b/vaadin-maps-leaflet-flow/src/main/java/software/xdev/vaadin/maps/leaflet/MapContainer.java @@ -15,6 +15,9 @@ */ package software.xdev.vaadin.maps.leaflet; +import java.util.function.Consumer; + +import com.vaadin.flow.component.ClientCallable; import com.vaadin.flow.component.Composite; import com.vaadin.flow.component.HasComponents; import com.vaadin.flow.component.HasSize; @@ -26,6 +29,7 @@ import com.vaadin.flow.component.dependency.NpmPackage; import com.vaadin.flow.component.html.Div; +import software.xdev.vaadin.maps.leaflet.basictypes.LLatLngBounds; import software.xdev.vaadin.maps.leaflet.map.LMap; import software.xdev.vaadin.maps.leaflet.registry.LComponentManagementRegistry; @@ -41,11 +45,62 @@ public class MapContainer extends Composite
implements HasSize, HasStyle, H { private final LMap lMap; + private Consumer afterInitialResize; + public MapContainer(final LComponentManagementRegistry reg) { + this(reg, null); + } + + /** + * @param afterInitialResize This is called after the map was initially resized/is ready. + *

+ * This is ONLY required when calling certain methods like e.g. + * {@link LMap#fitBounds(LLatLngBounds)} instantly after the map is created. + *

+ * For performance reasons it's highly recommended to only use this when required. + */ + public MapContainer( + final LComponentManagementRegistry reg, + final Consumer afterInitialResize) + { + this.afterInitialResize = afterInitialResize; this.getContent().setSizeFull(); + this.fixZIndex(); this.lMap = new LMap(reg, this.getContent()); + this.fixInitialSizeAfterCreation(); + } + + protected String ensureId() + { + // Id is auto assigned by LMap so this will never throw + return this.getContent().getId().orElseThrow(); + } + + protected void fixZIndex() + { + LMap.fixZIndex(this.getContent()); + } + + protected void fixInitialSizeAfterCreation() + { + this.lMap.fixInvalidSizeAfterCreation(this.afterInitialResize != null + ? "document.getElementById('" + this.ensureId() + "').$server.onInitialResize();" + : null); + } + + @ClientCallable + public void onInitialResize() + { + if(this.afterInitialResize == null) + { + return; + } + + this.afterInitialResize.accept(this.getlMap()); + // Free up + this.afterInitialResize = null; } public LMap getlMap() diff --git a/vaadin-maps-leaflet-flow/src/main/java/software/xdev/vaadin/maps/leaflet/base/LEvented.java b/vaadin-maps-leaflet-flow/src/main/java/software/xdev/vaadin/maps/leaflet/base/LEvented.java index ed8cd641..54b0583a 100644 --- a/vaadin-maps-leaflet-flow/src/main/java/software/xdev/vaadin/maps/leaflet/base/LEvented.java +++ b/vaadin-maps-leaflet-flow/src/main/java/software/xdev/vaadin/maps/leaflet/base/LEvented.java @@ -103,7 +103,7 @@ default S once(final String type, final String function, final String context) */ default S once(final String type, final String function) { - return this.on(type, function, null); + return this.once(type, function, null); } /** diff --git a/vaadin-maps-leaflet-flow/src/main/java/software/xdev/vaadin/maps/leaflet/map/LMap.java b/vaadin-maps-leaflet-flow/src/main/java/software/xdev/vaadin/maps/leaflet/map/LMap.java index edfb97dc..dd6cff8c 100644 --- a/vaadin-maps-leaflet-flow/src/main/java/software/xdev/vaadin/maps/leaflet/map/LMap.java +++ b/vaadin-maps-leaflet-flow/src/main/java/software/xdev/vaadin/maps/leaflet/map/LMap.java @@ -50,8 +50,6 @@ public LMap( final LMapOptions options) { super(compReg, "L.map($0" + compReg.writeOptionsOptionalParameter(options) + ")", id); - // https://stackoverflow.com/q/53879753 - this.fixInvalidSizeAfterCreation(); } public LMap( @@ -65,23 +63,6 @@ public LMap( final LComponentManagementRegistry compReg, final Div bindDiv, final LMapOptions options) - { - this(compReg, bindDiv, options, true); - } - - public LMap( - final LComponentManagementRegistry compReg, - final Div bindDiv, - final boolean fixDivZIndex) - { - this(compReg, bindDiv, null, fixDivZIndex); - } - - public LMap( - final LComponentManagementRegistry compReg, - final Div bindDiv, - final LMapOptions options, - final boolean fixDivZIndex) { this( compReg, @@ -91,10 +72,6 @@ public LMap( return dynamicId; }), options); - if(fixDivZIndex) - { - fixZIndex(bindDiv); - } } /** @@ -105,10 +82,15 @@ public static void fixZIndex(final Div div) div.getStyle().set("z-index", "1"); } - protected void fixInvalidSizeAfterCreation() + public void fixInvalidSizeAfterCreation(final String callback) { + // https://stackoverflow.com/q/53879753 + // This should no longer be required starting in Leaflet v2 https://github.com/Leaflet/Leaflet/pull/8612 this.componentRegistry().execJs("let tempMap = " + this.clientComponentJsAccessor() + "; " - + "setTimeout(function () { tempMap.invalidateSize(false); }, 100)"); + + "setTimeout(function () { " + + " tempMap.invalidateSize(false); " + + (callback != null ? callback : "") + + " }, 100)"); } // endregion