I try to accomplish that I will be able to change the color of marker icons to be visible in the map.
(我试图做到,我将能够更改标记图标的颜色以使其在地图上可见。)
They are in the map in different colors.(它们在地图上以不同的颜色显示。)
Those colors are correspondenting to the json cat_id key's.(这些颜色与json cat_id键的颜色相对应。)
1: "http://dev.openlayers.org/img/marker.png",
2: "http://dev.openlayers.org/img/marker-blue.png",
3: "http://dev.openlayers.org/img/marker-gold.png",
4: "http://dev.openlayers.org/img/marker-green.png",
Each marker icon that is in the map is getting it's position, color and other valuable data from the json objects in the data id in the script tag.
(地图中的每个标记图标都将从script标记的数据ID中的json对象获取其位置,颜色和其他有价值的数据。)
I didn't code the part of that work's close with the openlayer libary's.(我没有编写与openlayer libary紧密相关的部分代码。)
I wrote the following part of the total of the script:(我在脚本总数中写了以下部分:)
var json = document.getElementById('data').innerHTML;
json = JSON.parse(json); // converts text into JSON
// search criteria (could be changed)
var $search_postal = "8912JB";
var $search_number = "10";
var $change_cat = 1;
function changeColor() {
for (var key in json) {
if (json.hasOwnProperty(key)) {
if (json[key].postal == $search_postal) {
if (json[key].number == $search_number) {
alert("Gonna change cat_id " + json[key].cat_id + " of the number search string " + $search_number + " of the postal search string " + $search_postal + " to cat_id " + $change_cat);
json[key].cat_id = "1";
alert('Changed!');
const posts = json; // the constant that is used to display the icons
var myJSON = json;
document.getElementById('demo').innerHTML = JSON.stringify(myJSON, undefined, 2); // changes of the json data to see on screen
}
}
}
}
}
const posts = json; //the constant that is used to display the icons
var myJSON = JSON.stringify(json);
document.getElementById('demo').innerHTML = myJSON;
This script will change the cat_id of the given search input.
(该脚本将更改给定搜索输入的cat_id。)
In the example it does a search for postal 8912JB with number 1. Once it has made the loop to find it's position it will change the cat_id value of 3 to 1. In other words the json data has been changed.(在此示例中,它搜索编号为1的邮政8912JB。一旦找到要定位的位置,它将cat_id值3更改为1。换句话说,json数据已更改。)
Since it is stored in the const posts I replace this cons with the changed data.(由于它存储在const帖子中,因此我用更改后的数据替换了这个缺点。)
My problem is that I'm unable to refresh the marker icon(s) in the map with the new json data that is changed (cat_id: 1 of postal 8912JB number 10).(我的问题是我无法使用更改后的新json数据(cat_id:邮政8912JB号10的1)来刷新地图中的标记图标。)
This has to do with less knowledge about openlayers and Javascript.(这与对openlayers和Javascript的了解较少有关。)
I'm struggling already 2 weeks with this.(我已经为此挣扎了两个星期。)
Can anybody help me to accomplish this?(有人可以帮我实现这一目标吗?)
If it changes from color is the only thing that is required.(如果颜色发生变化,则唯一需要的就是它。)
I would only need to give the changes to the variables $search_postal, $search_number and $change_cat.(我只需要对变量$ search_postal,$ search_number和$ change_cat进行更改即可。)
Here is the page for debug: https://jsfiddle.net/j4z1vpht/4/
(这是调试页面: https : //jsfiddle.net/j4z1vpht/4/)
Thanks for any help,
(谢谢你的帮助,)
grid
(格线)
ask by grid translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…