简体   繁体   English

Openlayers 3为辅助几何造型

[英]Openlayers 3 style a secondary geometry

I've got a feature object with three geometries on it, main and two others. 我有一个要素对象,上面有三个几何,主要和另外两个。 Is there a way of styling each one of the geometries on a styleFunction pass? 有没有一种方法可以对styleFunction传递中的每个几何进行样式设置? If one is a point geometry and the other two are linestring geometries, how would I style all three in one styleFunction? 如果一个是点几何,另外两个是线串几何,我该如何在一个styleFunction中对所有三个进行样式设置?

I've got as far as having the sub-geometries available and the styleFunction can switch them with a call to this.setGeometryName() but after that I'm a bit stumped - as the point geometry at this point has already been styled (there is an array of styles waiting to be sent back from the styleFunction). 我已经拥有了可用的子几何体,并且styleFunction可以通过调用this.setGeometryName()来切换它们,但是在那之后我有些困惑-因为此时的点几何体已经过样式化(有一系列样式等待从styleFunction发送回来。

Am I correct in thinking I can style the other two geometries as well, or should I have a separate layer with separate geometries and style them individually (this would add an overhead). 我是否认为我也可以设置其他两个几何形状的样式是否正确,还是应该在单独的图层上设置单独的几何形状并分别设置样式(这会增加开销)。

Add sub-geometries as named 'sets' of the feature ( feature.set() ), then call them via this.get('name of geometry') and place that into an ol.style.Style call as the geometry parameter, then you can style it individually for that style. 将子几何添加为要素( feature.set() )的命名“集合”,然后通过this.get('name of geometry')对其进行调用,并将其作为geometry参数放入ol.style.Style调用geometry ,那么您可以为该样式分别设置样式。

Assuming your subgeometry is set on the feature as subgeom , your styleFunction could look like this: 假设您的子几何在要素上设置为subgeom ,则您的styleFunction可能如下所示:

function(feature, resolution) {
  return [
    new ol.style.Style({
      // main geometry style
    }),
    new ol.style.Style({
      geometry: feature.get('subgeom'),
      // subgeom style
    })
  ]
}

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

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