Skip to content

HeatmapLayer

Heatmap Layer: This component is only suitable for displaying data strongly correlated with density, such as business distribution or oil tank distribution. Other data, such as temperature or AQI pollution values, are not suitable for display with this layer. Mouse events are not supported.

示例

示例源码
vue
<template>
  <div style="height: 400px" class="vw-full vh-full">
    <mb-map :zoom="1.5" :pitch="20">
      <mb-tianditu-layer />
      <mb-heatmap-layer
        :data="airpotDataSource"
        :color="color"
        :radius="radius"
      />
    </mb-map>
  </div>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue'

const airpotDataSource = ref([])
const color = [
  0,
  'rgba(33,102,172,0)',
  0.2,
  'rgb(103,169,207)',
  0.4,
  'rgb(209,229,240)',
  0.6,
  'rgb(253,219,199)',
  0.8,
  'rgb(239,138,98)',
  1,
  'rgb(178,24,43)',
]
const radius = [0, 5, 1, 10, 14, 80]

onMounted(() => {
  fetch(`${__RESOURCE_URL__}json/ne_10m_airports.geojson`)
    .then((res) => res.json())
    .then((data) => {
      airpotDataSource.value = data.features.map((feature) => {
        return {
          coordinates: feature.geometry.coordinates.slice(),
          properties: feature.properties,
        }
      })
    })
})
</script>

API

PROPS

NameDescriptionTypeDefault
idThe ID of the layerstring-
radiusThe "influence radius" of each heatmap point, in pixels. Higher values result in a smoother appearance. If an array is provided, the radius will be associated with the zoom level. For example: [1, 2, 14, 50] means that when the zoom level is 1/14, the radius is 2/50number / number[]30
intensityThe intensity of the heatmap. Higher intensity values increase the influence of heatmap points on the visual effect. If an array is provided, the intensity values will be associated with the zoom level. For example: [1, 3, 10, 5] means that when the zoom level is 1/10, the corresponding intensity value is 3/5number / number[]1
colorThe color values. The default setting is related to the heatmap point densityArray<string | number>[0,'rgba(0, 0, 255, 0)',0.1,'royalblue',0.3,'cyan',0.5,'lime',0.7,'yellow',1,'red']
dataThe 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/polygonVectorLayerData-
geo-json-data-sourceGeoJSON 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 ignoredstring / GeoJSONSource-
opacityOpacitynumber1
maxzoomMaximum zoom levelnumber22
minzoomMinimum zoom levelnumber0
pickableWhether the layer responds to pick events. If false, the component will not emit mouse-related eventsbooleantrue
showWhether to show the layerbooleantrue
source-idID of the layer's source. If this ID is set, both the geoJsonDataSource and data properties are ignoredstring-
source-layer-nameLayer name in the source data. This property is effective when sourceId is setstring-
weightDefines the weight of each heatmap point's contribution to the heatmap. A value of 10 means that a heatmap point is redrawn 10 times. If an array is provided, it indicates a linear interpolation based on the target property value. For example, ["mag", 0, 0, 6, 1] means that the mag property of each heatmap point is used; when its value is 0, the weight is 0; when its value is 6 or greater than 6, the weight is 1number / Array<string | number>1

EVENTS

NameDescriptionParameters
createdMap initialization completed event-
clickLayer click eventobject — Contains screen coordinates (pixel), longitude/latitude (coordinate), selected element properties, and originalEvent
mousemoveMouse move eventobject — Contains screen coordinates (pixel), longitude/latitude (coordinate), selected element properties, and originalEvent
mouseleaveMouse leave element eventMapMouseEvent

SLOTS

NameDescription

METHODS

NameDescriptionDefinition
exportToGeoJsonTranslate 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