Skip to content

Commit f757778

Browse files
paodbjavier-godoy
authored andcommitted
feat: add possibility to style map features and elements
Close #123
1 parent 4e47357 commit f757778

File tree

9 files changed

+701
-0
lines changed

9 files changed

+701
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

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

23+
import com.flowingcode.vaadin.addons.googlemaps.maptypestyle.ElementType;
24+
import com.flowingcode.vaadin.addons.googlemaps.maptypestyle.FeatureType;
25+
import com.flowingcode.vaadin.addons.googlemaps.maptypestyle.MapStyle;
2326
import com.vaadin.flow.component.ClickEvent;
2427
import com.vaadin.flow.component.ClientCallable;
2528
import com.vaadin.flow.component.Component;
@@ -849,4 +852,17 @@ public void closeFullScreen() {
849852
.executeJs("document.exitFullscreen();");
850853
}
851854

855+
/**
856+
* Sets style formatting to the {@link FeatureType features} and {@link ElementType elements} of the map.
857+
*
858+
* @param mapStyles formatting to be applied to the map features and elements
859+
*/
860+
public void setMapStyle(MapStyle... mapStyles) {
861+
JsonArray jsonArray = Json.createArray();
862+
for (int i = 0; i < mapStyles.length; i++) {
863+
MapStyle mapStyle = mapStyles[i];
864+
jsonArray.set(i, mapStyle.getJson());
865+
}
866+
this.getElement().setPropertyJson("styles", jsonArray);
867+
}
852868
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*-
2+
* #%L
3+
* Google Maps Addon
4+
* %%
5+
* Copyright (C) 2020 - 2024 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
21+
package com.flowingcode.vaadin.addons.googlemaps.maptypestyle;
22+
23+
import lombok.Getter;
24+
25+
/**
26+
* Enum representing supported element types. Elements are subdivisions of a feature.
27+
*/
28+
public enum ElementType {
29+
30+
/**
31+
* Selects all elements of the specified feature. Is the default option.
32+
*/
33+
ALL("all"),
34+
35+
/**
36+
* Selects all geometric elements of the specified feature.
37+
*/
38+
GEOMETRY("geometry"),
39+
40+
/**
41+
* Selects only the fill of the feature's geometry.
42+
*/
43+
GEOMETRY_FILL("geometry.fill"),
44+
45+
/**
46+
* Selects only the stroke of the feature's geometry.
47+
*/
48+
GEOMETRY_STROKE("geometry.stroke"),
49+
50+
/**
51+
* Selects the textual labels associated with the specified feature.
52+
*/
53+
LABELS("labels"),
54+
55+
/**
56+
* Selects only the icon displayed within the feature's label.
57+
*/
58+
LABELS_ICON("labels.icon"),
59+
60+
/**
61+
* Selects only the text of the label.
62+
*/
63+
LABELS_TEXT("labels.text"),
64+
65+
/**
66+
* Selects only the fill of the label. The fill of a label is typically rendered as a colored
67+
* outline that surrounds the label text.
68+
*/
69+
LABELS_TEXT_FILL("labels.text.fill"),
70+
71+
/**
72+
* Selects only the stroke of the label's text.
73+
*/
74+
LABELS_TEXT_STROKE("labels.text.stroke");
75+
76+
@Getter
77+
private String value;
78+
79+
ElementType(String value) {
80+
this.value = value;
81+
}
82+
83+
}
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
/*-
2+
* #%L
3+
* Google Maps Addon
4+
* %%
5+
* Copyright (C) 2020 - 2024 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
21+
package com.flowingcode.vaadin.addons.googlemaps.maptypestyle;
22+
23+
import lombok.Getter;
24+
25+
/**
26+
* Enum representing supported feature types. Features are geographic characteristics on the
27+
* map, including roads, parks, bodies of water, businesses, and more.
28+
*/
29+
public enum FeatureType {
30+
31+
/**
32+
* Selects all features. Is the default option.
33+
*/
34+
ALL("all"),
35+
36+
/**
37+
* Selects all administrative areas. Styling affects only the labels of administrative areas, not
38+
* the geographical borders or fill.
39+
*/
40+
ADMINISTRATIVE("administrative"),
41+
42+
/**
43+
* Selects countries.
44+
*/
45+
ADMINISTRATIVE_COUNTRY("administrative.country"),
46+
47+
/**
48+
* Selects land parcels.
49+
*/
50+
ADMINISTRATIVE_LAND_PARCEL("administrative.land_parcel"),
51+
52+
53+
/**
54+
* Selects localities.
55+
*/
56+
ADMINISTRATIVE_LOCALITY("administrative.locality"),
57+
58+
59+
/**
60+
* Selects neighborhoods.
61+
*/
62+
ADMINISTRATIVE_NEIGHBORHOOD("administrative.neighborhood"),
63+
64+
65+
/**
66+
* Selects provinces.
67+
*/
68+
ADMINISTRATIVE_PROVINCE("administrative.province"),
69+
70+
/**
71+
* Selects all landscapes.
72+
*/
73+
LANDSCAPE("landscape"),
74+
75+
/**
76+
* Selects man-made features, such as buildings and other structures.
77+
*/
78+
LANDSCAPE_MAN_MADE("landscape.man_made"),
79+
80+
/**
81+
* Selects natural features, such as mountains, rivers, deserts, and glaciers..
82+
*/
83+
LANDSCAPE_NATURAL("landscape.natural"),
84+
85+
/**
86+
* Selects land cover features, the physical material that covers the earth's surface, such as
87+
* forests, grasslands, wetlands, and bare ground..
88+
*/
89+
LANDSCAPE_NATURAL_LANDCOVER("landscape.natural.landcover"),
90+
91+
/**
92+
* Selects terrain features of a land surface, such as elevation, slope, and orientation.
93+
*/
94+
LANDSCAPE_NATURAL_TERRAIN("landscape.natural.terrain"),
95+
96+
/**
97+
* Selects all points of interest.
98+
*/
99+
POI("poi"),
100+
101+
/**
102+
* Selects tourist attractions.
103+
*/
104+
POI_ATTRACTION("poi.attraction"),
105+
106+
/**
107+
* Selects businesses.
108+
*/
109+
POI_BUSINESS("poi.business"),
110+
111+
/**
112+
* Selects government buildings.
113+
*/
114+
POI_GOVERNMENT("poi.government"),
115+
116+
/**
117+
* Selects emergency services, including hospitals, pharmacies, police, doctors, and others.
118+
*/
119+
POI_MEDICAL("poi.medical"),
120+
121+
/**
122+
* Selects parks.
123+
*/
124+
POI_PARK("poi.park"),
125+
126+
/**
127+
* Selects places of worship, including churches, temples, mosques, and others.
128+
*/
129+
POI_PLACE_OF_WORSHIP("poi.place_of_worship"),
130+
131+
/**
132+
* Selects schools.
133+
*/
134+
POI_SCHOOL("poi.school"),
135+
136+
/**
137+
* Selects sports complexes.
138+
*/
139+
POI_SPORTS_COMPLEX("poi.sports_complex"),
140+
141+
/**
142+
* Selects all roads.
143+
*/
144+
ROAD("road"),
145+
146+
/**
147+
* Selects arterial roads.
148+
*/
149+
ROAD_ARTERIAL("road.arterial"),
150+
151+
/**
152+
* Selects highways.
153+
*/
154+
ROAD_HIGHWAY("road.highway"),
155+
156+
/**
157+
* Selects highways with controlled access.
158+
*/
159+
ROAD_HIGHWAY_CONTROLLED_ACCESS("road.highway.controlled_access"),
160+
161+
/**
162+
* Selects local roads.
163+
*/
164+
ROAD_LOCAL("road.local"),
165+
166+
/**
167+
* Selects all transit stations and lines.
168+
*/
169+
TRANSIT("transit"),
170+
171+
/**
172+
* Selects transit lines.
173+
*/
174+
TRANSIT_LINE("transit.line"),
175+
176+
/**
177+
* Selects transit stations.
178+
*/
179+
TRANSIT_STATION("transit.station"),
180+
181+
/**
182+
* Selects airports.
183+
*/
184+
TRANSIT_STATION_AIRPORT("transit.station.airport"),
185+
186+
/**
187+
* Selects bus stops.
188+
*/
189+
TRANSIT_STATION_BUS("transit.station.bus"),
190+
191+
/**
192+
* Selects rail stations.
193+
*/
194+
TRANSIT_STATION_RAIL("transit.station.rail"),
195+
196+
/**
197+
* Selects bodies of water.
198+
*/
199+
WATER("water");
200+
201+
@Getter
202+
private String value;
203+
204+
FeatureType(String value) {
205+
this.value = value;
206+
}
207+
208+
}

0 commit comments

Comments
 (0)