From 6654ee415f2fb81b031d87d80e84d579caf28308 Mon Sep 17 00:00:00 2001 From: Paola De Bartolo Date: Fri, 29 Sep 2023 17:41:10 -0300 Subject: [PATCH] fix(demo): consolidate markers demos Close #98 --- .../addons/googlemaps/AddMarkersDemo.java | 67 +++++++++++++--- .../googlemaps/DraggableMarkerDemo.java | 48 ------------ .../addons/googlemaps/GooglemapsDemoView.java | 2 - .../googlemaps/RightClickOnMarkersDemo.java | 78 ------------------- 4 files changed, 57 insertions(+), 138 deletions(-) delete mode 100644 src/test/java/com/flowingcode/vaadin/addons/googlemaps/DraggableMarkerDemo.java delete mode 100644 src/test/java/com/flowingcode/vaadin/addons/googlemaps/RightClickOnMarkersDemo.java diff --git a/src/test/java/com/flowingcode/vaadin/addons/googlemaps/AddMarkersDemo.java b/src/test/java/com/flowingcode/vaadin/addons/googlemaps/AddMarkersDemo.java index f04e2b9..281d780 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/googlemaps/AddMarkersDemo.java +++ b/src/test/java/com/flowingcode/vaadin/addons/googlemaps/AddMarkersDemo.java @@ -20,17 +20,25 @@ package com.flowingcode.vaadin.addons.googlemaps; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; import com.flowingcode.vaadin.addons.demo.DemoSource; import com.flowingcode.vaadin.addons.googlemaps.GoogleMap.MapType; +import com.vaadin.flow.component.HtmlComponent; +import com.vaadin.flow.component.Text; import com.vaadin.flow.component.button.Button; +import com.vaadin.flow.component.checkbox.Checkbox; import com.vaadin.flow.component.combobox.ComboBox; +import com.vaadin.flow.component.html.Div; +import com.vaadin.flow.component.icon.Icon; +import com.vaadin.flow.component.icon.VaadinIcon; +import com.vaadin.flow.component.notification.Notification; import com.vaadin.flow.component.orderedlayout.FlexLayout; import com.vaadin.flow.component.orderedlayout.FlexLayout.FlexWrap; +import com.vaadin.flow.component.orderedlayout.HorizontalLayout; import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.Route; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; @PageTitle("Add Markers Demo") @DemoSource @@ -54,23 +62,62 @@ protected void createGoogleMapsDemo(String apiKey) { markerColorsMap.put("Yellow", Markers.YELLOW); markerColorsMap.put("Orange", Markers.ORANGE); markerColorsMap.put("Light blue", Markers.LIGHTBLUE); - ComboBox colorCB = new ComboBox<>(); + + ComboBox colorCB = new ComboBox<>("Color"); ReflectionUtil.setItems(colorCB, markerColorsMap.keySet()); - colorCB.setPlaceholder("Marker color"); + colorCB.setPlaceholder("Choose color"); + + Checkbox draggable = new Checkbox("Draggable"); + Checkbox withRightClick = new Checkbox("Right Click"); + Button addMarker = new Button( "Add Marker", ev -> { String markerColor = Optional.ofNullable(markerColorsMap.get(colorCB.getValue())).orElse(""); - gmaps.addMarker("New Marker", gmaps.getCenter(), true, markerColor); + Boolean isDraggable = draggable.getValue(); + GoogleMapMarker marker = + new GoogleMapMarker("New Marker", gmaps.getCenter(), isDraggable, markerColor); + + if (isDraggable) { + marker.addDragEndEventListener(e -> Notification.show("Dragged to -> Latitude: " + + e.getLatitude() + " - Longitude: " + e.getLongitude())); + } + + if (withRightClick.getValue()) { + marker.addRightClickListener(e -> { + Div text = new Div(new Text("Alt key: " + e.isAltKey()), new HtmlComponent("br"), + new Text("Shift key: " + e.isShiftKey()), new HtmlComponent("br"), + new Text("Ctrol key: " + e.isCtrlKey()), new HtmlComponent("br"), + new Text("Click counts: " + e.getClickCount()), new HtmlComponent("br"), + new Text("Latitude: " + e.getLatitude()), new HtmlComponent("br"), + new Text("Longitude: " + e.getLongitude())); + + Notification notification = new Notification(); + + Button closeButton = new Button(new Icon(VaadinIcon.CLOSE_SMALL)); + closeButton.addClickListener(event -> { + notification.close(); + }); + + HorizontalLayout layout = new HorizontalLayout(text, closeButton); + layout.setAlignItems(Alignment.CENTER); + + notification.add(layout); + notification.open(); + }); + } + gmaps.addMarker(marker); }); FlexLayout layout = new FlexLayout(); - layout.setFlexWrap(FlexWrap.WRAP); - addMarker.addClassName("margin-button"); - colorCB.addClassName("margin-button"); - layout.add(addMarker, colorCB); + layout.setFlexWrap(FlexWrap.WRAP); // hide-source + addMarker.addClassName("margin-button"); // hide-source + colorCB.addClassName("margin-button"); // hide-source + layout.add(colorCB, draggable, withRightClick, addMarker); + layout.setAlignItems(Alignment.BASELINE); // hide-source + layout.getStyle().set("margin-top", "0"); // hide-source add(gmaps, layout); } } diff --git a/src/test/java/com/flowingcode/vaadin/addons/googlemaps/DraggableMarkerDemo.java b/src/test/java/com/flowingcode/vaadin/addons/googlemaps/DraggableMarkerDemo.java deleted file mode 100644 index 22925d0..0000000 --- a/src/test/java/com/flowingcode/vaadin/addons/googlemaps/DraggableMarkerDemo.java +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * #%L - * Google Maps Addon - * %% - * Copyright (C) 2020 - 2023 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.flowingcode.vaadin.addons.demo.DemoSource; -import com.flowingcode.vaadin.addons.googlemaps.GoogleMap.MapType; -import com.vaadin.flow.component.notification.Notification; -import com.vaadin.flow.router.PageTitle; -import com.vaadin.flow.router.Route; - -@PageTitle("Draggable Marker Demo") -@DemoSource -@Route(value = "googlemaps/draggablemarker", layout = GooglemapsDemoView.class) -@SuppressWarnings("serial") -public class DraggableMarkerDemo extends AbstractGoogleMapsDemo { - - @Override - protected void createGoogleMapsDemo(String apiKey) { - GoogleMap gmaps = new GoogleMap(apiKey, null, null); - gmaps.setMapType(MapType.ROADMAP); - gmaps.setSizeFull(); - gmaps.setCenter(new LatLon(-31.636036, -60.7055271)); - - gmaps.addMarker("Center", gmaps.getCenter(), true, Markers.PURPLE) - .addDragEndEventListener( - e -> - Notification.show("Lat: " + e.getLatitude() + " - Lng: " + e.getLongitude())); - - add(gmaps); - } -} diff --git a/src/test/java/com/flowingcode/vaadin/addons/googlemaps/GooglemapsDemoView.java b/src/test/java/com/flowingcode/vaadin/addons/googlemaps/GooglemapsDemoView.java index 717584a..7516d13 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/googlemaps/GooglemapsDemoView.java +++ b/src/test/java/com/flowingcode/vaadin/addons/googlemaps/GooglemapsDemoView.java @@ -37,14 +37,12 @@ public GooglemapsDemoView() { addDemo(AddMarkersDemo.class); addDemo(AddPolygonsDemo.class); addDemo(GeolocationDemo.class); - addDemo(DraggableMarkerDemo.class); addDemo(DisableUIControlsDemo.class); addDemo(CloudBasedMapStylingDemo.class); addDemo(ControlSizeDemo.class); addDemo(KMLLayerDemo.class); addDemo(MarkerClusteringDemo.class); addDemo(TiltAndRotationDemo.class); - addDemo(RightClickOnMarkersDemo.class); addDemo(ClusteringWithCustomRendererDemo.class); setSizeFull(); } diff --git a/src/test/java/com/flowingcode/vaadin/addons/googlemaps/RightClickOnMarkersDemo.java b/src/test/java/com/flowingcode/vaadin/addons/googlemaps/RightClickOnMarkersDemo.java deleted file mode 100644 index 9b44758..0000000 --- a/src/test/java/com/flowingcode/vaadin/addons/googlemaps/RightClickOnMarkersDemo.java +++ /dev/null @@ -1,78 +0,0 @@ -/*- - * #%L - * Google Maps Addon - * %% - * Copyright (C) 2020 - 2023 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.flowingcode.vaadin.addons.demo.DemoSource; -import com.flowingcode.vaadin.addons.googlemaps.GoogleMap.MapType; -import com.vaadin.flow.component.HtmlComponent; -import com.vaadin.flow.component.Text; -import com.vaadin.flow.component.button.Button; -import com.vaadin.flow.component.button.ButtonVariant; -import com.vaadin.flow.component.icon.Icon; -import com.vaadin.flow.component.icon.VaadinIcon; -import com.vaadin.flow.component.html.Div; -import com.vaadin.flow.component.notification.Notification; -import com.vaadin.flow.component.orderedlayout.HorizontalLayout; -import com.vaadin.flow.router.PageTitle; -import com.vaadin.flow.router.Route; - -@PageTitle("Right Click on Marker Demo") -@DemoSource -@Route(value = "googlemaps/right-click-on-marker", layout = GooglemapsDemoView.class) -@SuppressWarnings("serial") -public class RightClickOnMarkersDemo extends AbstractGoogleMapsDemo { - - @Override - protected void createGoogleMapsDemo(String apiKey) { - GoogleMap gmaps = new GoogleMap(apiKey, null, null); - gmaps.setMapType(MapType.ROADMAP); - gmaps.setSizeFull(); - gmaps.setCenter(new LatLon(-31.636036, -60.7055271)); - gmaps.setZoom(12); - - gmaps.addMarker("Marker", gmaps.getCenter(), true, Markers.GREEN) - .addRightClickListener(e -> { - - Div text = new Div(new Text("Alt key: " + e.isAltKey()), new HtmlComponent("br"), - new Text("Shift key: " + e.isShiftKey()), new HtmlComponent("br"), - new Text("Ctrol key: " + e.isCtrlKey()), new HtmlComponent("br"), - new Text("Click counts: " + e.getClickCount()), new HtmlComponent("br"), - new Text("Latitude: " + e.getLatitude()), new HtmlComponent("br"), - new Text("Longitude: " + e.getLongitude())); - - Notification notification = new Notification(); - - Button closeButton = new Button(new Icon(VaadinIcon.CLOSE_SMALL)); - closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY_INLINE); - closeButton.addClickListener(event -> { - notification.close(); - }); - - HorizontalLayout layout = new HorizontalLayout(text, closeButton); - layout.setAlignItems(Alignment.CENTER); - - notification.add(layout); - notification.open(); - }); - - add(gmaps); - } -}