Skip to content

Commit 69b09be

Browse files
paodbmlopezFC
authored andcommitted
feat: add mapId property for map styling
Close #58
1 parent c3bedf5 commit 69b09be

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-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
@@ -300,6 +300,25 @@ public void disableScaleControl(boolean disable) {
300300
this.getElement().setProperty("disableScaleControl", disable);
301301
}
302302

303+
/**
304+
* Sets the mapId. See
305+
* https://developers.google.com/maps/documentation/javascript/cloud-based-map-styling
306+
*
307+
* @param mapId If set, the custom style associated with that map id is applied.
308+
*/
309+
public void setMapId(String mapId) {
310+
this.getElement().setProperty("mapId", mapId);
311+
}
312+
313+
/**
314+
* Returns the current map id.
315+
*
316+
* @return The current map id.
317+
*/
318+
public String getMapId() {
319+
return this.getElement().getProperty("mapId");
320+
}
321+
303322
public static class GoogleMapClickEvent extends ClickEvent<GoogleMap> {
304323
private final double lat;
305324
private final double lon;
@@ -426,4 +445,5 @@ public Registration addGeolocationErrorEventListener(
426445
ComponentEventListener<GeolocationErrorEvent> listener) {
427446
return addListener(GeolocationErrorEvent.class, listener);
428447
}
448+
429449
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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.router.PageTitle;
6+
7+
@PageTitle("MapId Styling Demo")
8+
@DemoSource(
9+
"https://github.com/FlowingCode/GoogleMapsAddon/blob/master/src/test/java/com/flowingcode/vaadin/addons/googlemaps/CloudBasedMapStylingDemo.java")
10+
@SuppressWarnings("serial")
11+
public class CloudBasedMapStylingDemo extends AbstractGoogleMapsDemo {
12+
13+
@Override
14+
protected void createGoogleMapsDemo(String apiKey) {
15+
GoogleMap gmaps = new GoogleMap(apiKey, null, null);
16+
gmaps.setMapType(MapType.ROADMAP);
17+
gmaps.setSizeFull();
18+
gmaps.setCenter(new LatLon(-31.636036, -60.7055271));
19+
gmaps.setMapId("8e0a97af9386fef");
20+
add(gmaps);
21+
}
22+
23+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public GooglemapsDemoView() {
3636
addDemo(new GeolocationDemo());
3737
addDemo(new DraggableMarkerDemo());
3838
addDemo(new DisableUIControlsDemo());
39+
addDemo(new CloudBasedMapStylingDemo());
3940
setSizeFull();
4041
}
4142
}

0 commit comments

Comments
 (0)