diff --git a/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMap.java b/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMap.java index 2b317a3..c8752fa 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMap.java +++ b/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMap.java @@ -148,34 +148,76 @@ public GoogleMapMarker addMarker( return gmm; } + /** + * Creates a polygon with the given points and adds the new polygon to the map. + * + * @param points the points of the polygon + * + * @return the new created polygon + */ public GoogleMapPolygon addPolygon(List points) { GoogleMapPolygon polygon = new GoogleMapPolygon(points); - this.getElement().appendChild(polygon.getElement()); + addPolygon(polygon); return polygon; } + /** + * Adds a new polygon to the map. + * + * @param polygon the polygon to be added to the map + */ public void addPolygon(GoogleMapPolygon polygon) { this.getElement().appendChild(polygon.getElement()); + if (this.getElement().getParent() != null) { + this.getElement().executeJs("this._updateObjects()"); + } } + /** + * Removes a polygon from the map. + * + * @param polygon the polygon to be removed from the map + */ @SuppressWarnings("squid:S3242") public void removePolygon(GoogleMapPolygon polygon) { this.getElement().removeChild(polygon.getElement()); + this.getElement().executeJs("this._updateObjects()"); } + /** + * Creates a polyline with the given points and adds the new polyline to the map. + * + * @param points the points of the polyline + * + * @return the new created polyline + */ public GoogleMapPolyline addPolyline(List points) { GoogleMapPolyline polyline = new GoogleMapPolyline(points); - this.getElement().appendChild(polyline.getElement()); + addPolyline(polyline); return polyline; } + /** + * Adds a new polyline to the map. + * + * @param polyline the polyline to be added to the map + */ public void addPolyline(GoogleMapPolyline polyline) { this.getElement().appendChild(polyline.getElement()); + if (this.getElement().getParent() != null) { + this.getElement().executeJs("this._updateObjects()"); + } } + /** + * Removes a polyline from the map. + * + * @param polyline the polyline to be removed from the map + */ @SuppressWarnings("squid:S3242") public void removePolyline(GoogleMapPolyline polyline) { this.getElement().removeChild(polyline.getElement()); + this.getElement().executeJs("this._updateObjects()"); } /**