【OpenLayers笔记】绘制描边线
let layer = new VectorLayer(); //新建一个绘线层 let feature = new Feature({ geometry: new LineString([ fromLonLat([114, 24]), //线的点坐标 fromLonLat([114.01, 24.01]), //线的点坐标 fromLonLat([114.02, 24]), //线的点坐标 fromLonLat([114.02, 24.02]), //线的点坐标 ]), }); const textFill = new Fill({ color: "#FFF",//线文本颜色 }); const borderStroke = new Stroke({ color: "#FFF", width: 5, lineJoin: "round", }); const lineStroke = new Stroke({ color: "#FF0000", width: 2, lineJoin: "round", }); feature.setStyle([ new Style({ stroke: borderStroke, text: new Text({ fill: textFill, text:'线添加文本' }), }), new Style({ stroke: lineStroke }), ]); layer.setSource( new VectorSource({ features: [feature], }) ); map.addLayer(layer); //把线的图层添加到地图中
效果: