Skip to content

Commit

Permalink
code clean, added map conversion functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabor committed Mar 16, 2020
1 parent 31a08a0 commit 45e9f76
Show file tree
Hide file tree
Showing 51 changed files with 797 additions and 177 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ pnpmfile.js
node_modules
target
webpack.generated.js
.settings
.vscode/settings.json
package-lock.json
pnpm-lock.yaml
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"java.configuration.updateBuildConfiguration": "disabled"
"java.configuration.updateBuildConfiguration": "disabled",
"maven.view": "flat"
}
119 changes: 61 additions & 58 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,67 @@
{
"name": "no-name",
"name": "temp",
"license": "UNLICENSED",
"repository": "npm/npm",
"description": "Temporary package for pnpm installation",
"dependencies": {
"pnpm": "^4.5.0",
"@polymer/polymer": "3.2.0",
"@webcomponents/webcomponentsjs": "^2.2.10",
"@vaadin/vaadin-crud": "1.1.0",
"@vaadin/vaadin-grid": "5.5.0",
"@vaadin/vaadin-icons": "4.3.1",
"@polymer/iron-collapse": "3.0.1",
"@vaadin/vaadin-split-layout": "4.1.1",
"@vaadin/vaadin-combo-box": "5.0.9",
"@vaadin/vaadin-cookie-consent": "1.1.2",
"@vaadin/vaadin-core-shrinkwrap": "14.2.0-alpha3",
"@vaadin/vaadin-upload": "4.2.2",
"@vaadin/vaadin-dialog": "2.2.1",
"@polymer/iron-overlay-behavior": "^3.0.2",
"@vaadin/vaadin-select": "2.1.6",
"@vaadin/vaadin-app-layout": "2.0.4",
"@vaadin/vaadin-item": "2.1.1",
"@polymer/app-layout": "3.1.0",
"@vaadin/vaadin-board": "2.1.1",
"@vaadin/vaadin-notification": "1.4.0",
"@vaadin/vaadin-charts": "6.2.4",
"@vaadin/vaadin-grid-pro": "2.0.5",
"@vaadin/vaadin-progress-bar": "1.1.2",
"@vaadin/vaadin-shrinkwrap": "14.2.0-alpha3",
"@vaadin/vaadin-ordered-layout": "1.1.0",
"@vaadin/vaadin-login": "1.0.1",
"@vaadin/vaadin-button": "2.2.2",
"@vaadin/vaadin-date-picker": "4.0.5",
"@vaadin/vaadin-text-field": "2.5.3",
"@vaadin/vaadin-menu-bar": "1.0.3",
"@vaadin/vaadin-custom-field": "1.0.10",
"@polymer/paper-tabs": "3.1.0",
"@vaadin/vaadin-form-layout": "2.1.6",
"@vaadin/vaadin-accordion": "1.0.1",
"@vaadin/vaadin-confirm-dialog": "1.1.5",
"@polymer/iron-list": "3.0.2",
"@vaadin/vaadin-list-box": "1.2.0",
"@polymer/paper-badge": "3.0.1",
"@vaadin/vaadin-checkbox": "2.2.10",
"@vaadin/vaadin-details": "1.0.1",
"@polymer/iron-icon": "3.0.1",
"@polymer/paper-ripple": "3.0.1",
"@vaadin/vaadin-time-picker": "2.0.4",
"@vaadin/vaadin-context-menu": "4.3.15",
"@vaadin/vaadin-radio-button": "1.2.3",
"@vaadin/vaadin-tabs": "3.0.5",
"@vaadin/vaadin-lumo-styles": "1.5.0",
"leaflet": "1.6.0",
"@vaadin/vaadin-material-styles": "1.2.3",
"@vaadin/vaadin-rich-text-editor": "1.1.1"
},
"vaadin": {
"dependencies": {
"@polymer/polymer": "3.2.0",
"@webcomponents/webcomponentsjs": "^2.2.10",
"@vaadin/vaadin-crud": "1.1.0",
"@vaadin/vaadin-icons": "4.3.1",
"@vaadin/vaadin-grid": "5.5.0",
"@vaadin/vaadin-icons": "4.3.1",
"@polymer/iron-collapse": "3.0.1",
"@vaadin/vaadin-split-layout": "4.1.1",
"@vaadin/vaadin-combo-box": "5.0.9",
Expand All @@ -21,8 +75,8 @@
"@vaadin/vaadin-item": "2.1.1",
"@polymer/app-layout": "3.1.0",
"@vaadin/vaadin-board": "2.1.1",
"@vaadin/vaadin-charts": "6.2.4",
"@vaadin/vaadin-notification": "1.4.0",
"@vaadin/vaadin-charts": "6.2.4",
"@vaadin/vaadin-grid-pro": "2.0.5",
"@vaadin/vaadin-progress-bar": "1.1.2",
"@vaadin/vaadin-shrinkwrap": "14.2.0-alpha3",
Expand All @@ -33,21 +87,21 @@
"@vaadin/vaadin-text-field": "2.5.3",
"@vaadin/vaadin-menu-bar": "1.0.3",
"@vaadin/vaadin-custom-field": "1.0.10",
"@vaadin/vaadin-form-layout": "2.1.6",
"@polymer/paper-tabs": "3.1.0",
"@vaadin/vaadin-form-layout": "2.1.6",
"@vaadin/vaadin-accordion": "1.0.1",
"@vaadin/vaadin-confirm-dialog": "1.1.5",
"@polymer/iron-list": "3.0.2",
"@vaadin/vaadin-list-box": "1.2.0",
"@polymer/paper-badge": "3.0.1",
"@vaadin/vaadin-details": "1.0.1",
"@vaadin/vaadin-checkbox": "2.2.10",
"@vaadin/vaadin-details": "1.0.1",
"@polymer/iron-icon": "3.0.1",
"@polymer/paper-ripple": "3.0.1",
"@vaadin/vaadin-time-picker": "2.0.4",
"@vaadin/vaadin-context-menu": "4.3.15",
"@vaadin/vaadin-tabs": "3.0.5",
"@vaadin/vaadin-radio-button": "1.2.3",
"@vaadin/vaadin-tabs": "3.0.5",
"@vaadin/vaadin-lumo-styles": "1.5.0",
"leaflet": "1.6.0",
"@vaadin/vaadin-material-styles": "1.2.3",
Expand All @@ -63,58 +117,7 @@
"webpack-merge": "4.2.2",
"webpack-dev-server": "3.9.0"
},
"hash": "7ea82b9d8577f97b8daf1d1c2d82a8ff97abb43511404bca589493918d1f31bb"
},
"dependencies": {
"@polymer/polymer": "3.2.0",
"@webcomponents/webcomponentsjs": "^2.2.10",
"@vaadin/vaadin-crud": "1.1.0",
"@vaadin/vaadin-icons": "4.3.1",
"@vaadin/vaadin-grid": "5.5.0",
"@polymer/iron-collapse": "3.0.1",
"@vaadin/vaadin-split-layout": "4.1.1",
"@vaadin/vaadin-combo-box": "5.0.9",
"@vaadin/vaadin-cookie-consent": "1.1.2",
"@vaadin/vaadin-core-shrinkwrap": "14.2.0-alpha3",
"@vaadin/vaadin-upload": "4.2.2",
"@vaadin/vaadin-dialog": "2.2.1",
"@polymer/iron-overlay-behavior": "^3.0.2",
"@vaadin/vaadin-select": "2.1.6",
"@vaadin/vaadin-app-layout": "2.0.4",
"@vaadin/vaadin-item": "2.1.1",
"@polymer/app-layout": "3.1.0",
"@vaadin/vaadin-board": "2.1.1",
"@vaadin/vaadin-charts": "6.2.4",
"@vaadin/vaadin-notification": "1.4.0",
"@vaadin/vaadin-grid-pro": "2.0.5",
"@vaadin/vaadin-progress-bar": "1.1.2",
"@vaadin/vaadin-shrinkwrap": "14.2.0-alpha3",
"@vaadin/vaadin-ordered-layout": "1.1.0",
"@vaadin/vaadin-login": "1.0.1",
"@vaadin/vaadin-button": "2.2.2",
"@vaadin/vaadin-date-picker": "4.0.5",
"@vaadin/vaadin-text-field": "2.5.3",
"@vaadin/vaadin-menu-bar": "1.0.3",
"@vaadin/vaadin-custom-field": "1.0.10",
"@vaadin/vaadin-form-layout": "2.1.6",
"@polymer/paper-tabs": "3.1.0",
"@vaadin/vaadin-accordion": "1.0.1",
"@vaadin/vaadin-confirm-dialog": "1.1.5",
"@polymer/iron-list": "3.0.2",
"@vaadin/vaadin-list-box": "1.2.0",
"@polymer/paper-badge": "3.0.1",
"@vaadin/vaadin-details": "1.0.1",
"@vaadin/vaadin-checkbox": "2.2.10",
"@polymer/iron-icon": "3.0.1",
"@polymer/paper-ripple": "3.0.1",
"@vaadin/vaadin-time-picker": "2.0.4",
"@vaadin/vaadin-context-menu": "4.3.15",
"@vaadin/vaadin-tabs": "3.0.5",
"@vaadin/vaadin-radio-button": "1.2.3",
"@vaadin/vaadin-lumo-styles": "1.5.0",
"leaflet": "1.6.0",
"@vaadin/vaadin-material-styles": "1.2.3",
"@vaadin/vaadin-rich-text-editor": "1.1.1"
"hash": "94d214e42509f282667923083ea95b75c46b0538edd15195972c017c15801af4"
},
"devDependencies": {
"webpack-babel-multi-target-plugin": "2.3.3",
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<artifactId>leafletf4vaadin</artifactId>
<version>0.2.4-beta</version>
<name>Leaflet4Vaadin</name>
<description>Integration of Leaflet map for Vaadin platform</description>
<description>Integration of Leaflet map for Vaadin platform LTS 14</description>
<scm>
<url>https://github.com/Gubancs/leaflet4vaadin</url>
<connection>scm:git:git://https://github.com/Gubancs/leaflet4vaadin.git</connection>
Expand Down
77 changes: 73 additions & 4 deletions src/main/java/com/vaadin/addon/leaflet4vaadin/LeafletMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

package com.vaadin.addon.leaflet4vaadin;

import java.io.IOException;
import java.io.Serializable;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.vaadin.addon.leaflet4vaadin.controls.LeafletControl;
import com.vaadin.addon.leaflet4vaadin.layer.Identifiable;
import com.vaadin.addon.leaflet4vaadin.layer.Layer;
Expand Down Expand Up @@ -56,24 +58,32 @@
import com.vaadin.addon.leaflet4vaadin.layer.events.types.TooltipEventType;
import com.vaadin.addon.leaflet4vaadin.layer.groups.LayerGroup;
import com.vaadin.addon.leaflet4vaadin.layer.map.functions.GeolocationFunctions;
import com.vaadin.addon.leaflet4vaadin.layer.map.functions.MapConversionFunctions;
import com.vaadin.addon.leaflet4vaadin.layer.map.functions.MapGetStateFunctions;
import com.vaadin.addon.leaflet4vaadin.layer.map.functions.MapModifyStateFunctions;
import com.vaadin.addon.leaflet4vaadin.layer.map.options.DefaultMapOptions;
import com.vaadin.addon.leaflet4vaadin.layer.map.options.MapOptions;
import com.vaadin.addon.leaflet4vaadin.operations.LeafletOperation;
import com.vaadin.addon.leaflet4vaadin.types.LatLng;
import com.vaadin.addon.leaflet4vaadin.types.Point;
import com.vaadin.flow.component.ComponentEvent;
import com.vaadin.flow.component.ComponentEventListener;
import com.vaadin.flow.component.ComponentUtil;
import com.vaadin.flow.component.EventData;
import com.vaadin.flow.component.HasSize;
import com.vaadin.flow.component.HasTheme;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.dependency.NpmPackage;
import com.vaadin.flow.component.internal.DeadlockDetectingCompletableFuture;
import com.vaadin.flow.component.page.PendingJavaScriptResult;
import com.vaadin.flow.component.page.PendingJavaScriptResult.JavaScriptException;
import com.vaadin.flow.component.polymertemplate.EventHandler;
import com.vaadin.flow.component.polymertemplate.PolymerTemplate;
import com.vaadin.flow.internal.JsonSerializer;
import com.vaadin.flow.server.VaadinSession;
import com.vaadin.flow.shared.Registration;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -84,15 +94,20 @@
@JsModule("leaflet/dist/leaflet-src.js")
@CssImport(value = "leaflet/dist/leaflet.css", id = "leaflet-css")
@CssImport(value = "./styles/leaflet-lumo-theme.css", id = "lumo-leaflet-map")
public final class LeafletMap extends PolymerTemplate<LeafletModel>
implements MapModifyStateFunctions, MapGetStateFunctions, GeolocationFunctions, SupportsMouseEvents,
SupportsMapEvents, SupportsLocationEvents, SupportsKeyboardEvents, SupportsLayerEvents, HasSize, HasTheme {
public final class LeafletMap extends PolymerTemplate<LeafletModel> implements MapModifyStateFunctions,
MapGetStateFunctions, GeolocationFunctions, MapConversionFunctions, SupportsMouseEvents, SupportsMapEvents,
SupportsLocationEvents, SupportsKeyboardEvents, SupportsLayerEvents, HasSize, HasTheme {

private static final long serialVersionUID = 3789693345308589828L;

private final Logger logger = LoggerFactory.getLogger(LeafletMap.class);

private static class MapLayer extends LayerGroup {

/**
*
*/
private static final long serialVersionUID = -3205153902141978918L;
}

private final MapLayer mapLayer = new MapLayer();
Expand Down Expand Up @@ -464,6 +479,26 @@ public void removeAllLayers() {
this.mapLayer.getLayers().clear();
}

/**
* Fired when the map gets initialized with a view (center and zoom) and at
* least one layer, or immediately if it's already initialized.
*
* @param listener the listener to call when the event occurs, not {@code null}
* @return a handle that can be used for removing the listener
*/
public Registration whenReady(ComponentEventListener<MapReadyEvent> listener) {
return ComponentUtil.addListener(this, MapReadyEvent.class, listener);
}

/**
* Fired when the map gets initialized on client side
*/
@EventHandler
private void onMapReadyEventHandler() {
logger.info("Leaflet map gets initialized on client side.");
fireEvent(new MapReadyEvent(this));
}

/**
* Adds theme variants to the map component.
*
Expand All @@ -487,7 +522,24 @@ public <T extends Serializable> CompletableFuture<T> call(Identifiable target, S
LeafletOperation leafletOperation = new LeafletOperation(target, functionName, arguments);
PendingJavaScriptResult javascriptResult = getElement().callJsFunction("callLeafletFunction",
JsonSerializer.toJson(leafletOperation));
return javascriptResult.toCompletableFuture(resultType);

VaadinSession session = VaadinSession.getCurrent();

CompletableFuture<T> completableFuture = new DeadlockDetectingCompletableFuture<>(session);
javascriptResult.then(value -> {
try {
ObjectMapper objectMapper = new ObjectMapper();
T result = objectMapper.readValue(value.toString(), resultType);
completableFuture.complete(result);
} catch (IOException e) {
throw new RuntimeException("Failed to parse javascript result", e);
}
}, errorValue -> {
JavaScriptException exception = new JavaScriptException(errorValue);
completableFuture.completeExceptionally(exception);
});

return completableFuture;
}

@Override
Expand Down Expand Up @@ -519,4 +571,21 @@ public boolean hasEventListeners(LeafletEventType eventType) {
return this.mapLayer.hasEventListeners(eventType);
}

/**
* Map event which fired when map gets initialized on client side
*
* @author <strong>Gabor Kokeny</strong> Email:
* <a href='[email protected]'>[email protected]</a>
* @since 2020-03-16
* @version 1.0
*/
public static final class MapReadyEvent extends ComponentEvent<LeafletMap> {

private static final long serialVersionUID = 412791990495078838L;

public MapReadyEvent(LeafletMap source) {
super(source, true);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,17 @@ public void setSortLayers(boolean sortLayers) {
this.sortLayers = sortLayers;
}

/**
* Expand the control container if collapsed.
*/
public void expand() {
execute(this, "expand");
}

/**
* Collapse the control container if expanded.
*/
public void collapse() {
execute(this, "collapse");
}
}
Loading

0 comments on commit 45e9f76

Please sign in to comment.