Skip to content

Commit cecbb84

Browse files
paodbmlopezFC
authored andcommitted
feat: add controlSize feature
Close #63
1 parent 69b09be commit cecbb84

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMap.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,26 @@ public String getMapId() {
319319
return this.getElement().getProperty("mapId");
320320
}
321321

322+
/**
323+
* Sets the size of the control buttons appearing in the map. Must be specified when creating the
324+
* map. See
325+
* https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions.controlSize
326+
*
327+
* @param controlSize If set, control's size will be updated with this value.
328+
*/
329+
public void setControlSize(int controlSize) {
330+
this.getElement().setProperty("controlSize", controlSize);
331+
}
332+
333+
/**
334+
* Returns the current control size value.
335+
*
336+
* @return The current size of the control buttons.
337+
*/
338+
public int getControlSize() {
339+
return this.getElement().getProperty("controlSize", 0);
340+
}
341+
322342
public static class GoogleMapClickEvent extends ClickEvent<GoogleMap> {
323343
private final double lat;
324344
private final double lon;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.flowingcode.vaadin.addons.googlemaps;
2+
3+
import com.flowingcode.vaadin.addons.demo.DemoSource;
4+
import com.flowingcode.vaadin.addons.googlemaps.GoogleMap.MapType;
5+
import com.vaadin.flow.component.html.Span;
6+
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
7+
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
8+
import com.vaadin.flow.router.PageTitle;
9+
10+
@PageTitle("Control Size Demo")
11+
@DemoSource(
12+
"https://github.com/FlowingCode/GoogleMapsAddon/blob/master/src/test/java/com/flowingcode/vaadin/addons/googlemaps/ControlSizeDemo.java")
13+
@SuppressWarnings("serial")
14+
public class ControlSizeDemo extends AbstractGoogleMapsDemo {
15+
16+
@Override
17+
protected void createGoogleMapsDemo(String apiKey) {
18+
19+
GoogleMap gmaps1 = createGoogleMap(apiKey);
20+
gmaps1.setControlSize(20);
21+
VerticalLayout controlSizeLayout = new VerticalLayout(createSpan("Map with custom size value for controls"), gmaps1);
22+
controlSizeLayout.setSizeFull();
23+
24+
GoogleMap gmaps2 = createGoogleMap(apiKey);
25+
VerticalLayout noControlSizeLayout = new VerticalLayout(createSpan("Map with default size value for controls"), gmaps2);
26+
noControlSizeLayout.setSizeFull();
27+
28+
HorizontalLayout horizontalLayout = new HorizontalLayout(controlSizeLayout, noControlSizeLayout);
29+
horizontalLayout.setSizeFull();
30+
add(horizontalLayout);
31+
}
32+
33+
private GoogleMap createGoogleMap(String apiKey) {
34+
GoogleMap gmaps = new GoogleMap(apiKey, null, null);
35+
gmaps.setMapType(MapType.ROADMAP);
36+
gmaps.setSizeFull();
37+
gmaps.setZoom(5);
38+
gmaps.setCenter(new LatLon(-35.198155, -65.776366));
39+
return gmaps;
40+
}
41+
42+
private Span createSpan(String text) {
43+
Span span = new Span(text);
44+
span.getElement().getStyle().set("font-weight", "bold");
45+
return span;
46+
}
47+
48+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public GooglemapsDemoView() {
3737
addDemo(new DraggableMarkerDemo());
3838
addDemo(new DisableUIControlsDemo());
3939
addDemo(new CloudBasedMapStylingDemo());
40+
addDemo(new ControlSizeDemo());
4041
setSizeFull();
4142
}
4243
}

0 commit comments

Comments
 (0)