openlayers渲染wkt数据

  1. 数据示例
    openlayers渲染wkt数据_第1张图片

  2. 代码

var styles = new ol.style.Style({
    fill:new ol.style.Fill({
        color: 'rgba(239,152,152, 0.5)',
    }),
    stroke: new ol.style.Stroke({
        color: '#319FD3',
        width: 1,
    }),
    image: new ol.style.Circle({
        radius: 7,
        fill: new ol.style.Fill({
            color: 'red'
        })
    })
});

var source = new ol.layer.Tile({
    source:new ol.source.OSM()
});
var format =  new ol.format.WKT();
var feature = format.readFeature(POLYGON);
var vectorLayer = new ol.layer.Vector({
    source:new ol.source.Vector({
        features:[feature]
    }),
    style:styles
});

  1. 如果需要转换坐标的情况
var feature = format.readFeature(wkt, {
        dataProjection: 'EPSG:4326',
        featureProjection: 'EPSG:3857'
 });

你可能感兴趣的:(Openlayers,vue,开发语言)