Skip to content

Commit

Permalink
Merge pull request #112 from FlowingCode/fix-issue-102
Browse files Browse the repository at this point in the history
Add support for polylines
  • Loading branch information
flang authored Jan 16, 2024
2 parents 03c573b + 47936f7 commit ee221e1
Show file tree
Hide file tree
Showing 31 changed files with 331 additions and 189 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.flowingcode.vaadin.addons</groupId>
<artifactId>google-maps</artifactId>
<version>1.10.2-SNAPSHOT</version>
<version>1.11.0-SNAPSHOT</version>
<name>Google Maps Addon</name>
<description>Integration of google-map for Vaadin platform</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Google Maps Addon
* %%
* Copyright (C) 2020 - 2023 Flowing Code
* Copyright (C) 2020 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -160,6 +160,21 @@ public void addPolygon(GoogleMapPolygon polygon) {
public void removePolygon(GoogleMapPolygon polygon) {
this.getElement().removeChild(polygon.getElement());
}

public GoogleMapPolyline addPolyline(List<GoogleMapPoint> points) {
GoogleMapPolyline polyline = new GoogleMapPolyline(points);
this.getElement().appendChild(polyline.getElement());
return polyline;
}

public void addPolyline(GoogleMapPolyline polyline) {
this.getElement().appendChild(polyline.getElement());
}

@SuppressWarnings("squid:S3242")
public void removePolyline(GoogleMapPolyline polyline) {
this.getElement().removeChild(polyline.getElement());
}

/**
* Adds a marker to the map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Google Maps Addon
* %%
* Copyright (C) 2020 - 2023 Flowing Code
* Copyright (C) 2020 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Google Maps Addon
* %%
* Copyright (C) 2020 - 2023 Flowing Code
* Copyright (C) 2020 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
/*-
* #%L
* Google Maps Addon
* %%
* Copyright (C) 2020 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

package com.flowingcode.vaadin.addons.googlemaps;

import com.vaadin.flow.component.ClickEvent;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.ComponentEventListener;
import com.vaadin.flow.component.DomEvent;
import com.vaadin.flow.component.EventData;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.dependency.NpmPackage;
import com.vaadin.flow.shared.Registration;
import elemental.json.Json;
import elemental.json.JsonArray;
import elemental.json.JsonObject;
import elemental.json.JsonValue;
import java.util.List;

@SuppressWarnings("serial")
@Tag("google-map-poly")
@JsModule("@flowingcode/google-map/google-map-poly.js")
@JsModule("@flowingcode/google-map/google-map-point.js")
@NpmPackage(value = "@flowingcode/google-map", version = "3.6.1")
@NpmPackage(value = "@googlemaps/markerclusterer", version = "2.0.8")
public abstract class GoogleMapPoly extends Component {

private static final double DEFAULT_FILL_OPACITY = 0.5d;
private static final String DEFAULT_FILL_COLOR = "blue";

public enum StrokePosition {
CENTER,
INSIDE,
OUTSIDE
}

public GoogleMapPoly(List<GoogleMapPoint> points) {
getElement().removeProperty("draggable");
setFillColor(DEFAULT_FILL_COLOR);
setFillOpacity(DEFAULT_FILL_OPACITY);
setPoints(points);
}

public void setFillOpacity(double opacity) {
this.getElement().setProperty("fillOpacity", opacity);
}

public double getFillOpacity() {
return this.getElement().getProperty("fillOpacity", 1d);
}

public void setStrokeOpacity(double opacity) {
this.getElement().setProperty("strokeOpacity", opacity);
}

public double getStrokeOpacity() {
return this.getElement().getProperty("strokeOpacity", 1d);
}

public void setStrokePosition(StrokePosition position) {
this.getElement().setProperty("strokePosition", position.name().toLowerCase());
}

public StrokePosition getStrokePosition() {
return StrokePosition.valueOf(this.getElement().getProperty("strokePosition").toUpperCase());
}

public void setStrokeWeight(double weight) {
this.getElement().setProperty("strokeWeight", weight);
}

public double getStrokeWeight() {
return this.getElement().getProperty("strokeWeight", 1d);
}

public void setZIndex(double zindex) {
this.getElement().setProperty("zIndex", zindex);
}

public double getZIndex() {
return this.getElement().getProperty("zIndex", 1d);
}

public void setFillColor(String string) {
this.getElement().setProperty("fillColor", string);
}

public String getFillColor() {
return this.getElement().getProperty("fillColor");
}

public void setStrokeColor(String string) {
this.getElement().setProperty("strokeColor", string);
}

public String getStrokeColor() {
return this.getElement().getProperty("strokeColor");
}

public void setClosed(boolean b) {
this.getElement().setProperty("closed", b);
}

public boolean isClosed() {
return this.getElement().getProperty("closed", false);
}

public void setGeodesic(boolean b) {
this.getElement().setProperty("geodesic", b);
}

public boolean isGeodesic() {
return this.getElement().getProperty("geodesic", false);
}

public void setPoints(Iterable<GoogleMapPoint> points) {
points.forEach(point -> this.getElement().appendChild(point.getElement()));
}

public GoogleMapPoint addPoint(LatLon position) {
GoogleMapPoint point = new GoogleMapPoint(position.getLat(), position.getLon());
this.getElement().appendChild(point.getElement());
return point;
}

public void addPoint(GoogleMapPoint point) {
this.getElement().appendChild(point.getElement());
}

@SuppressWarnings("squid:S3242")
public void removePoint(GoogleMapPoint point) {
this.getElement().removeChild(point.getElement());
}

@DomEvent("google-map-poly-click")
public static class GoogleMapPolyClickEvent extends ClickEvent<GoogleMapPolygon> {

private final double lat;
private final double lon;

public GoogleMapPolyClickEvent(
GoogleMapPoly source,
boolean fromClient,
@EventData(value = "event.detail.latLng") JsonValue latLng) {
super(source);
this.lat = ((JsonObject) latLng).getNumber("lat");
this.lon = ((JsonObject) latLng).getNumber("lng");
}

public double getLatitude() {
return this.lat;
}

public double getLongitude() {
return this.lon;
}
}

public Registration addClickListener(
ComponentEventListener<GoogleMapPolyClickEvent> listener) {
this.getElement().setProperty("clickable", true);
this.getElement().setProperty("clickEvents", true);
return addListener(GoogleMapPolyClickEvent.class, listener);
}

public void setIcons(Icon... icons) {
JsonArray jsonArray = Json.createArray();
for (int i = 0; i < icons.length; i++) {
jsonArray.set(i, icons[i].getJson());
}
this.getElement().setPropertyJson("icons", jsonArray);
}
}
Loading

0 comments on commit ee221e1

Please sign in to comment.