Javascript 每x秒刷新一次数据后,无法动态更新图标图像
我目前每x秒动态更新一次标记,这里是数据更新和放置标记,但这里的问题是,当数据根据图标更新时,我放置的图像没有更新Javascript 每x秒刷新一次数据后,无法动态更新图标图像,javascript,angular,google-maps,google-maps-api-3,Javascript,Angular,Google Maps,Google Maps Api 3,我目前每x秒动态更新一次标记,这里是数据更新和放置标记,但这里的问题是,当数据根据图标更新时,我放置的图像没有更新 0== red 1== green 2== orange here this.markerIcon = this.mapData[i].OrderState; this is my icon color status 下面是我获取动态数据的代码 if(this.mapData!=null && this.mapData.length>0){
0== red
1== green
2== orange
here this.markerIcon = this.mapData[i].OrderState; this is my icon color status
下面是我获取动态数据的代码
if(this.mapData!=null && this.mapData.length>0){
for (var i = 0; i < this.mapData.length;i++){
this.latlng = {lat: parseFloat(this.mapData[i].latitude), lng: parseFloat(this.mapData[i].longitude)};
this.markerName = this.mapData[i].Name;
this.markerIcon = this.mapData[i].OrderState;
if (this.markerStore.hasOwnProperty(this.mapData[i].DriverId)) {
if (this.markerIcon === "0") {
this.iconDisplay = this.red;
} else if (this.markerIcon === "1") {
this.iconDisplay = this.green;
} else if ( this.markerIcon === "2") {
this.iconDisplay = this.orange;
} else if (this.markerIcon === "3") {
this.iconDisplay = this.building;
}
this.markerStore[this.mapData[i].DriverId].setPosition(this.latlng);
} else {
if (this.markerIcon === "0") {
this.iconDisplay = this.red;
} else if (this.markerIcon === "1") {
this.iconDisplay = this.green;
} else if ( this.markerIcon === "2") {
this.iconDisplay = this.orange;
} else if (this.markerIcon === "3") {
this.iconDisplay = this.building;
}
var marker = new google.maps.Marker({
position: this.latlng,
map:this.mapObject,
icon:this.iconDisplay
});
this.markerStore[this.mapData[i].DriverId] = marker;
}
}
}
}
});
这里,根据标记图像中的顺序状态值,每10秒更新一次数据0==红色、1==绿色和2==橙色,如果标记存在而不是替换数组中的元素,则0也可能变为1或2,请移除旧标记并添加新标记
if (this.mapData[i].DriverId in this.markerStore) {
this.markerStore[this.mapData[i].DriverId].setMap(null);
}
// create here the new one as you did before
你能提供一个这样我们就可以重现这个问题吗?我正在以标记的形式显示动态数据,每10秒我从服务器获取实时数据,这里发生的事情是我能够显示数据和自定义标记,这里也可以显示基于后端it技术值的自定义标记现在发生的事情是即使后端的值是正确的,但图标图像没有更新,在我在浏览器中按“重新加载”后,它正在更新image@Madpop使用控制台日志或开发人员工具查看if-else中的变量值logic@Madpop检查此演示此问题缺少更多信息(一个最小、完整且可验证的示例)。如果没有这一点,就很难对您提出的问题进行故障排除。失败的原因有:您正在更新this.iconDisplay,但是,在上下文中这是什么?可能是您一直在修改同一个iconDisplay。也可能是您没有在每次收到更新时都执行代码,也可能是谷歌地图在您的更改后没有得到刷新。请提供一个工作示例
if (this.mapData[i].DriverId in this.markerStore) {
this.markerStore[this.mapData[i].DriverId].setMap(null);
}
// create here the new one as you did before