Skip to content

Commit

Permalink
Merge pull request #308 from xdev-software/develop
Browse files Browse the repository at this point in the history
4.1.0
  • Loading branch information
AB-xdev authored Dec 6, 2023
2 parents 1d13cef + 549dfe3 commit f345e4f
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/checkBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -105,6 +105,9 @@ jobs:
<artifactId>${{ env.PRIMARY_MAVEN_MODULE }}</artifactId>
<version>${{ steps.version.outputs.release }}</version>
</dependency>
### 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
Expand All @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/update-from-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.xdev-software</groupId>
<artifactId>vaadin-maps-leaflet-flow-root</artifactId>
<version>4.0.2-SNAPSHOT</version>
<version>4.1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<organization>
Expand Down
6 changes: 3 additions & 3 deletions vaadin-maps-leaflet-flow-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.xdev-software</groupId>
<artifactId>vaadin-maps-leaflet-flow-demo</artifactId>
<version>4.0.2-SNAPSHOT</version>
<version>4.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<inceptionYear>2019</inceptionYear>
Expand All @@ -26,9 +26,9 @@
<mainClass>software.xdev.vaadin.Application</mainClass>

<!-- Dependency-Versions -->
<vaadin.version>24.1.12</vaadin.version>
<vaadin.version>24.2.5</vaadin.version>

<org.springframework.boot.version>3.1.4</org.springframework.boot.version>
<org.springframework.boot.version>3.2.0</org.springframework.boot.version>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
10 changes: 5 additions & 5 deletions vaadin-maps-leaflet-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.xdev-software</groupId>
<artifactId>vaadin-maps-leaflet-flow</artifactId>
<version>4.0.2-SNAPSHOT</version>
<version>4.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>LeafletMap for Vaadin</name>
Expand Down Expand Up @@ -49,7 +49,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<!-- Dependency-Versions -->
<vaadin.version>24.1.12</vaadin.version>
<vaadin.version>24.2.5</vaadin.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -108,13 +108,13 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.3</version>
<version>2.16.0</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.10.0</version>
<version>1.11.0</version>
</dependency>
</dependencies>

Expand Down Expand Up @@ -178,7 +178,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.0</version>
<version>3.6.3</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -41,11 +45,62 @@ public class MapContainer extends Composite<Div> implements HasSize, HasStyle, H
{
private final LMap lMap;

private Consumer<LMap> afterInitialResize;

public MapContainer(final LComponentManagementRegistry reg)
{
this(reg, null);
}

/**
* @param afterInitialResize This is called after the map was initially resized/is ready.
* <p/>
* This is ONLY required when calling certain methods like e.g.
* {@link LMap#fitBounds(LLatLngBounds)} instantly after the map is created.
* <p/>
* For performance reasons it's highly recommended to only use this when required.
*/
public MapContainer(
final LComponentManagementRegistry reg,
final Consumer<LMap> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -91,10 +72,6 @@ public LMap(
return dynamicId;
}),
options);
if(fixDivZIndex)
{
fixZIndex(bindDiv);
}
}

/**
Expand All @@ -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
Expand Down

0 comments on commit f345e4f

Please sign in to comment.