Skip to content

Commit

Permalink
feat: add possibility to style map features and elements
Browse files Browse the repository at this point in the history
Close #123
  • Loading branch information
paodb authored and javier-godoy committed Aug 21, 2024
1 parent 4e47357 commit f757778
Show file tree
Hide file tree
Showing 9 changed files with 701 additions and 0 deletions.
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

0 comments on commit f757778

Please sign in to comment.