## Symbol Resource

The symbol resource represents the symbols used in a map, such as marker symbols, line symbols, or fill symbols. To retrieve the corresponding symbol images, you can implement the GET request with parameters included in the URI. The ID of the symbol in style is the only unique field among these parameters.

### HTTP Request Methods

Supported methods for the symbol resource are:

- `GET`: Gets the image of a specific symbol. This method returns the image in the specified format (PNG, BMP, GIF, JPG, RJSON, JSON, HTML, XML).

- `HEAD`: Checks if the symbol resource exists and can be accessed by making a simple HTTP request to the URI without any response body.

### Example URI

To implement this functionality using a GET request, you would use the following URI:

```arduino

/symbol[.]

```

Replace `` with the base URL of your MapProxy server, and `` with the desired output format (PNG, BMP, GIF, JPG, RJSON, JSON, HTML, XML). For example:

```arduino

https://supermapiserver.example.com/worldmap/symbol?id=123&type=marker&style=red&format=PNG

```

In this example, we're retrieving the red marker symbol with ID 123 from the WorldMap map. We specify that we want the output in PNG format.

## 获取符号图片

### 请求方式

```http

GET http://supermapiserver:8090/iserver/services/map-world/rest/maps/WorldMap/symbol.bmp

```

### 请求参数

在实现符号资源的GET请求时,需要在URI中包含以下参数:

| 字段 | 类型 | 定义 |

| --- | --- | --- |

| resourceType | ResourceType | [必需] | 符号的类型:标记符号、线型符号、填充符号等。|

| style | Style | [必需] | 符号的样式。|

| redirect | boolean | 是否重定向。如果为true,则请求将被重定向到图像的实际地址;如果为false,则图像的字节流将在响应体中。默认为true。|

| picWidth | int | 目标符号图像的宽度。默认宽度为64像素。|

| picHeight | int | 目标符号图像的高度。默认高度为64像素。|

| _cache | boolean | 是否使用缓存,默认为True。如果为false,则关闭所有缓存。|

### 响应结构

成功时返回如下响应:

```json

{"succeed":true,"resourceType":"marker symbol","style":{"color":"red","size":"10px"},"redirect":true,"url":"http://localhost:8090/iserver/services/map- world/rest/maps/WorldMap/symbol.bmp?picWidth=32&picHeight=32&_cache=false", "id":"d45f375b-c9a6-4f3d-92f6-6c8b7a1b5e9f"}

```

The output image format can be specified when retrieving the map symbol. The available formats are PNG, BMP, GIF, or JPG. If a non-transparent image is requested, it will be returned in the specified format.

Alternatively, when retrieving information about the map symbol, the output format can be RJSON, JSON, HTML, or XML. The returned representation includes several fields as follows:

Field| Type| Definition

---|---|---

resourceImageUrl| String| A URI to the symbol image, which must be in PNG format.

resourceParameter| ResourceParameter| Information about the symbol image, such as its width, height, and style from the source image.

For example, if you want to retrieve the map symbol information and specify the output format as JSON, you can use the following code snippet:

```python

import requests

url = "your_map_symbol_api_endpoint"

params = {"format": "JSON"}

response = requests.get(url, params=params)

data = response.json()

# Process the data as needed

# ...

```

Make sure to replace `"your_map_symbol_api_endpoint"` with the actual API endpoint for retrieving map symbols based on your specific needs.

To implement a GET request on the symbol resource with the given parameters, you can follow these steps:

1. Construct the URL by appending the necessary query parameters to the base URL. In this case, the URL would be: `http://supermapiserver:8090/iserver/services/map-world/rest/maps/WorldMap/symbol.png?resourceType=SYMBOLLINE&style=fillBackOpaque%3Atrue%2ClineWidth%3A0.1%2CfillBackColor%3Ared%3A255%2Cblue%3A255%2Cgreen%3A255%2CfillForeColor%3Ared%3A208%2Cblue%3A240%2Cgreen%3A255%2CmarkerAngle%3A0%2CmarkerSize%3A50%2CfillGradientOffsetRatioX%3A0%2CfillGradientOffsetRatioY%3A0%2ClineColor%3Ared%3A0%2Cblue%3A0%2Cgreen%3A128%2CfillOpaqueRate%3A100%2CfillGradientMode%3ANONE%2CfillSymbolID%3A76%2CfillGradientAngle%3A0%2CmarkerSymbolID%3A10%2ClineSymbolID%3A34`

Note that we have used `&` instead of `&` for the ampersand in the query string, as it is needed to avoid encoding issues.

2. Send an HTTP GET request to the constructed URL using your preferred HTTP client library or tool. For example, if you're using Python and the `requests` library, the code would look like:

```python

import requests

url = "http://supermapiserver:8090/iserver/services/map-world/rest/maps/WorldMap/symbol.png?resourceType=SYMBOLLINE&style=fillBackOpaque:true,lineWidth:0.1,fillBackColor:red:255,blue:255,green:255,fillForeColor:red:208,blue:240,green:255,markerAngle:0,markerSize:50,fillGradientOffsetRatioX:0,fillGradientOffsetRatioY:0,lineColor:red:0,blue:0,green:128,fillOpaqueRate:100,fillGradientMode:NONE,fillSymbolID:76,fillGradientAngle:0,markerSymbolID:10,lineSymbolID:34"

response = requests.get(url)

# Check if the request was successful (status code 200)

if response.status_code == 200:

# Process the response content (e.g. save it to a file)

with open("symbol_image.png", "wb") as f:

f.write(response.content)

else:

print(f"Request failed with status code {response.status_code}")

```

Make sure to replace the `url` variable with your actual URL if it differs from the provided one. Additionally, adjust the code inside the `if` statement based on how you want to process the response content (e.g. saving it to a file).

HEAD请求的响应与对应于GET请求的响应相同,但不包含响应体。这对于检索写在响应头中的元信息非常有用,而无需传输整个内容。元信息包括媒体类型、内容编码、传输编码、内容长度等。

HEAD请求有助于检查符号资源的存在以及客户端是否可以访问它。通过在URI上实现HEAD请求并在其后附加.<格式>,我们可以快速了解符号资源是否支持以.<;格式>表示。

参考:ERROR: 变量(map_link)未定义。