

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 如何向静态地图添加线条
<a name="how-to-add-line-static"></a>

 在本主题中，您将了解如何使用 Amazon Location Service 向静态地图添加线条。我们将介绍支持的样式选项，介绍如何使用 GeoJSON 定义线条，以及如何应用颜色、宽度和轮廓等自定义样式。我们还将探讨如何对线宽等属性使用不同的测量单位。

## 支持的样式设置
<a name="supported-styling"></a>


| 名称 | 类型 | 默认值 | 描述 | 
| --- | --- | --- | --- | 
| `color` | 颜色 | 取决于样式 | 线条颜色。 | 
| `width` | 整数/字符串 | 2 | 线宽。有关更多信息，请参阅 [如何向静态地图添加线条](#how-to-add-line-static)。 | 
| `outline-color`  | 颜色 | 取决于样式 | 线条轮廓颜色。 | 
|  `outline-width`  | 整数/字符串 | 0（已关闭） | 轮廓的宽度。有关更多信息，请参阅 [如何向静态地图添加线条](#how-to-add-line-static)。 | 

## 支持的单位
<a name="supported-unit"></a>


| 单位 | 描述 | 
| --- | --- | 
| 整数，例如 `5` | 像素 | 
| 没有单位的字符串，例如 `"5"` | 像素 | 
| `"px"` | 像素 | 
| `"m"` | 米 | 
|  `"km"`  | 公里 | 
| `"mi"` | 英里 | 
| `"ft"` | 英尺 | 
| `"yd"` | 码 | 
| `"%"` | 特定属性的默认值百分比（以像素为单位）。例如，如果 `width` 的默认值为 `2` 像素，则 `200%` 为 `4` 像素。`%` 是敏感字符，必须在请求 URL 中将其编码为 `%25`。 | 

## 添加线条
<a name="add-a-line"></a>

 在本示例中，您将添加一条从温哥华某个地点到斯坦利公园的线。这条线是使用具有所定义坐标的 GeoJSON 格式创建的。

------
#### [ Request ]

```
{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [-123.11813, 49.28246],
          [-123.11967, 49.28347],
          [-123.12108, 49.28439],
          [-123.12216, 49.28507],
          [-123.12688, 49.28812],
          [-123.1292, 49.28964],
          [-123.13216, 49.2916],
          [-123.13424, 49.29291],
          [-123.13649, 49.2944],
          [-123.13678, 49.29477],
          [-123.13649, 49.29569],
          [-123.13657, 49.29649],
          [-123.13701, 49.29715],
          [-123.13584, 49.29847],
          [-123.13579, 49.29935],
          [-123.13576, 49.30018],
          [-123.13574, 49.30097]
        ]
      },
      "properties": {
        "name": "To Stanley Park",
        "description": "An evening walk to Stanley Park."
      }
    }
  ]
}
```

------
#### [ Request URL ]

```
https://maps.geo.eu-central-1.amazonaws.com/v2/static/map?style=Satellite&width=1024&height=1024&padding=200&scale-unit=KilometersMiles&geojson-overlay=%7B%22type%22%3A%22FeatureCollection%22,%22features%22%3A%5B%7B%22type%22%3A%22Feature%22,%22geometry%22%3A%7B%22type%22%3A%22LineString%22,%22coordinates%22%3A%5B%5B-123.11813,49.28246%5D,%5B-123.11967,49.28347%5D,%5B-123.12108,49.28439%5D,%5B-123.12216,49.28507%5D,%5B-123.12688,49.28812%5D,%5B-123.1292,49.28964%5D,%5B-123.13216,49.2916%5D,%5B-123.13424,49.29291%5D,%5B-123.13649,49.2944%5D,%5B-123.13678,49.29477%5D,%5B-123.13649,49.29569%5D,%5B-123.13657,49.29649%5D,%5B-123.13701,49.29715%5D,%5B-123.13584,49.29847%5D,%5B-123.13579,49.29935%5D,%5B-123.13576,49.30018%5D,%5B-123.13574,49.30097%5D%5D%7D,%22properties%22%3A%7B%22name%22%3A%22To%20Stanley%20Park%22,%22description%22%3A%22An%20evening%20walk%20to%20Stanley%20Park.%22%7D%7D%5D%7D&key=API_KEY
```

------
#### [ Response image ]

![\[Aerial view of coastal city with dense urban area, marina, and surrounding forests.\]](http://docs.aws.amazon.com/zh_cn/location/latest/developerguide/images/static-add-line.png)


------

## 为线条添加样式
<a name="add-styling"></a>

 在本示例中，您将为前一个示例中添加的线条设置样式。这包括定义线条的颜色、宽度、轮廓颜色和轮廓宽度，以自定义线条在地图上的视觉外观。

------
#### [ Request ]

```
{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [-123.11813, 49.28246],
          [-123.11967, 49.28347],
          [-123.12108, 49.28439],
          [-123.12216, 49.28507],
          [-123.12688, 49.28812],
          [-123.1292, 49.28964],
          [-123.13216, 49.2916],
          [-123.13424, 49.29291],
          [-123.13649, 49.2944],
          [-123.13678, 49.29477],
          [-123.13649, 49.29569],
          [-123.13657, 49.29649],
          [-123.13701, 49.29715],
          [-123.13584, 49.29847],
          [-123.13579, 49.29935],
          [-123.13576, 49.30018],
          [-123.13574, 49.30097]
        ]
      },
      "properties": {
        "color": "#6d34b3", 
        "width": "9m",
        "outline-color": "#a8b9cc",  
        "outline-width": "2px"
      }
    }
  ]
}
```

------
#### [ Request URL ]

```
https://maps.geo.eu-central-1.amazonaws.com/v2/static/map?style=Satellite&width=1024&height=1024&padding=200&scale-unit=KilometersMiles&geojson-overlay=%7B%22type%22%3A%22FeatureCollection%22,%22features%22%3A%5B%7B%22type%22%3A%22Feature%22,%22geometry%22%3A%22LineString%22,%22coordinates%22%3A%5B%5B-123.11813,49.28246%5D,%5B-123.11967,49.28347%5D,%5B-123.12108,49.28439%5D,%5B-123.12216,49.28507%5D,%5B-123.12688,49.28812%5D,%5B-123.1292,49.28964%5D,%5B-123.13216,49.2916%5D,%5B-123.13424,49.29291%5D,%5B-123.13649,49.2944%5D,%5B-123.13678,49.29477%5D,%5B-123.13649,49.29569%5D,%5B-123.13657,49.29649%5D,%5B-123.13701,49.29715%5D,%5B-123.13584,49.29847%5D,%5B-123.13579,49.29935%5D,%5B-123.13576,49.30018%5D,%5B-123.13574,49.30097%5D%5D%7D,%22properties%22%3A%7B%22color%22%3A%22%236d34b3%22,%22width%22%3A%229m%22,%22outline-color%22%3A%22%23a8b9cc%22,%22outline-width%22%3A%222px%22%7D%7D%5D%7D&key=API_KEY
```

------
#### [ Response image ]

![\[Aerial view of coastal city with dense urban area, marina, and surrounding forests.\]](http://docs.aws.amazon.com/zh_cn/location/latest/developerguide/images/static-add-line-styling.png)


------