PolygonLayer
Example
Example Source Code
vue
<template>
<div style="height: 400px" class="vw-full vh-full">
<mb-map>
<div style="position: absolute; top: 5px; left: 5px">
<button class="primary" @click="colorIndex++">Switch Color</button>
</div>
<mb-tianditu-layer />
<mb-polygon-layer
:data="polygonCoordinates"
:color="color"
outline-color="yellow"
/>
</mb-map>
</div>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue'
const colors = ['rgba(255,125,0,0.5)', '#ec71a9', 'red']
const colorIndex = ref(0)
const polygonCoordinates = [
{
coordinates: [
[110.56640625, 39.639537564366684],
[107.22656249999999, 36.527294814546245],
[107.57812499999999, 32.39851580247402],
[112.5, 30.600093873550072],
[117.42187500000001, 32.02670629333614],
[117.24609374999999, 36.94989178681327],
[114.697265625, 39.70718665682654],
[110.56640625, 39.639537564366684],
],
},
{
coordinates: [
[82.08984375, 32.47269502206151],
[90.966796875, 32.47269502206151],
[90.966796875, 38.685509760012],
[82.08984375, 38.685509760012],
[82.08984375, 32.47269502206151],
],
},
]
const color = computed(() => colors[colorIndex.value % colors.length])
</script>
API
PROPS
Name | Description | Type | Default |
---|---|---|---|
id | Layer ID | string | - |
color | Color value. Supports modes such as "#000000", "rgb(0,0,0)", [255,0,0,1] | string / number[] | #000000 |
data | Data for the vector layer. Each object in the array must contain the required coordinates property and the optional properties property. Each object represents a point/line/polygon | VectorLayerData | - |
geo-json-data-source | GeoJSON data source. Can be set to a GeoJSON data link or a GeoJSON data object. Specification Link. If this property is set, the data property is ignored | string / GeoJSONSource | - |
opacity | Opacity | number | 1 |
outline-color | Outline color | string / number[] | #000 |
maxzoom | Maximum zoom level | number | 22 |
minzoom | Minimum zoom level | number | 0 |
pickable | Whether the layer responds to pick events. If false , the component will not emit mouse-related events | boolean | true |
show | Whether to show the layer | boolean | true |
source-id | ID of the layer's source. If this ID is set, both the geoJsonDataSource and data properties are ignored | string | - |
source-layer-name | Layer name in the source data. This property is effective when sourceId is set | string | - |
translate | Offset. Positive numbers indicate right/down | number[] | [0,0] |
pattern | Image texture. The name of the image loaded via ImageLoader. If this value is set, the color property is ineffective | string | - |
auto-highlight | Whether to automatically apply highlighting | boolean | false |
highlight-color | The highlight color | string / number[] | [255, 255, 128, 1] |
generate-id | Whether to automatically generate GeoJSON Feature IDs. If the data does not have IDs and automatic highlighting is required, this must be set to true | boolean | false |
useExpression | Whether to use an expression. When set to true, color-related properties will not be parsed | boolean | false |
EVENTS
Name | Description | Parameters |
---|---|---|
created | Map initialization completed event | - |
click | Layer click event | object — Contains screen coordinates (pixel), longitude/latitude (coordinate), selected element properties, and originalEvent |
mousemove | Mouse move event | object — Contains screen coordinates (pixel), longitude/latitude (coordinate), selected element properties, and originalEvent |
mouseleave | Mouse leave element event | MapMouseEvent |
SLOTS
Name | Description |
---|
METHODS
Name | Description | Definition |
---|---|---|
exportToGeoJson | Translate the layer's data to GeoJSON formatted text. If the layer's data source comes from a source component or a URL, output null. | ()=> object | null |