javascript - 使用循环对 Fusion 层进行排序并更新每个结果
问题描述
一般来说,我对 javascript 和 web 开发很陌生。我一直在试验融合表和谷歌 API,并难住了自己。
我正在寻找遍历 Javascript 对象并突出显示我的融合层中名称与 javascript 对象中的名称匹配的任何多边形。下面的代码:
function fillcolour(match){ // ---- match is an array within the javascript object
var limit = 0; // --- currently limiting the responses to 5. There are 126 in each response array and I know within the first 5 there are 3 matches.
var options = {
styles : []
};
var styles = [];
for (x in match) { //---- getting each name in match. from alerts and console log I know this returns 5 results, three of which should satisfy the requirements below.
if(limit < 5){
PolygonLayer.setOptions({
query: {
select: "shape",
from: mapTable,
where: "'name' = '" + x + "'"
}
});
options.styles.push({
polygonOptions: {
fillColor: "#FFF000",
}
});
PolygonLayer.setOptions(options);
limit++;
}
}
};
所以我看到的当前结果是只有一个多边形变成黄色(数组中的最后一个)。
我想看到的是循环中检查的所有可行多边形都变成黄色。我很确定答案在查询语法中,但我已经搜索了半天,但什么也找不到。
我想要的可能吗?
谢谢阅读!
解决方案
您的函数可能看起来像这样
function fillcolour(match){
PolygonLayer.setOptions({
styles: [{
where: "'name' in ('" + match.join("','") + "')"
polygonOptions: {
fillColor: "#FFF000"
}
}]
})
}
推荐阅读
- c - C循环双向链表,静态头初始化下一个/上一个指向静态头地址的指针
- python - 因式分解,请帮我看看d出了什么问题,我是刚学习的新手
- javascript - 如何使用 NodeJS 串行端口向 Arduino 串行写入多个数据
- jquery - 如何使用html函数缩短重复代码并在jquery中返回标签
- csv - 上传的 CSV 文件将日期列显示为字符串,如何转换为日期以供 AutoAI 使用?
- node.js - 在 Node js 的 MIDI 事件侦听器中发送 OSC 或 MQTT 消息时代码非常慢
- r - 具有调查权重的组别比例
- reactjs - 禁止(403)在“构建 React 应用程序”中发布请求,但可以在“http://localhost:3000/”和 PostMan 上运行的 React 应用程序正常工作
- flutter - 如何在颤动中创建这样的列表视图构建器项目?
- c - 从 txt 文件中读取列