简体   繁体   English

OpenLayers 3:如何更改/设置矢量地图的样式

[英]OpenLayers 3: How to change/set the style of vector map

I am trying to remove all of the lines from an indoor vector map. 我正在尝试从室内矢量地图中删除所有线条。 Im not sure how to do this using styles. 我不确定如何使用样式执行此操作。 Can someone guide me on this? 有人可以指导我吗?

here is the code of how i set the map up: 这是我如何设置地图的代码:

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
    })    
}); 

do i have to use the foreachfeature method to loop through the features and set the style individually or is there a way to set a global style on the map? 我是否必须使用foreachfeature方法来遍历要素并分别设置样式,或者是否可以在地图上设置全局样式? I think vectors take on a default style when none is defined, how do i create a style with no stroke or fill, and then set that as the style for the vector map? 我认为向量在未定义时采用默认样式,如何创建没有笔触或填充的样式,然后将其设置为向量图的样式?

thank you 谢谢

here is the solution, gotten from the link that Jonatas provided 这是从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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM