Skip to content

Commit a007241

Browse files
paodbjavier-godoy
authored andcommitted
fix(demo): consolidate markers demos
Close #98
1 parent fa3d4d2 commit a007241

File tree

4 files changed

+57
-138
lines changed

4 files changed

+57
-138
lines changed

src/test/java/com/flowingcode/vaadin/addons/googlemaps/AddMarkersDemo.java

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,25 @@
2020

2121
package com.flowingcode.vaadin.addons.googlemaps;
2222

23-
import java.util.HashMap;
24-
import java.util.Map;
25-
import java.util.Optional;
2623
import com.flowingcode.vaadin.addons.demo.DemoSource;
2724
import com.flowingcode.vaadin.addons.googlemaps.GoogleMap.MapType;
25+
import com.vaadin.flow.component.HtmlComponent;
26+
import com.vaadin.flow.component.Text;
2827
import com.vaadin.flow.component.button.Button;
28+
import com.vaadin.flow.component.checkbox.Checkbox;
2929
import com.vaadin.flow.component.combobox.ComboBox;
30+
import com.vaadin.flow.component.html.Div;
31+
import com.vaadin.flow.component.icon.Icon;
32+
import com.vaadin.flow.component.icon.VaadinIcon;
33+
import com.vaadin.flow.component.notification.Notification;
3034
import com.vaadin.flow.component.orderedlayout.FlexLayout;
3135
import com.vaadin.flow.component.orderedlayout.FlexLayout.FlexWrap;
36+
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
3237
import com.vaadin.flow.router.PageTitle;
3338
import com.vaadin.flow.router.Route;
39+
import java.util.HashMap;
40+
import java.util.Map;
41+
import java.util.Optional;
3442

3543
@PageTitle("Add Markers Demo")
3644
@DemoSource
@@ -54,23 +62,62 @@ protected void createGoogleMapsDemo(String apiKey) {
5462
markerColorsMap.put("Yellow", Markers.YELLOW);
5563
markerColorsMap.put("Orange", Markers.ORANGE);
5664
markerColorsMap.put("Light blue", Markers.LIGHTBLUE);
57-
ComboBox<String> colorCB = new ComboBox<>();
65+
66+
ComboBox<String> colorCB = new ComboBox<>("Color");
5867
ReflectionUtil.setItems(colorCB, markerColorsMap.keySet());
59-
colorCB.setPlaceholder("Marker color");
68+
colorCB.setPlaceholder("Choose color");
69+
70+
Checkbox draggable = new Checkbox("Draggable");
71+
Checkbox withRightClick = new Checkbox("Right Click");
72+
6073
Button addMarker =
6174
new Button(
6275
"Add Marker",
6376
ev -> {
6477
String markerColor =
6578
Optional.ofNullable(markerColorsMap.get(colorCB.getValue())).orElse("");
66-
gmaps.addMarker("New Marker", gmaps.getCenter(), true, markerColor);
79+
Boolean isDraggable = draggable.getValue();
80+
GoogleMapMarker marker =
81+
new GoogleMapMarker("New Marker", gmaps.getCenter(), isDraggable, markerColor);
82+
83+
if (isDraggable) {
84+
marker.addDragEndEventListener(e -> Notification.show("Dragged to -> Latitude: "
85+
+ e.getLatitude() + " - Longitude: " + e.getLongitude()));
86+
}
87+
88+
if (withRightClick.getValue()) {
89+
marker.addRightClickListener(e -> {
90+
Div text = new Div(new Text("Alt key: " + e.isAltKey()), new HtmlComponent("br"),
91+
new Text("Shift key: " + e.isShiftKey()), new HtmlComponent("br"),
92+
new Text("Ctrol key: " + e.isCtrlKey()), new HtmlComponent("br"),
93+
new Text("Click counts: " + e.getClickCount()), new HtmlComponent("br"),
94+
new Text("Latitude: " + e.getLatitude()), new HtmlComponent("br"),
95+
new Text("Longitude: " + e.getLongitude()));
96+
97+
Notification notification = new Notification();
98+
99+
Button closeButton = new Button(new Icon(VaadinIcon.CLOSE_SMALL));
100+
closeButton.addClickListener(event -> {
101+
notification.close();
102+
});
103+
104+
HorizontalLayout layout = new HorizontalLayout(text, closeButton);
105+
layout.setAlignItems(Alignment.CENTER);
106+
107+
notification.add(layout);
108+
notification.open();
109+
});
110+
}
111+
gmaps.addMarker(marker);
67112
});
68113

69114
FlexLayout layout = new FlexLayout();
70-
layout.setFlexWrap(FlexWrap.WRAP);
71-
addMarker.addClassName("margin-button");
72-
colorCB.addClassName("margin-button");
73-
layout.add(addMarker, colorCB);
115+
layout.setFlexWrap(FlexWrap.WRAP); // hide-source
116+
addMarker.addClassName("margin-button"); // hide-source
117+
colorCB.addClassName("margin-button"); // hide-source
118+
layout.add(colorCB, draggable, withRightClick, addMarker);
119+
layout.setAlignItems(Alignment.BASELINE); // hide-source
120+
layout.getStyle().set("margin-top", "0"); // hide-source
74121
add(gmaps, layout);
75122
}
76123
}

src/test/java/com/flowingcode/vaadin/addons/googlemaps/DraggableMarkerDemo.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/test/java/com/flowingcode/vaadin/addons/googlemaps/GooglemapsDemoView.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@ public GooglemapsDemoView() {
3737
addDemo(AddMarkersDemo.class);
3838
addDemo(AddPolygonsDemo.class);
3939
addDemo(GeolocationDemo.class);
40-
addDemo(DraggableMarkerDemo.class);
4140
addDemo(DisableUIControlsDemo.class);
4241
addDemo(CloudBasedMapStylingDemo.class);
4342
addDemo(ControlSizeDemo.class);
4443
addDemo(KMLLayerDemo.class);
4544
addDemo(MarkerClusteringDemo.class);
4645
addDemo(TiltAndRotationDemo.class);
47-
addDemo(RightClickOnMarkersDemo.class);
4846
addDemo(ClusteringWithCustomRendererDemo.class);
4947
setSizeFull();
5048
}

src/test/java/com/flowingcode/vaadin/addons/googlemaps/RightClickOnMarkersDemo.java

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)