Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add possibility to style map features and elements #137

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.flowingcode.vaadin.addons</groupId>
<artifactId>google-maps</artifactId>
<version>2.0.1-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
<name>Google Maps Addon</name>
<description>Integration of google-map for Vaadin platform</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

package com.flowingcode.vaadin.addons.googlemaps;

import com.flowingcode.vaadin.addons.googlemaps.maptypestyle.ElementType;
import com.flowingcode.vaadin.addons.googlemaps.maptypestyle.FeatureType;
import com.flowingcode.vaadin.addons.googlemaps.maptypestyle.MapStyle;
import com.vaadin.flow.component.ClickEvent;
import com.vaadin.flow.component.ClientCallable;
import com.vaadin.flow.component.Component;
Expand Down Expand Up @@ -849,4 +852,17 @@ public void closeFullScreen() {
.executeJs("document.exitFullscreen();");
}

/**
* Sets style formatting to the {@link FeatureType features} and {@link ElementType elements} of the map.
*
* @param mapStyles formatting to be applied to the map features and elements
*/
public void setMapStyle(MapStyle... mapStyles) {
JsonArray jsonArray = Json.createArray();
for (int i = 0; i < mapStyles.length; i++) {
MapStyle mapStyle = mapStyles[i];
jsonArray.set(i, mapStyle.getJson());
}
this.getElement().setPropertyJson("styles", jsonArray);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*-
* #%L
* Google Maps Addon
* %%
* Copyright (C) 2020 - 2024 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.maptypestyle;

import lombok.Getter;

/**
* Enum representing supported element types. Elements are subdivisions of a feature.
*/
public enum ElementType {

/**
* Selects all elements of the specified feature. Is the default option.
*/
ALL("all"),

/**
* Selects all geometric elements of the specified feature.
*/
GEOMETRY("geometry"),

/**
* Selects only the fill of the feature's geometry.
*/
GEOMETRY_FILL("geometry.fill"),

/**
* Selects only the stroke of the feature's geometry.
*/
GEOMETRY_STROKE("geometry.stroke"),

/**
* Selects the textual labels associated with the specified feature.
*/
LABELS("labels"),

/**
* Selects only the icon displayed within the feature's label.
*/
LABELS_ICON("labels.icon"),

/**
* Selects only the text of the label.
*/
LABELS_TEXT("labels.text"),

/**
* Selects only the fill of the label. The fill of a label is typically rendered as a colored
* outline that surrounds the label text.
*/
LABELS_TEXT_FILL("labels.text.fill"),

/**
* Selects only the stroke of the label's text.
*/
LABELS_TEXT_STROKE("labels.text.stroke");

@Getter
private String value;

ElementType(String value) {
this.value = value;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
/*-
* #%L
* Google Maps Addon
* %%
* Copyright (C) 2020 - 2024 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.maptypestyle;

import lombok.Getter;

/**
* Enum representing supported feature types. Features are geographic characteristics on the
* map, including roads, parks, bodies of water, businesses, and more.
*/
public enum FeatureType {

/**
* Selects all features. Is the default option.
*/
ALL("all"),

/**
* Selects all administrative areas. Styling affects only the labels of administrative areas, not
* the geographical borders or fill.
*/
ADMINISTRATIVE("administrative"),

/**
* Selects countries.
*/
ADMINISTRATIVE_COUNTRY("administrative.country"),

/**
* Selects land parcels.
*/
ADMINISTRATIVE_LAND_PARCEL("administrative.land_parcel"),


/**
* Selects localities.
*/
ADMINISTRATIVE_LOCALITY("administrative.locality"),


/**
* Selects neighborhoods.
*/
ADMINISTRATIVE_NEIGHBORHOOD("administrative.neighborhood"),


/**
* Selects provinces.
*/
ADMINISTRATIVE_PROVINCE("administrative.province"),

/**
* Selects all landscapes.
*/
LANDSCAPE("landscape"),

/**
* Selects man-made features, such as buildings and other structures.
*/
LANDSCAPE_MAN_MADE("landscape.man_made"),

/**
* Selects natural features, such as mountains, rivers, deserts, and glaciers..
*/
LANDSCAPE_NATURAL("landscape.natural"),

/**
* Selects land cover features, the physical material that covers the earth's surface, such as
* forests, grasslands, wetlands, and bare ground..
*/
LANDSCAPE_NATURAL_LANDCOVER("landscape.natural.landcover"),

/**
* Selects terrain features of a land surface, such as elevation, slope, and orientation.
*/
LANDSCAPE_NATURAL_TERRAIN("landscape.natural.terrain"),

/**
* Selects all points of interest.
*/
POI("poi"),

/**
* Selects tourist attractions.
*/
POI_ATTRACTION("poi.attraction"),

/**
* Selects businesses.
*/
POI_BUSINESS("poi.business"),

/**
* Selects government buildings.
*/
POI_GOVERNMENT("poi.government"),

/**
* Selects emergency services, including hospitals, pharmacies, police, doctors, and others.
*/
POI_MEDICAL("poi.medical"),

/**
* Selects parks.
*/
POI_PARK("poi.park"),

/**
* Selects places of worship, including churches, temples, mosques, and others.
*/
POI_PLACE_OF_WORSHIP("poi.place_of_worship"),

/**
* Selects schools.
*/
POI_SCHOOL("poi.school"),

/**
* Selects sports complexes.
*/
POI_SPORTS_COMPLEX("poi.sports_complex"),

/**
* Selects all roads.
*/
ROAD("road"),

/**
* Selects arterial roads.
*/
ROAD_ARTERIAL("road.arterial"),

/**
* Selects highways.
*/
ROAD_HIGHWAY("road.highway"),

/**
* Selects highways with controlled access.
*/
ROAD_HIGHWAY_CONTROLLED_ACCESS("road.highway.controlled_access"),

/**
* Selects local roads.
*/
ROAD_LOCAL("road.local"),

/**
* Selects all transit stations and lines.
*/
TRANSIT("transit"),

/**
* Selects transit lines.
*/
TRANSIT_LINE("transit.line"),

/**
* Selects transit stations.
*/
TRANSIT_STATION("transit.station"),

/**
* Selects airports.
*/
TRANSIT_STATION_AIRPORT("transit.station.airport"),

/**
* Selects bus stops.
*/
TRANSIT_STATION_BUS("transit.station.bus"),

/**
* Selects rail stations.
*/
TRANSIT_STATION_RAIL("transit.station.rail"),

/**
* Selects bodies of water.
*/
WATER("water");

@Getter
private String value;

FeatureType(String value) {
this.value = value;
}

}
Loading
Loading