javascript - HERE 映射(集群)集成以响应应用程序
问题描述
我能够将 Here maps 聚类覆盖与虚拟数据集成,但无法操纵从 api 获取的数据以正确使用它。
在过去的两天里,我一直在搞乱这么多不同的 JS 数组和对象方法,以至于我忘记了我尝试过和没有尝试过的东西。
我来自 api 的 JSON 响应是:
[0 … 99]
0:
coordinates: Array(2)
0: 24.77234
1: 59.43862
length: 2
__proto__: Array(0)
type: "Point"
__proto__: Object
1: {type: "Point", coordinates: Array(2)}
和此功能的代码:
const getTlnBusData = async () => {
const test = await gpsData.flatMap((vehicle) => [vehicle.geometry]);
console.log('test', test);
const testValues = Object.values(test);
console.log('testValues', testValues);
// const coords = [el.geometry.coordinates];
// console.log('batman', coords);
const dataPoints = [];
// const dataPoints = [test];
// dataPoints.push(new H.clustering.DataPoint([test.coordinates]);
dataPoints.push(new H.clustering.DataPoint(50.04, 1.01));
dataPoints.push(new H.clustering.DataPoint(51.45, 1.01));
dataPoints.push(new H.clustering.DataPoint(51.01, 2.01));
/**
* Assuming that 'dataPoints' and 'map'
* is initialized and available, create a data provider:
*/
const clusteredDataProvider = new H.clustering.Provider(dataPoints);
// Create a layer that includes the data provider and its data points:
const layer = new H.map.layer.ObjectLayer(clusteredDataProvider);
// Add the layer to the map:
hMap.addLayer(layer);
};
getTlnBusData();
我尝试了 forEach、loop、map/flatMap 的变体,但我似乎无法用我的任何解决方案替换虚拟数据。
谁能指出我正确的方向?
蒂亚!
解决方案
我发现的解决方案:
const getTlnBusData = async () => {
const vehicles = await gpsData.flatMap((vehicle) => [vehicle.geometry]);
const dataPoints = vehicles.map(
(item, idx) =>
new H.clustering.DataPoint(
item.coordinates[1],
item.coordinates[0],
null,
item
)
);
console.log('bounty', dataPoints);
/**
* Assuming that 'dataPoints' and 'map'
* is initialized and available, create a data provider:
*/
const clusteredDataProvider = new H.clustering.Provider(dataPoints);
// Create a layer that includes the data provider and its data points:
const layer = new H.map.layer.ObjectLayer(clusteredDataProvider);
// Add the layer to the map:
hMap.addLayer(layer);
};
getTlnBusData();
推荐阅读
- php - Symfony 3 DTOOneCommand changing null value to 0 after handleRequest
- html - 如何在 Kentico CMS 中编辑模式中的文本
- python - twisted.python.failure.Failure 的“值”属性是否有回溯?如果没有,如何建立回溯?
- sqr - SQR - Last-Page() 在打印 1000000 页时打印 ****
- shell - 我可以在命令行上做一个否定的通配符吗?
- android - WifiManager.disconnect() 在 Android Q 中已弃用
- python - 将嵌套的类字典 txt 文件读入 Pandas 数据帧
- php - 为什么我的请求不能与 orWhereRaw() 一起使用?
- php - 我将如何检查电子邮件是否已在使用中?
- api - 使用 POST Web 请求发送 PDF base64