[英]Open Layers 3 - How to prevent LineString from drawing from starting coordinate again?
[英]drawing lines in open layers 3
我知道已經有很多這樣的帖子,但我已經嘗試了很多,但它們似乎並沒有解決我的問題。
我正在嘗試使用 linestring 在地圖上繪制一條線,但無論我做什么,它都不會繪制一條線。 這是我的代碼:
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
,原來有點奇怪|錯了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.