简体   繁体   English

使用JavaScript在OpenLayers中绘制一条带有一条线的路径

[英]Drawing a path with a line in OpenLayers using JavaScript

I have seen the examples presented here of how to draw a line but the examples only show how to do it with the mouse, by clicking. 我已经看到了这里提供的如何绘制线条的示例,但示例仅显示了如何使用鼠标进行操作,方法是单击。

What I want to do is draw the line manually using JavaScript given a list of Longitude and Latitude coordinates . 我想要做的是在给定经度和纬度坐标列表的情况下使用JavaScript手动绘制线条

The reason I cannot work on the source provided in the link above is because they are only calling activate on the feature, and then let the user point and click on the map. 我无法处理上面链接中提供的源的原因是因为它们只在该功能上调用activate ,然后让用户指向并单击地图。

Has anyone ever drew a path on an OpenLayers map programatically? 有没有人以编程方式在OpenLayers地图上绘制路径?

What I want to do is exactly this: http://openspace.ordnancesurvey.co.uk/openspace/example4.html , but without using OpenSpace. 我想要做的就是: http//openspace.ordnancesurvey.co.uk/openspace/example4.html ,但不使用OpenSpace。

You would need to make use of the LineString object 您需要使用LineString对象

Here is an example: 这是一个例子:

var lineLayer = new OpenLayers.Layer.Vector("Line Layer"); 

map.addLayer(lineLayer);                    
map.addControl(new OpenLayers.Control.DrawFeature(lineLayer, OpenLayers.Handler.Path));                                     
var points = new Array(
   new OpenLayers.Geometry.Point(lon1, lat1),
   new OpenLayers.Geometry.Point(lon2, lat2)
);

var line = new OpenLayers.Geometry.LineString(points);

var style = { 
  strokeColor: '#0000ff', 
  strokeOpacity: 0.5,
  strokeWidth: 5
};

var lineFeature = new OpenLayers.Feature.Vector(line, null, style);
lineLayer.addFeatures([lineFeature]);

Assuming map is your map object and lon and lat are float values. 假设map是你的map对象而lonlat是float值。

this page is a classic example of animation via javascript using openlayers. 此页面是使用openlayers通过javascript动画的经典示例

it uses a filter strategy to define what to show at what moment in time. 它使用过滤策略来定义在什么时刻显示的内容。

full javascript available. 完整的JavaScript可用。

I've never done it myself before, but I know OpenSteetMap does it. 我以前从未做过,但我知道OpenSteetMap会这样做。 For example: 例如:

http://www.openstreetmap.org/?way=23649627 http://www.openstreetmap.org/?way=23649627

No idea how difficult it would be to work through their code. 不知道通过他们的代码是多么困难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM