[comment]: # translation:outdated

[comment]: # ({b243934a-0067e4a0})
# 创建

[comment]: # ({/b243934a-0067e4a0})

[comment]: # ({f4dd7559-1b2ce1e9})
### 描述

`object map.create(object/array maps)`

这个方法允许创建一个新的拓扑图。

[comment]: # ({/f4dd7559-1b2ce1e9})

[comment]: # ({e1a8d0e1-73d879ea})
### 参数

`(object/array)` Maps to create.

除了[standard map properties](object#map)之外，该方法还接受以下参数。

|Parameter|Type|Description|
|---------|----|-----------|
|links|array|拓扑图上创建拓扑图链接|
|selements|array|拓扑图上创建拓扑图元素|
|urls|array|拓扑图上创建拓扑图URL|
|users|array|拓扑图共享用户|
|userGroups|array|拓扑图共享用户组|
|shapes|array|拓扑图上创建拓扑图图形|
|lines|array|拓扑图上创建拓扑图线|

::: notetip
To create map links you'll need to set a map elements
`selementid` to an arbitrary value and then use this value to reference
this element in the links `selementid1` or `selementid2` properties.
When the element is created, this value will be replaced with the
correct ID generated by Zabbix. [See example.](create#create_a_host_map)
要创建映射链接，您需要将映射元素设置为任意值，然后使用该值在链接`selectd1`或`selemand2`属性中引用该元素。在创建元素时，将用Zabbix生成的正确ID替换该值。
:::

[comment]: # ({/e1a8d0e1-73d879ea})

[comment]: # ({3d9d42a7-2e617567})
### 返回值

`(对象)`返回一个对象，该对象包含在“sysmapid”属性下创建的拓扑图的id。返回id的顺序与传递的拓扑图的顺序相匹配。

[comment]: # ({/3d9d42a7-2e617567})

[comment]: # ({10b44098-b41637d2})
### 例子

[comment]: # ({/10b44098-b41637d2})

[comment]: # ({41481806-584ef8f6})
#### 创建一个空的拓扑图

创建一个拓扑图没有任何元素。

Request:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "map.create",
    "params": {
        "name": "Map",
        "width": 600,
        "height": 600
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Response:

``` {.java}
{
    "jsonrpc": "2.0",
    "result": {
        "sysmapids": [
            "8"
        ]
    },
    "id": 1
}
```

[comment]: # ({/41481806-584ef8f6})

[comment]: # ({0668a9c9-e32540ab})
#### 创建一个主机拓扑图

创建一个关于两个主机的拓扑图，并且关联他们，需要注意的是在地图上临时使用"selementid1"和"selementid2"的值来引用地图元素。

Request:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "map.create",
    "params": {
        "name": "Host map",
        "width": 600,
        "height": 600,
        "selements": [
            {
                "selementid": "1",
                "elements": [
                    {"hostid": "1033"}
                ],
                "elementtype": 0,
                "iconid_off": "2"
            },

            {
                "selementid": "2",
                "elements": [
                    {"hostid": "1037"}
                ],
                "elementtype": 0,
                "iconid_off": "2"
            }
        ],
        "links": [
            {
                "selementid1": "1",
                "selementid2": "2"
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Response:

``` {.java}
{
    "jsonrpc": "2.0",
    "result": {
        "sysmapids": [
            "9"
        ]
    },
    "id": 1
}
```

[comment]: # ({/0668a9c9-e32540ab})

[comment]: # ({54767654-9a8ffa0d})
#### 创建一个触发器拓扑图

创建一个关于触发器元素的拓扑图，包含两个触发器。

Request:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "map.create",
    "params": {
        "name": "Trigger map",
        "width": 600,
        "height": 600,
        "selements": [
            {
                "elements": [
                    {"triggerid": "12345"},
                    {"triggerid": "67890"}
                ],
                "elementtype": 2,
                "iconid_off": "2"
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Response:

``` {.java}
{
    "jsonrpc": "2.0",
    "result": {
        "sysmapids": [
            "10"
        ]
    },
    "id": 1
}
```

[comment]: # ({/54767654-9a8ffa0d})

[comment]: # ({ec696ee0-d8024143})
#### 拓扑图共享

创建一个关于两种共享类项（用户和用户组）的拓扑图。

Request:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "map.create",
    "params": {
        "name": "Map sharing",
        "width": 600,
        "height": 600,
        "users": [
            {
                "userid": "4",
                "permission": "3"
            }
        ],
        "userGroups": [
            {
                "usrgrpid": "7",
                "permission": "2"
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Response:

``` {.java}
{
    "jsonrpc": "2.0",
    "result": {
        "sysmapids": [
            "9"
        ]
    },
    "id": 1
}
```

[comment]: # ({/ec696ee0-d8024143})

[comment]: # ({ff86b360-2fa44a8b})
#### 拓扑图形状

创建一个带有主题的拓扑图。

Request:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "map.create",
    "params": {
        "name": "Host map",
        "width": 600,
        "height": 600,
        "shapes": [
            {
                "type": 0,
                "x": 0,
                "y": 0,
                "width": 600,
                "height": 11,
                "text": "{MAP.NAME}"
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Response:

``` {.java}
{
    "jsonrpc": "2.0",
    "result": {
        "sysmapids": [
            "10"
        ]
    },
    "id": 1
}
```

[comment]: # ({/ff86b360-2fa44a8b})

[comment]: # ({5aa58242-5aa58242})
#### Map lines

Create a map line.

Request:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "map.create",
    "params": {
        "name": "Map API lines",
        "width": 500,
        "height": 500,
        "lines": [
            {
                "x1": 30,
                "y1": 10,
                "x2": 100,
                "y2": 50,
                "line_type": 1,
                "line_width": 10,
                "line_color": "009900"
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Response:

``` {.java}
{
    "jsonrpc": "2.0",
    "result": {
        "sysmapids": [
            "11"
        ]
    },
    "id": 1
}
```

[comment]: # ({/5aa58242-5aa58242})

[comment]: # ({436079d5-436079d5})
### See also

-   [Map element](object#map_element)
-   [Map link](object#map_link)
-   [Map URL](object#map_url)
-   [Map user](object#map_user)
-   [Map user group](object#map_user_group)
-   [Map shape](object#map_shapes)
-   [Map line](object#map_lines)

[comment]: # ({/436079d5-436079d5})

[comment]: # ({9af1ee5b-a9533b09})
### Source

CMap::create() in *frontends/php/include/classes/api/services/CMap.php*.

[comment]: # ({/9af1ee5b-a9533b09})
