在开放层中绘制线条 3
drawing lines in open layers 3
我知道已经有很多这样的帖子了,但我已经尝试了很多,但它们似乎并没有解决我的问题。
我正在尝试使用线串在地图上画一条线,但无论我做什么,它都不会画线。这是我的代码:
var coords = [[78.65, -32.65], [15.65, -98.65]];
var lineStyle = new ol.style.Style({
stroke: new ol.style.Stroke(({
width: 10
}))
});
var layerLines = new ol.layer.Vector({
style: lineStyle,
source: new ol.source.Vector({
features: [new ol.Feature({
geometry: new ol.geom.LineString(coords, 'EPSG:4326', 'EPSG:3857'),
name: 'Line'
})]
}),
});
var map = new ol.Map({
layers: [
mainLayer,
vectorLayer,
layerLines
],
projection: "EPSG:3857",
target: 'map',
view: view
});
如果我在没有转换的情况下创建线串,那么它会在 0,0 处显示一个点,但我不认为它无法读取我的坐标,因为如果我将其留空,则不会出现任何点,所以它不能使用默认值。
我对 javascript 和 OL 很陌生,所以我当前的示例项目是创建一个测量应用程序,人们可以在其中测量两点并在两点之间画一条线。回答时请注意这一点。
注意一些变化:
var coords = [[-65.65, 10.10], [13, 18]];
var lineString = new ol.geom.LineString(coords);
// transform to EPSG:3857
lineString.transform('EPSG:4326', 'EPSG:3857');
// create the feature
var feature = new ol.Feature({
geometry: lineString,
name: 'Line'
});
http://jsfiddle.net/jonataswalker/7cf5egm2/
我改了coords
,原来的有点奇怪|错了
我知道已经有很多这样的帖子了,但我已经尝试了很多,但它们似乎并没有解决我的问题。
我正在尝试使用线串在地图上画一条线,但无论我做什么,它都不会画线。这是我的代码:
var coords = [[78.65, -32.65], [15.65, -98.65]];
var lineStyle = new ol.style.Style({
stroke: new ol.style.Stroke(({
width: 10
}))
});
var layerLines = new ol.layer.Vector({
style: lineStyle,
source: new ol.source.Vector({
features: [new ol.Feature({
geometry: new ol.geom.LineString(coords, 'EPSG:4326', 'EPSG:3857'),
name: 'Line'
})]
}),
});
var map = new ol.Map({
layers: [
mainLayer,
vectorLayer,
layerLines
],
projection: "EPSG:3857",
target: 'map',
view: view
});
如果我在没有转换的情况下创建线串,那么它会在 0,0 处显示一个点,但我不认为它无法读取我的坐标,因为如果我将其留空,则不会出现任何点,所以它不能使用默认值。
我对 javascript 和 OL 很陌生,所以我当前的示例项目是创建一个测量应用程序,人们可以在其中测量两点并在两点之间画一条线。回答时请注意这一点。
注意一些变化:
var coords = [[-65.65, 10.10], [13, 18]];
var lineString = new ol.geom.LineString(coords);
// transform to EPSG:3857
lineString.transform('EPSG:4326', 'EPSG:3857');
// create the feature
var feature = new ol.Feature({
geometry: lineString,
name: 'Line'
});
http://jsfiddle.net/jonataswalker/7cf5egm2/
我改了coords
,原来的有点奇怪|错了