使用OpenLayers在两点之间画线 [英] Draw line between two points using OpenLayers

查看:832
本文介绍了使用OpenLayers在两点之间画线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个点,其中lolLat分别为0,10和30,0

I have two points having lolLat as 0,10 and 30,0

现在要在此处绘制标记,我在生成标记的同时使用了此变换

Now to draw a marker at this point i use this transform while generating marker for it

lonLat.transform(
                 new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
                 map.getProjectionObject() // to Spherical Mercator Projection
             )

我如何在它们之间画线,有什么办法可以在openlayers中完成呢?我曾尝试在向量层中使用线串来做到这一点,但它似乎对我不起作用.

How can i draw line between them is there any way to do that in openlayers,i have tried doing it with linestring in vector layer but it doesn't seems to be working for me.

推荐答案

例如:

map = new OpenLayers.Map();

var start_point = new OpenLayers.Geometry.Point(0,10);
var end_point = new OpenLayers.Geometry.Point(30,0);

var vector = new OpenLayers.Layer.Vector();
vector.addFeatures([new OpenLayers.Feature.Vector(new OpenLayers.Geometry.LineString([start_point, end_point]))]);
map.addLayers([vector]);

实时演示

这篇关于使用OpenLayers在两点之间画线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆