【问题标题】:OpenLayers 3: How to change/set the style of vector mapOpenLayers 3:如何更改/设置矢量图的样式
【发布时间】:2015-08-12 13:01:52
【问题描述】:

我正在尝试从室内矢量图中删除所有线条。我不确定如何使用样式来做到这一点。有人可以指导我吗?

这是我如何设置地图的代码:

var vector = new ol.layer.Vector({
    source: new ol.source.Vector({
        url: MAPS_URL + 'map.kml',
        format: new ol.format.KML()
    })
});

var map = new ol.Map({
  layers: [vector],  
  target: 'floormap',
  interactions: ol.interaction.defaults({mouseWheelZoom:false}),
  view: new ol.View({
      center: [0, 0],          
      zoom: 15,
      minZoom: 15,
      maxZoom: 18
    })    
}); 

我是否必须使用 foreachfeature 方法来循环遍历功能并单独设置样式,或者有没有办法在地图上设置全局样式?我认为向量在没有定义时采用默认样式,我如何创建一个没有描边或填充的样式,然后将其设置为矢量图的样式?

谢谢你

【问题讨论】:

  • 你检查examples了吗?
  • 不,我很懒惰。我将在下面添加一些工作代码

标签: javascript maps vector-graphics openlayers-3


【解决方案1】:

这是从 Jonatas 提供的链接中获得的解决方案

var stroke = new ol.style.Stroke({
    color: 'rgba(255, 204, 0, 0)',
    width: 0,
});

var style = new ol.style.Style({
    stroke: stroke
});


vector = new ol.layer.Vector({
    source: new ol.source.Vector({
        url: MAPS_URL + maps[map_id],
        format: new ol.format.KML({
            extractStyles: false
        })
    }),
    style: style
});        

map.addLayer(vector);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-26
    • 1970-01-01
    • 2015-10-07
    相关资源
    最近更新 更多