首页 > 解决方案 > 热图不适用于 FeatureLayer (ArcGIS JS API 4.8)

问题描述

我尽了最大努力,但没有成功使用最新的 ArcGIS JavaScript API 4.8 在 FeatureLayer 上显示热图。我的代码位于此处。我使用HeatMapRenderer将地图上的点渲染为热图。但不知何故,它根本不起作用。我想我错过了一些很容易解决的东西。

放置我认为应该修复的 JavaScript 代码:

const renderer = {
    type: "heatmap",
    colorStops: [{
        color: "rgba(63, 40, 102, 0)",
        ratio: 0
      },
      {
        color: "#472b77",
        ratio: 0.083
      },
      {
        color: "#4e2d87",
        ratio: 0.166
      },
      {
        color: "#563098",
        ratio: 0.249
      },
      {
        color: "#5d32a8",
        ratio: 0.332
      },
      {
        color: "#6735be",
        ratio: 0.415
      },
      {
        color: "#7139d4",
        ratio: 0.498
      },
      {
        color: "#7b3ce9",
        ratio: 0.581
      },
      {
        color: "#853fff",
        ratio: 0.664
      },
      {
        color: "#a46fbf",
        ratio: 0.747
      },
      {
        color: "#c29f80",
        ratio: 0.830
      },
      {
        color: "#e0cf40",
        ratio: 0.913
      },
      {
        color: "#ffff00",
        ratio: 1
      }
    ],
    maxPixelIntensity: 10,
    minPixelIntensity: 0,
    blurRadius: 8.764705882352942
  };
  var point = {
    type: "point",
    longitude: -81.4230821,
    latitude: 28.3103877,
  };
  var markerSymbol = {
    type: "simple-marker",
    color: [226, 119, 40]
  };
  var pointGraphic = new Graphic({
    geometry: point,
    symbol: markerSymbol
  });
  let graphics = getGraphics(Graphic);
  graphics.push(pointGraphic);

  const layer = new FeatureLayer({
    title: "Magnitude 2.5+ earthquakes from the last week",
    copyright: "USGS Earthquakes",
    source: graphics,
    popupTemplate: template,
    attributionVisible: true,
    fields: [{
        name: "OBJECTID",
        alias: "OBJECTID",
        type: "oid"
      },
      {
        name: "id",
        alias: "id",
        type: "integer"
      }, {
        name: "agencyId",
        alias: "agencyId",
        type: "integer"
      },
      {
        name: "heat",
        alias: "heat",
        type: "number"
      }, {
        name: "latitude",
        alias: "latitude",
        type: "number"
      }, {
        name: "longitude",
        alias: "longitude",
        type: "number"
      }
    ],
    objectIdField: "OBJECTID",
    outFields: ["OBJECTID", "heat", "id", "longitude", "latitude", "agencyId"],
    geometryType: "point",
    opacity: 1,
    spatialReference: {
      wkid: 4326
    },
    renderer: renderer
  });
  const map = new Map({
    basemap: "gray",
    layers: [layer]
  });

标签: javascriptheatmaparcgisesriarcgis-js-api

解决方案


我向 Esri GeoNet 社区提出了这个问题,他们很快就回答了。你可以在这里找到详细的答案。以下是答案:

热图需要 WebGL,它需要托管的要素图层服务或 10.6.1+。带有图形集合的热图目前不起作用。

他们还回答了 StackExchange 地理信息系统社区。你可以在这里找到答案。答案是:

HeatmapRenderer 仅适用于启用 WebGL 的 FeatureLayer,在 4.8 版中,WebGL 支持的限制之一被列为:不支持从特征集合或客户端图形创建的图层。https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#webgl-rendering 这个限制有望在下一个版本(4.9 版)中消失。


推荐阅读