Document Maps JavaScript API Reference Manual Industry Standard Layer MapboxVectorTileLayer

MapboxVectorTileLayer

AMap.MapboxVectorTileLayer 

Description

Is it a plugin

To meet development needs such as data visualization based on vector tiles and vector tile boundary display, a simple vector tile layer is provided through the AMap.MapboxVectorTileLayer plugin. This layer can use standard MVT tile services as the data source.

Yes

Prompt

It can be used with the vector tile service released by the GeoHub data center. Note: When using the AMap data platform to publish services, since the service URL address is in plain text, it is recommended to set up a service proxy forwarding to prevent the service ID and Key from being transmitted in plain text and causing data leakage.

Construct an MVT layer object and set layer properties through MapboxVTLayerOptions

new AMap.MapboxVectorTileLayer(opts: MapboxVTLayerOptions)

Parameter

opts(MapboxVTLayerOptions): Simple vector tile layer parameters

Attribute

Type

Description

zIndex

Number

Order value of layer stacking, the larger the number, the higher the layer level, 1 means the bottom layer. Default: 80

opacity

Number

Layer opacity, range [0 ~ 1], 1 means completely opaque, 0 means completely transparent, default: 1

url

String

Link address of MVT data

visible

Boolean

Whether to display, default: true

zooms

[Number, Number]

Supported zoom level range, default range: [2,22]

dataZooms

[Number, Number]

Tile data level range, if exceeded, the maximum/minimum level data will be used, default: [2,18]

styles

MapboxVTLayerStyle

Style settings

polygon

PolygonStyle?

Style of polygon type

sourceLayer

String

Which layer to use in the data, default: default layer

color

(String | Function)?

Fill color

borderWidth

(Number | Function)?

Stroke width

dash

(Array<Number>Function)?

Stroke line dash configuration, for example: [10,5,8,5]

borderColor

(String | Function)?

Stroke color

injection

Array<Any>?

For function-type values in other properties, if external variables need to be accessed, they should be passed in the form of an array to facilitate access to external variables within the function. See the example below.

visible

(Boolean | Function)?

Display or Not

line

LineStyle?

Line Type Data Style

sourceLayer

String

Which layer in the data to use, default: default layer

color

(String | Function)?

Line Fill Color

lineWidth

(Number | Function)?

Width

dash

(String | Function)?

Dashed line configuration, for example: [10,5,8,5]

injection

Array<Any>?

For function-type values in other attribute values, if external variables need to be accessed, use an array to pass them in, making it easy to access external variables inside the function. See the example below.

visible

(Boolean | Function)?

Whether to display

point

PointStyle?

Style of point-type data

sourceLayer

String

Which layer in the data to use, default: default layer

radius

(String | Function)?

The radius of the dot, in pixels

color

(Number | Function)?

The fill color of the circle

borderWidth

(String | Function)?

The width of the outline

borderColor

(String | Function)?

The color of the outline

injection

Array<Any>?

For function-form values in other property values, if it is necessary to obtain external variables, they should be passed in the form of an array to facilitate access to external variables within the function. Please refer to the example below.

visible

(Boolean | Function)?

Whether to display

polyhedron

PolyhedronStyle?

Polyhedron style

sourceLayer

String

Which layer in the data to use, default: default layer

topColor

(String | Function)?

Top color

sideColor

(String | Function)?

Side color

texture

(String | Function)?

Side texture, which has a higher priority than side color

injection

Array<Any>?

For values in the form of functions in other attributes, if you need to obtain external variables, use an array to pass them in for easy access to external variables within the function. Please see the example below.

visible

(Boolean | Function)?

Whether to display

Demo

var globalVar = ["这是", "一个", "外部", "变量"];
AMap.plugin(["AMap.MapboxVectorTileLayer"], function () {
  var mvtl = new AMap.MapboxVectorTileLayer({
    zIndex: 150,
    opacity: 1,
    // The URL can use the services of the data service platform or the MVT data service you published
    url: "https://restapi.amap.com/rest/lbs/geohub/tiles/mvt?z=[z]&x=[x]&y=[y]&size=512&key=The key value you applied for&id=Data service ID",
    dataZooms: [2, 18],
    zooms: [2, 20],
    tileSize: 256,
    styles: {
      point: {
        sourceLayer: "default",
        visible: function (f, inject) {
          // Here, the inject parameter is an array, and its value is the array value of the injection field: [visis].
          return inject[0].indexOf("这是") > -1;
        },
        injection: [globalVar],
        radius: function (props) {
          return Math.random() * 20 + 5;
        },
        color: "red",
        borderWidth:
          20 ||
          function (props) {
            return Math.random() * 5 + 2;
          },
        borderColor: "rgba(255,255,255,1)",
      },
      polygon: {
        sourceLayer: "default",
        color: function (props) {
          return "rgba(0,0,0,1)";
        },
        dash: [10, 0, 10, 0],
        borderColor: "rgba(30,112,255,1)",
        borderWidth: 5,
      },
      line: {
        sourceLayer: "default",
        color: "rgba(20,140,40,1)",
        lineWidth: 5,
        dash: [10, 0, 10, 0],
      },
      polyhedron: {
        sourceLayer: "default",
        topColor: "rgba(230,230,230,0.9)",
        sideColor: "rgba(240,240,240,0.9)",
      },
    },
  });
  map.add(mvtl);
});

Method

setStyles(styles)

Set style information

Parameterstyles((MapboxVTLayerStyle)Style information (refer to the style attribute configuration in the properties list above)

filterByRect(rect, type)

Retrieve features within the rectangular area

Parameter

rect(PolygonPolygon, for example:[ [lng,lat] , [lng,lat] , [lng,lat] , [lng,lat] , [lng,lat] ]

type(String = "all") The type of feature you want to acquire, default to all: all. Options: all, point, polygon, line

return value: (Array<Feature>) Range Feature

getStyles()

Get Style Information

return value: (MapboxVTLayerStyle) Style

on(type, fn, option)

Listen to mouse events at the layer level to get elements at the mouse position in the current layer

Parameter 

type (StringListening event types, currently support click, mousemove

fn (FunctionCallback function for listening, the features in the parameters are the elements obtained at the mouse position

option (ObjectPick parameters, featType: represents the type of feature to be picked, refer to the type in the filterByRect() function; buffer: 5, represents a square area with a range of 5 centered on the mouse as the mouse pick range. The larger the value, the larger the pick range, it is recommended to use the default value.

hide()

Hide Layer

show()

Set Layer Visibility

getOptions()

Get Layer Parameter Information

return value: (Object) Layer Parameter Information

getzIndex()

Get Layer Level

return value: (NumberzIndex Layer Level

setzIndex(zIndex)

Set layer level, the higher the number, the higher the layer level

ParameterzIndex (NumberLayer level value

getOpacity()

Get layer transparency

return value: (Number) opacity layer transparency

setOpacity(opacity)

Set layer transparency, range [0 ~ 1], where 1 means completely opaque and 0 means completely transparent

Parameteropacity(NumberLayer transparency

getZooms()

Get the display level range of this layer

return value: ([Number, Number]Display level range of this layer

setZooms(zooms)

Set the display level range for this layer

Parameterzooms([Number, Number]Zoom range displayable for this layer