Draw line between two points using OpenLayers

后端 未结 2 809
借酒劲吻你
借酒劲吻你 2021-01-04 02:39

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.transf         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-01-04 03:11

    In OpenLayers version 3.3, you can do this as

    var points = [ [-89.8802, 32.5804], [-95.04286, 46.9235] ];
    
    for (var i = 0; i < points.length; i++) {
        points[i] = ol.proj.transform(points[i], 'EPSG:4326', 'EPSG:3857');
    }
    
    var featureLine = new ol.Feature({
        geometry: new ol.geom.LineString(points)
    });
    
    var vectorLine = new ol.source.Vector({});
    vectorLine.addFeature(featureLine);
    
    var vectorLineLayer = new ol.layer.Vector({
        source: vectorLine,
        style: new ol.style.Style({
            fill: new ol.style.Fill({ color: '#00FF00', weight: 4 }),
            stroke: new ol.style.Stroke({ color: '#00FF00', width: 2 })
        })
    });
    

    Then add layer to map

    map.addLayer(vectorLineLayer);
    

提交回复
热议问题