Package com.cercalia.sdk.services
Class StaticMapsService
java.lang.Object
com.cercalia.sdk.CercaliaClient
com.cercalia.sdk.services.StaticMapsService
StaticMapsService - Generates static map images with markers, shapes, and labels.
This service allows you to create custom map images centered on coordinates or cities, with various overlays like markers, circles, polylines, and rectangles.
Example usage:
StaticMapsService service = new StaticMapsService(config);
// Simple map centered on a city
StaticMapResult result = service.generateCityMap("Barcelona", "ESP", 800, 600);
String url = result.getImageUrl();
// Complex map with markers and shapes
StaticMapOptions options = StaticMapOptions.builder()
.center(new Coordinate(41.38, 2.17))
.width(1024)
.height(768)
.addMarker(StaticMapMarker.builder(new Coordinate(41.38, 2.17)).label("Center").build())
.addShape(StaticMapCircle.builder(new Coordinate(41.38, 2.17), 500).fillColor("AA0000").build())
.build();
StaticMapResult complexResult = service.generateMap(options);
byte[] imageData = service.downloadImage(complexResult.getImageUrl());
- See Also:
-
Field Summary
Fields inherited from class com.cercalia.sdk.CercaliaClient
config, logger, objectMapper -
Constructor Summary
ConstructorsConstructorDescriptionStaticMapsService(@NotNull CercaliaConfig config) Creates a new StaticMapsService with the specified configuration. -
Method Summary
Modifier and TypeMethodDescription@org.jetbrains.annotations.NotNull byte[]downloadImage(@NotNull String imageUrl) Download the static map image as a byte array.@NotNull StaticMapResultgenerateCityMap(@NotNull String cityName, @NotNull String countryCode) Generate a map centered on a city with default dimensions.@NotNull StaticMapResultgenerateCityMap(@NotNull String cityName, @NotNull String countryCode, @Nullable Integer width, @Nullable Integer height) Generate a map centered on a city with a label.@NotNull StaticMapResultgenerateMap(@NotNull StaticMapOptions options) Generate a static map with optional markers and shapes.@NotNull StaticMapResultgenerateMapAsImage(@NotNull StaticMapOptions options) Generate map and return image data directly.@NotNull CompletableFuture<StaticMapResult>generateMapAsync(@NotNull StaticMapOptions options) Generate a static map asynchronously.@NotNull StaticMapResultgenerateMapWithCircle(@NotNull Coordinate center, int radius) Generate a map with a circle shape using default style.@NotNull StaticMapResultgenerateMapWithCircle(@NotNull Coordinate center, int radius, @Nullable StaticMapCircle circle, @Nullable Integer width, @Nullable Integer height) Generate a map with a circle shape.@NotNull StaticMapResultgenerateMapWithLabel(@NotNull Coordinate center, @NotNull String text, @Nullable Integer width, @Nullable Integer height) Generate a map with a label at a specific position.@NotNull StaticMapResultgenerateMapWithLine(@NotNull Coordinate start, @NotNull Coordinate end, @Nullable StaticMapLine line, @Nullable Integer width, @Nullable Integer height) Generate a map with a line between two points.@NotNull StaticMapResultgenerateMapWithMarkers(@NotNull List<StaticMapMarker> markers, @Nullable Integer width, @Nullable Integer height) Generate a map with markers.@NotNull StaticMapResultgenerateMapWithPolyline(@NotNull List<Coordinate> coordinates, @Nullable StaticMapPolyline polyline, @Nullable Integer width, @Nullable Integer height) Generate a map with a polyline.@NotNull StaticMapResultgenerateMapWithRectangle(@NotNull Coordinate upperLeft, @NotNull Coordinate lowerRight, @Nullable StaticMapRectangle rectangle, @Nullable String cityName, @Nullable Integer width, @Nullable Integer height) Generate a map with a rectangle shape.@NotNull StaticMapResultgenerateMapWithSector(@NotNull Coordinate center, int innerRadius, int outerRadius, int startAngle, int endAngle, @Nullable Integer width, @Nullable Integer height) Generate a map with a sector shape.Methods inherited from class com.cercalia.sdk.CercaliaClient
addIfPresent, addIfPresent, addIfPresent, addIfTrue, getConfig, newParams, newParams, request, request, requestAsync, requestAsync
-
Constructor Details
-
StaticMapsService
Creates a new StaticMapsService with the specified configuration.- Parameters:
config- the Cercalia configuration
-
-
Method Details
-
generateMap
Generate a static map with optional markers and shapes.- Parameters:
options- the map generation options- Returns:
- the generated map result
- Throws:
CercaliaException- if the request fails
-
generateMapAsync
@NotNull public @NotNull CompletableFuture<StaticMapResult> generateMapAsync(@NotNull @NotNull StaticMapOptions options) Generate a static map asynchronously.- Parameters:
options- the map generation options- Returns:
- CompletableFuture with the result
-
generateCityMap
@NotNull public @NotNull StaticMapResult generateCityMap(@NotNull @NotNull String cityName, @NotNull @NotNull String countryCode, @Nullable @Nullable Integer width, @Nullable @Nullable Integer height) Generate a map centered on a city with a label.- Parameters:
cityName- the city namecountryCode- the country code (e.g., "ESP")width- optional widthheight- optional height- Returns:
- the generated map result
-
generateCityMap
@NotNull public @NotNull StaticMapResult generateCityMap(@NotNull @NotNull String cityName, @NotNull @NotNull String countryCode) Generate a map centered on a city with default dimensions. -
generateMapWithCircle
@NotNull public @NotNull StaticMapResult generateMapWithCircle(@NotNull @NotNull Coordinate center, int radius, @Nullable @Nullable StaticMapCircle circle, @Nullable @Nullable Integer width, @Nullable @Nullable Integer height) Generate a map with a circle shape.- Parameters:
center- the center coordinateradius- the radius in meterscircle- optional circle style (uses defaults if null)width- optional widthheight- optional height- Returns:
- the generated map result
-
generateMapWithCircle
@NotNull public @NotNull StaticMapResult generateMapWithCircle(@NotNull @NotNull Coordinate center, int radius) Generate a map with a circle shape using default style. -
generateMapWithRectangle
@NotNull public @NotNull StaticMapResult generateMapWithRectangle(@NotNull @NotNull Coordinate upperLeft, @NotNull @NotNull Coordinate lowerRight, @Nullable @Nullable StaticMapRectangle rectangle, @Nullable @Nullable String cityName, @Nullable @Nullable Integer width, @Nullable @Nullable Integer height) Generate a map with a rectangle shape.- Parameters:
upperLeft- the upper left cornerlowerRight- the lower right cornerrectangle- optional rectangle stylecityName- optional city name for centeringwidth- optional widthheight- optional height- Returns:
- the generated map result
-
generateMapWithPolyline
@NotNull public @NotNull StaticMapResult generateMapWithPolyline(@NotNull @NotNull List<Coordinate> coordinates, @Nullable @Nullable StaticMapPolyline polyline, @Nullable @Nullable Integer width, @Nullable @Nullable Integer height) Generate a map with a polyline.- Parameters:
coordinates- the polyline coordinatespolyline- optional polyline stylewidth- optional widthheight- optional height- Returns:
- the generated map result
-
generateMapWithLine
@NotNull public @NotNull StaticMapResult generateMapWithLine(@NotNull @NotNull Coordinate start, @NotNull @NotNull Coordinate end, @Nullable @Nullable StaticMapLine line, @Nullable @Nullable Integer width, @Nullable @Nullable Integer height) Generate a map with a line between two points.- Parameters:
start- the start coordinateend- the end coordinateline- optional line stylewidth- optional widthheight- optional height- Returns:
- the generated map result
-
generateMapWithMarkers
@NotNull public @NotNull StaticMapResult generateMapWithMarkers(@NotNull @NotNull List<StaticMapMarker> markers, @Nullable @Nullable Integer width, @Nullable @Nullable Integer height) Generate a map with markers.- Parameters:
markers- the markers to placewidth- optional widthheight- optional height- Returns:
- the generated map result
-
generateMapWithLabel
@NotNull public @NotNull StaticMapResult generateMapWithLabel(@NotNull @NotNull Coordinate center, @NotNull @NotNull String text, @Nullable @Nullable Integer width, @Nullable @Nullable Integer height) Generate a map with a label at a specific position.- Parameters:
center- the label positiontext- the label textwidth- optional widthheight- optional height- Returns:
- the generated map result
-
generateMapWithSector
@NotNull public @NotNull StaticMapResult generateMapWithSector(@NotNull @NotNull Coordinate center, int innerRadius, int outerRadius, int startAngle, int endAngle, @Nullable @Nullable Integer width, @Nullable @Nullable Integer height) Generate a map with a sector shape.- Parameters:
center- the center coordinateinnerRadius- the inner radiusouterRadius- the outer radiusstartAngle- the start angle in degreesendAngle- the end angle in degreeswidth- optional widthheight- optional height- Returns:
- the generated map result
-
downloadImage
@NotNull public @org.jetbrains.annotations.NotNull byte[] downloadImage(@NotNull @NotNull String imageUrl) Download the static map image as a byte array.- Parameters:
imageUrl- the image URL- Returns:
- the image bytes
- Throws:
CercaliaException- if download fails
-
generateMapAsImage
@NotNull public @NotNull StaticMapResult generateMapAsImage(@NotNull @NotNull StaticMapOptions options) Generate map and return image data directly.- Parameters:
options- the map generation options (returnImage is ignored)- Returns:
- the result with imageData populated
-