Javascript 此处API群集错误:";“未定义addLayer”;

Javascript 此处API群集错误:";“未定义addLayer”;,javascript,here-api,Javascript,Here Api,我试图在我的应用程序中使用碎屑,但我得到一个错误addLayer未定义” 我不知道如何解决这个问题 我只是从这里复制并粘贴这个示例函数API示例API集群 我把lat和lng传递给函数,但是addLayer没有定义 function startClustering(map, data) { // First we need to create an array of DataPoint objects, // for the ClusterProvider var dataPoint

我试图在我的应用程序中使用碎屑,但我得到一个错误addLayer未定义”

我不知道如何解决这个问题

我只是从这里复制并粘贴这个示例函数API示例API集群

我把lat和lng传递给函数,但是addLayer没有定义

function startClustering(map, data) {
  // First we need to create an array of DataPoint objects,
  // for the ClusterProvider
  var dataPoints = data.map(function(item) {
    return new H.clustering.DataPoint(item.latitude, item.longitude);
  });

  // Create a clustering provider with custom options for clusterizing the input
  var clusteredDataProvider = new H.clustering.Provider(dataPoints, {
    clusteringOptions: {
      // Maximum radius of the neighbourhood
      eps: 32,
      // minimum weight of points required to form a cluster
      minWeight: 2
    }
  });

  // Create a layer tha will consume objects from our clustering provider
  var clusteringLayer = new H.map.layer.ObjectLayer(clusteredDataProvider);

  // To make objects from clustering provder visible,
  // we need to add our layer to the map

  map.addLayer(clusteringLayer);

}
我有map对象,但addLayer未定义

function startClustering(map, data) {
  // First we need to create an array of DataPoint objects,
  // for the ClusterProvider
  var dataPoints = data.map(function(item) {
    return new H.clustering.DataPoint(item.latitude, item.longitude);
  });

  // Create a clustering provider with custom options for clusterizing the input
  var clusteredDataProvider = new H.clustering.Provider(dataPoints, {
    clusteringOptions: {
      // Maximum radius of the neighbourhood
      eps: 32,
      // minimum weight of points required to form a cluster
      minWeight: 2
    }
  });

  // Create a layer tha will consume objects from our clustering provider
  var clusteringLayer = new H.map.layer.ObjectLayer(clusteredDataProvider);

  // To make objects from clustering provder visible,
  // we need to add our layer to the map

  map.addLayer(clusteringLayer);

}
我把lat和lng传递给函数,但是addLayer没有定义

function startClustering(map, data) {
  // First we need to create an array of DataPoint objects,
  // for the ClusterProvider
  var dataPoints = data.map(function(item) {
    return new H.clustering.DataPoint(item.latitude, item.longitude);
  });

  // Create a clustering provider with custom options for clusterizing the input
  var clusteredDataProvider = new H.clustering.Provider(dataPoints, {
    clusteringOptions: {
      // Maximum radius of the neighbourhood
      eps: 32,
      // minimum weight of points required to form a cluster
      minWeight: 2
    }
  });

  // Create a layer tha will consume objects from our clustering provider
  var clusteringLayer = new H.map.layer.ObjectLayer(clusteredDataProvider);

  // To make objects from clustering provder visible,
  // we need to add our layer to the map

  map.addLayer(clusteringLayer);

}
我有地图对象,半身像不存在

我正在嵌入脚本

<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-clustering.js"></script>

您第二次问这个问题时的回答是:这不包括这个问题中的一些细节。但是,考虑到您对这个问题所做的额外编辑/上下文,您似乎正在添加一个事件侦听器,其中
map
可能超出范围,或者尚未定义匿名函数中的可见性

document.querySelector(".camera-box").addEventListener("click", function() {
    if (document.getElementsByClassName("camera-marker-position")[0] === undefined) {
      map.addObject(cameraMarker);
      self.startClustering(map, coordinate);
    } else {
      map.removeAll();
    }
  });
您可以执行键入检查,以查看在单击事件发生时是否定义了map,和/或确认它是否为
H.map
。在没有看到完整列表的情况下,也可能是您没有将
map
设置为全局变量,而是在页面初始化中的其他位置声明了它,因此当t他被解雇了


您可以查看有关闭包的详细信息,您可以在声明函数时向事件提供
map
。有关更一般的信息:

您要传递的
map
参数是什么?更好的是,您能不能只包含调用此函数的代码?听起来您可能传递了错误的类型。From,它看起来像是
addLayer
需要
map
类型为
H.map
。我正在从我的函数addDomMarker(map)调用函数startClustering(map,cords),并将映射作为参数传递,这就是我的代码
函数addMarkerToCameraGroup(map,coordinate,html){//add and remove markers document.querySelector(“.camera box”).addEventListener(“单击”,函数(){if(document.getElementsByClassName(“摄影机标记位置”)[0]==未定义){//map.addObject(camerarmarker);self.startClustering(map,坐标);}else{map.removeAll();}}
您提供的代码仍然没有明确显示
map
是什么,您正在调用的方法之一(
map.addObject()
)在
H.map
的文档中列出,但是另一个(
removeAll()
)不是。请在您第一次声明
map
的位置发布代码。对不起,我有'map=new H.map(document.getElementById('map'),defaultLayers.normal.map,{center:{lat:-19.9211375,lng:-43.9490617,},zoom:6})是的,问题是作用域,将当前作用域发送到函数,但我遇到另一个错误,引用作用域,返回a(returnindexof(a)this),也没有作用域上下文