博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
openlayers3线段添加闪烁_在OpenLayers 3中动态地添加和删除轨道段
阅读量:5149 次
发布时间:2019-06-13

本文共 1466 字,大约阅读时间需要 4 分钟。

I want to display a track in real-time with OpenLayers 3 which disolves at the end, just like a snails trail.

Only appending new coordinates to a LineString is easy. See this example. But removing coordinates from the end of the line does not seem to be supported by the API.

How should I go about that? Is extending the LineString class the only option? Or should I use a separate feature for each line segment?

Update:

I used this code with ol-debug.js. But get/setFlatCoordinates is not exported in the compiled version.

var flatCoordinates = geometry.getFlatCoordinates(); // not exported

if (flatCoordinates && flatCoordinates.length > 100) {

// remove first coordinate elements from array

flatCoordinates.splice(0, geometry.getStride());

// call push with coordinate elements as arguments

Array.prototype.push.apply(flatCoordinates, coordinate);

// update coordinates calling change()

geometry.setFlatCoordinates(geometry.getLayout(), flatCoordinates);

}

else {

geometry.appendCoordinate(coordinate);

}

解决方案

The appendCoordinate method is a shortcut for the fairly common use case of adding a coordinate to the end of a LineString. To modify geometries with more control, set your desired coordinates with setCoordinates.

var maxCoords = 100;

var coords = lineString.getCoordinates(); // get coordinate array

coords.unshift(newCoord); // add to beginning of array

if (coords.length > maxCoords) {

coords.length = maxCoords;

}

lineString.setCoordinates(coords);

转载地址:http://nxdnv.baihongyu.com/

你可能感兴趣的文章
第二周 数据获取与表示 第二节 数据表示 Data representation
查看>>
Shader Overview
查看>>
[python]python学习笔记(五)
查看>>
Reveal 配置与使用
查看>>
Java中反射的学习与理解(一)
查看>>
多个jquery.datatable共存,checkbox全选异常问题的解决
查看>>
error LNK1112:模块计算机类型"X64" 与目标计算机类型"X86" 冲突
查看>>
数据库的操作
查看>>
JSt中对象的prototype属性
查看>>
把16进制值转换成颜色&颜色16进制值表 .
查看>>
nginx配置socket服务
查看>>
JS验证文本中是否有链接
查看>>
课后作业-阅读任务-阅读提问-4
查看>>
软件工程——团队答辩
查看>>
[再寄小读者之数学篇](2014-06-19 三维插值公式)
查看>>
什么是大学生、硕士生和博士生
查看>>
batch
查看>>
CodeForces 237C
查看>>
POJ 2485(Kruskal算法)
查看>>
《20171122-构建之法:现代软件工程-阅读笔记》
查看>>