javascript - 更新传单标记
问题描述
这是关于角度 5 上的传单标记,标记值是动态的,我只需要绘制最后一个结果。请问我该怎么做?
var markers;
markers = new L.LayerGroup().addTo(myfrugalmap);
let timer = TimerObservable.create(0, 10000);
this.subscription = timer.subscribe(t => { this.MyService.Localize().subscribe( result => {
this.positions = result;
let xpo = this.positions.x;
let ypo = this.positions.y;
let mar=L.marker([xpo,ypo], {icon: greenIcon}) mar.addTo(markers) });
//markers.clearLayers();
} )
结果(没有(markers.clearLayers))我在地图上每10秒就有一个新位置,我需要放弃旧位置,只看到最后一个
解决方案
在将新创建的标记添加到图层之前,您是否尝试过清除?你的最后几行看起来像这样。
let mar=L.marker([xpo,ypo], {icon: greenIcon});
markers.clearLayers();
mar.addTo(markers);
推荐阅读
- java - -server -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler 时使用哪个编译器
- linux - Azcopy 无法使用 sas 令牌从 azure 文件存储下载文件?
- spring-boot - 如何抑制 Spring Boot 错误消息
- jquery - 如何删除
- sql - 按语句添加顺序时获取重复行
- json - 如何将在 Teradata 上运行的 SQL 查询的结果导出到外部 JSON 文件?
- msbuild - 在 MSBuild 中忽略/禁用环境变量
- json - 如何用逗号 JsonFormat 长值
- kotlin - Kotlin 编译器使用 Spring 的 TypeDescriptor 报告“没有方法 'equals(Any?): Boolean available”
- assembly - 片选位代表什么以及它们如何影响整体内存地址?