|
7 | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | 8 | * you may not use this file except in compliance with the License. |
9 | 9 | * You may obtain a copy of the License at |
10 | | - * |
| 10 | + * |
11 | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | | - * |
| 12 | + * |
13 | 13 | * Unless required by applicable law or agreed to in writing, software |
14 | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
19 | 19 | */ |
20 | 20 | package com.flowingcode.vaadin.addons.googlemaps; |
21 | 21 |
|
22 | | -import java.util.Arrays; |
23 | | -import java.util.List; |
24 | | -import java.util.stream.Collectors; |
25 | | - |
26 | 22 | import com.vaadin.flow.component.ClickEvent; |
27 | 23 | import com.vaadin.flow.component.Component; |
28 | 24 | import com.vaadin.flow.component.ComponentEventListener; |
|
31 | 27 | import com.vaadin.flow.component.dependency.JsModule; |
32 | 28 | import com.vaadin.flow.component.dependency.NpmPackage; |
33 | 29 | import com.vaadin.flow.shared.Registration; |
| 30 | +import java.util.Arrays; |
| 31 | +import java.util.List; |
| 32 | +import java.util.stream.Collectors; |
34 | 33 |
|
35 | | -/** |
36 | | - * A class representing a polygon overlay of Google Maps. |
37 | | - */ |
| 34 | +/** A class representing a polygon overlay of Google Maps. */ |
38 | 35 | @SuppressWarnings("serial") |
39 | 36 | @Tag("google-map-poly") |
40 | 37 | @JsModule("@flowingcode/google-map/google-map-poly.js") |
41 | 38 | @JsModule("@flowingcode/google-map/google-map-point.js") |
42 | 39 | @NpmPackage(value = "@flowingcode/google-map", version = "3.0.2") |
43 | 40 | public class GoogleMapPolygon extends Component { |
44 | 41 |
|
45 | | - private static final double DEFAULT_FILL_OPACITY = 0.5d; |
46 | | - private static final String DEFAULT_FILL_COLOR = "blue"; |
47 | | - |
48 | | - public enum StrokePosition { |
49 | | - CENTER, INSIDE, OUTSIDE |
50 | | - } |
51 | | - |
52 | | - public GoogleMapPolygon(List<GoogleMapPoint> points) { |
53 | | - getElement().removeProperty("draggable"); |
54 | | - setClosed(true); |
55 | | - setFillColor(DEFAULT_FILL_COLOR); |
56 | | - setFillOpacity(DEFAULT_FILL_OPACITY); |
57 | | - setPoints(points); |
58 | | - } |
59 | | - |
60 | | - public void setFillOpacity(double opacity) { |
61 | | - this.getElement().setProperty("fillOpacity", opacity); |
62 | | - } |
63 | | - |
64 | | - public double getFillOpacity() { |
65 | | - return this.getElement().getProperty("fillOpacity", 1d); |
66 | | - } |
67 | | - |
68 | | - public void setStrokeOpacity(double opacity) { |
69 | | - this.getElement().setProperty("strokeOpacity", opacity); |
70 | | - } |
71 | | - |
72 | | - public double getStrokeOpacity() { |
73 | | - return this.getElement().getProperty("strokeOpacity", 1d); |
74 | | - } |
75 | | - |
76 | | - public void setStrokePosition(StrokePosition position) { |
77 | | - this.getElement().setProperty("strokePosition", position.name().toLowerCase()); |
78 | | - } |
79 | | - |
80 | | - public StrokePosition getStrokePosition() { |
81 | | - return StrokePosition.valueOf(this.getElement().getProperty("strokePosition").toUpperCase()); |
82 | | - } |
83 | | - |
84 | | - public void setStrokeWeight(double weight) { |
85 | | - this.getElement().setProperty("strokeWeight", weight); |
86 | | - } |
87 | | - |
88 | | - public double getStrokeWeight() { |
89 | | - return this.getElement().getProperty("strokeWeight", 1d); |
90 | | - } |
91 | | - |
92 | | - public void setZIndex(double zindex) { |
93 | | - this.getElement().setProperty("zIndex", zindex); |
94 | | - } |
95 | | - |
96 | | - public double getZIndex() { |
97 | | - return this.getElement().getProperty("zIndex", 1d); |
98 | | - } |
99 | | - |
100 | | - public void setFillColor(String string) { |
101 | | - this.getElement().setProperty("fillColor", string); |
102 | | - } |
103 | | - |
104 | | - public String getFillColor() { |
105 | | - return this.getElement().getProperty("fillColor"); |
106 | | - } |
107 | | - |
108 | | - public void setStrokeColor(String string) { |
109 | | - this.getElement().setProperty("strokeColor", string); |
110 | | - } |
111 | | - |
112 | | - public String getStrokeColor() { |
113 | | - return this.getElement().getProperty("strokeColor"); |
114 | | - } |
115 | | - |
116 | | - public void setClosed(boolean b) { |
117 | | - this.getElement().setProperty("closed", b); |
118 | | - } |
119 | | - |
120 | | - public boolean isClosed() { |
121 | | - return this.getElement().getProperty("closed", false); |
122 | | - } |
123 | | - |
124 | | - public void setGeodesic(boolean b) { |
125 | | - this.getElement().setProperty("geodesic", b); |
126 | | - } |
127 | | - |
128 | | - public boolean isGeodesic() { |
129 | | - return this.getElement().getProperty("geodesic", false); |
130 | | - } |
131 | | - |
132 | | - public void setPoints(Iterable<GoogleMapPoint> points) { |
133 | | - points.forEach(point -> this.getElement().appendChild(point.getElement())); |
134 | | - } |
135 | | - |
136 | | - public GoogleMapPoint addPoint(LatLon position) { |
137 | | - GoogleMapPoint point = new GoogleMapPoint(position.getLat(), position.getLon()); |
138 | | - this.getElement().appendChild(point.getElement()); |
139 | | - return point; |
140 | | - } |
141 | | - |
142 | | - public void addPoint(GoogleMapPoint point) { |
143 | | - this.getElement().appendChild(point.getElement()); |
144 | | - } |
145 | | - |
146 | | - @SuppressWarnings("squid:S3242") |
147 | | - public void removePoint(GoogleMapPoint point) { |
148 | | - this.getElement().removeChild(point.getElement()); |
149 | | - } |
150 | | - |
151 | | - @DomEvent("google-map-poly-click") |
152 | | - public static class GoogleMapPolygonClickEvent extends ClickEvent<GoogleMapPolygon> { |
153 | | - public GoogleMapPolygonClickEvent(GoogleMapPolygon source, boolean fromClient) { |
154 | | - super(source); |
155 | | - } |
156 | | - } |
157 | | - |
158 | | - public Registration addClickListener(ComponentEventListener<GoogleMapPolygonClickEvent> listener) { |
159 | | - this.getElement().setProperty("clickable", true); |
160 | | - this.getElement().setProperty("clickEvents", true); |
161 | | - return addListener(GoogleMapPolygonClickEvent.class, listener); |
162 | | - } |
163 | | - |
164 | | - public void setIcons(Icon... icons) { |
165 | | - String iconsStr = "[" |
166 | | - + Arrays.asList(icons).stream().map(Icon::getJson).collect(Collectors.joining(",")) + "]"; |
167 | | - getElement().executeJs("this.icons=" + iconsStr); |
168 | | - } |
169 | | - |
| 42 | + private static final double DEFAULT_FILL_OPACITY = 0.5d; |
| 43 | + private static final String DEFAULT_FILL_COLOR = "blue"; |
| 44 | + |
| 45 | + public enum StrokePosition { |
| 46 | + CENTER, |
| 47 | + INSIDE, |
| 48 | + OUTSIDE |
| 49 | + } |
| 50 | + |
| 51 | + public GoogleMapPolygon(List<GoogleMapPoint> points) { |
| 52 | + getElement().removeProperty("draggable"); |
| 53 | + setClosed(true); |
| 54 | + setFillColor(DEFAULT_FILL_COLOR); |
| 55 | + setFillOpacity(DEFAULT_FILL_OPACITY); |
| 56 | + setPoints(points); |
| 57 | + } |
| 58 | + |
| 59 | + public void setFillOpacity(double opacity) { |
| 60 | + this.getElement().setProperty("fillOpacity", opacity); |
| 61 | + } |
| 62 | + |
| 63 | + public double getFillOpacity() { |
| 64 | + return this.getElement().getProperty("fillOpacity", 1d); |
| 65 | + } |
| 66 | + |
| 67 | + public void setStrokeOpacity(double opacity) { |
| 68 | + this.getElement().setProperty("strokeOpacity", opacity); |
| 69 | + } |
| 70 | + |
| 71 | + public double getStrokeOpacity() { |
| 72 | + return this.getElement().getProperty("strokeOpacity", 1d); |
| 73 | + } |
| 74 | + |
| 75 | + public void setStrokePosition(StrokePosition position) { |
| 76 | + this.getElement().setProperty("strokePosition", position.name().toLowerCase()); |
| 77 | + } |
| 78 | + |
| 79 | + public StrokePosition getStrokePosition() { |
| 80 | + return StrokePosition.valueOf(this.getElement().getProperty("strokePosition").toUpperCase()); |
| 81 | + } |
| 82 | + |
| 83 | + public void setStrokeWeight(double weight) { |
| 84 | + this.getElement().setProperty("strokeWeight", weight); |
| 85 | + } |
| 86 | + |
| 87 | + public double getStrokeWeight() { |
| 88 | + return this.getElement().getProperty("strokeWeight", 1d); |
| 89 | + } |
| 90 | + |
| 91 | + public void setZIndex(double zindex) { |
| 92 | + this.getElement().setProperty("zIndex", zindex); |
| 93 | + } |
| 94 | + |
| 95 | + public double getZIndex() { |
| 96 | + return this.getElement().getProperty("zIndex", 1d); |
| 97 | + } |
| 98 | + |
| 99 | + public void setFillColor(String string) { |
| 100 | + this.getElement().setProperty("fillColor", string); |
| 101 | + } |
| 102 | + |
| 103 | + public String getFillColor() { |
| 104 | + return this.getElement().getProperty("fillColor"); |
| 105 | + } |
| 106 | + |
| 107 | + public void setStrokeColor(String string) { |
| 108 | + this.getElement().setProperty("strokeColor", string); |
| 109 | + } |
| 110 | + |
| 111 | + public String getStrokeColor() { |
| 112 | + return this.getElement().getProperty("strokeColor"); |
| 113 | + } |
| 114 | + |
| 115 | + public void setClosed(boolean b) { |
| 116 | + this.getElement().setProperty("closed", b); |
| 117 | + } |
| 118 | + |
| 119 | + public boolean isClosed() { |
| 120 | + return this.getElement().getProperty("closed", false); |
| 121 | + } |
| 122 | + |
| 123 | + public void setGeodesic(boolean b) { |
| 124 | + this.getElement().setProperty("geodesic", b); |
| 125 | + } |
| 126 | + |
| 127 | + public boolean isGeodesic() { |
| 128 | + return this.getElement().getProperty("geodesic", false); |
| 129 | + } |
| 130 | + |
| 131 | + public void setPoints(Iterable<GoogleMapPoint> points) { |
| 132 | + points.forEach(point -> this.getElement().appendChild(point.getElement())); |
| 133 | + } |
| 134 | + |
| 135 | + public GoogleMapPoint addPoint(LatLon position) { |
| 136 | + GoogleMapPoint point = new GoogleMapPoint(position.getLat(), position.getLon()); |
| 137 | + this.getElement().appendChild(point.getElement()); |
| 138 | + return point; |
| 139 | + } |
| 140 | + |
| 141 | + public void addPoint(GoogleMapPoint point) { |
| 142 | + this.getElement().appendChild(point.getElement()); |
| 143 | + } |
| 144 | + |
| 145 | + @SuppressWarnings("squid:S3242") |
| 146 | + public void removePoint(GoogleMapPoint point) { |
| 147 | + this.getElement().removeChild(point.getElement()); |
| 148 | + } |
| 149 | + |
| 150 | + @DomEvent("google-map-poly-click") |
| 151 | + public static class GoogleMapPolygonClickEvent extends ClickEvent<GoogleMapPolygon> { |
| 152 | + public GoogleMapPolygonClickEvent(GoogleMapPolygon source, boolean fromClient) { |
| 153 | + super(source); |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + public Registration addClickListener( |
| 158 | + ComponentEventListener<GoogleMapPolygonClickEvent> listener) { |
| 159 | + this.getElement().setProperty("clickable", true); |
| 160 | + this.getElement().setProperty("clickEvents", true); |
| 161 | + return addListener(GoogleMapPolygonClickEvent.class, listener); |
| 162 | + } |
| 163 | + |
| 164 | + public void setIcons(Icon... icons) { |
| 165 | + String iconsStr = |
| 166 | + "[" |
| 167 | + + Arrays.asList(icons).stream().map(Icon::getJson).collect(Collectors.joining(",")) |
| 168 | + + "]"; |
| 169 | + getElement().executeJs("this.icons=" + iconsStr); |
| 170 | + } |
170 | 171 | } |
0 commit comments