To display a polyline on a static map/with-polyline endpoint from the ArcGIS Static Maps servicex,y coordinate pairs in the polyline parameter to define the path. You can also specify the polyline color, line style, and width. Additionally, specify the image width and height in pixels, along with the output format (png, jpeg, or webp).
How to display a static map with a polyline
The typical workflow to display a static map with a polyline is:
- Map: Define the
basemapand map area withStyle centerandX center, andY zoomorradius. - Geometry: Define the
polylinearray containing the x,y coordinate pairs that define the polyline. - Image: Specify the image size
heightandwidthin pixels,format, andattributionstyle. - Request: Send a
GETrequest to the/with-polylineendpoint to generate the static map.
Service URL
https://static-maps-api.arcgis.com/arcgis/rest/services/static-maps-service/v1/static-mapsPath parameters
These are required parameters to specify the style to access.
https://static-maps-api.arcgis.com/arcgis/rest/services/static-maps-service/v1/static-maps/{basemapStyle}/with-polyline| Name | Description | Example |
|---|---|---|
{version} | Required: The API version. | v1 |
{basemap | Required: The basemap style for the static map. | arcgis/navigation, arcgis/navigation-night, arcgis/imagery, arcgis/streets-night, or arcgis/streets |
Query parameters
| Name | Type | Required | Default value | Description |
|---|---|---|---|---|
token | string | | An access token with the static maps service privilege. To pass the token as an authorization header, see HTTP authorization headers. | |
polyline | PathGeometryGet | | An array of x,y coordinate pairs defining a polyline in WGS84 spatial reference. Accepts 2 to 10 coordinate pairs. | |
endSymbolLabel | SymbolLabel | | Label displayed on the point symbol at the end of a polyline. Accepts 1–2 alphanumeric characters ( | |
endSymbolColor | string | 007 | Point symbol color at the end of a polyline in hexadecimal format. | |
endSymbolStyle | SymbolStyle | pin | Point symbol style at the end of the polyline. Supported values include | |
lineColor | HexColor | 007 | Line symbol color in hexadecimal format. | |
lineStyle | LineStyle | solid | Line symbol stroke applied to the polyline. Supported values include | |
lineWidth | integer | 4 | Line symbol width in device-independent pixels. Values range from | |
format | ImageFormat | webp | Output image format of the map. Supported formats include | |
height | ImageDimensionHeight | 400 | Height of the map image in pixels. Values must be between | |
width | ImageDimensionWidth | 400 | Width of the map image in pixels. Values must be between | |
padding | ImagePadding | 10 | Padding percentages around the map extent. Accepts an array of 1–4 values; default is | |
startSymbolLabel | SymbolLabel | | Label displayed on the point symbol at the start of a polyline. Accepts 1–2 alphanumeric characters ( | |
startSymbolColor | string | 007 | Point symbol color at the start of a polyline in hexadecimal format. | |
startSymbolStyle | SymbolStyle | pin | Point symbol style at the start of the polyline. Supported values include | |
symbolScale | SymbolScale | 1 | Scale factor applied to the point symbol size. Values range from | |
centerX | number(double) | | X-coordinate of the map center in WGS84 decimal degrees. Values range from | |
centerY | number(double) | | Y-coordinate of the map center in WGS84 decimal degrees. Values range from | |
zoom | ZoomLevel | | A number that defines the level of detail of the map. Values range from | |
radius | RadiusDistance | | A number (in meters) that defines the minimum geographic area around a center point of the map. If no center point is supplied, the radius is applied to the geometry. Values range from | |
attribution | string | auto | Attribution footer style. To learn more about attribution requirements for static maps, see Esri and data attribution. | |
referenceDetails | string | all | A basemap option that controls the visibility of labels and feature symbology. This parameter is currently supported only for the |
Code examples
Display a polyline for a driving route
Use the Static Maps service to draw a line representing a route on a static map. The image is displayed in a rideshare receipt along with details such as pick-up and drop-off points, distance, travel time, and fare breakdown. The image uses a pin to represent the destination and a circle to indicate the starting point.
Steps
- Reference the service.
- Define the polyline as an array of
x,ycoordinate pairs in the WGS84 spatial reference. - Set the API key in the
Authorizationrequest header using theBearerauthentication scheme. - Send the request to the Static Maps service to generate the static map.
fetch(
`https://static-maps-api.arcgis.com/arcgis/rest/services/static-maps-service/v1/static-maps/${basemapStyle}/with-polyline?polyline=${JSON.stringify(route)}&startSymbolStyle=circle&endSymbolStyle=pin&symbolScale=1&lineColor=007AC2&startSymbolColor=35AB46&endSymbolColor=F36F21&lineWidth=5&width=400&height=500&format=png&zoom=13`,
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
}
)
.then((response) => response.blob())
.then((blob) => {
document.getElementById("mapImage").src = URL.createObjectURL(blob);
});
REST API
curl -X GET "https://static-maps-api.arcgis.com/arcgis/rest/services/static-maps-service/v1/static-maps/arcgis/streets/with-polyline?polyline=[[-116.51055445979493,33.82303750349174],[-116.53701714772251,33.82306348953144],[-116.5368920286327,33.82677940662155],[-116.53958208906323,33.826857361194676]]&startSymbolStyle=circle&endSymbolStyle=pin&symbolScale=1&lineColor=007AC2&startSymbolColor=35AB46&endSymbolColor=F36F21&lineWidth=5&width=400&height=500&format=png" \
-H "Authorization: Bearer <ACCESS_TOKEN>"Tutorials
