【问题标题】:zIndex on Label标签上的 zIndex
【发布时间】:2016-11-13 01:52:29
【问题描述】:

早上好,

我的标记中标签的 zindex 有问题。 ZIndex 受到标记类型 Image 的尊重,但是当我尝试添加标签时:Zindex 未应用于标签。

我使用了如下代码:

var features = [];
var myStyle = new ol.style.Style({zIndex: 1,image: new ol.style.Icon(({anchor: [0.5, 74],anchorXUnits: 'fraction',anchorYUnits: 'pixels',src: '/css/images/markerB.png'})),text: new ol.style.Text({font: '100 28px icon_set_1',text: "Z",offsetY: -52,fill: new ol.style.Fill({color: 'black'})})});
var lat = 3;
for(i=0;i<=0.5;i+=0.1) {
  var lon = 50 + i;
  var iconFeature = new ol.Feature({geometry: new ol.geom.Point(ol.proj.transform([lon,lat], 'EPSG:4326',     'EPSG:3857'))});
  iconFeature.setStyle(myStyle);
  features.push(iconFeature);
}
vectorSource = new ol.source.Vector({features: features});vectorLayer = new ol.layer.Vector({source: vectorSource});map.addLayer(vectorLayer);

可能有人可以告诉我,我做错了什么? 提前致谢。

【问题讨论】:

    标签: label z-index openlayers-3


    【解决方案1】:

    请检查此代码,这是小提琴http://jsfiddle.net/n4h77xnz/

      var features = [];
      var myStyle = new ol.style.Style({
          zIndex: 1,
          image: new ol.style.Icon(({
              anchor: [0.5, 0.5],
              scale: 0.4,
              anchorXUnits: 'fraction',
              anchorYUnits: 'pixels',
              src: 'icon.png'
          })),
          text: new ol.style.Text({
              font: '100 22px icon_set_1',
              text: "yz",
              offsetY: 22,
              fill: new ol.style.Fill({
                  color: 'black'
              })
          })
      });
      var lat = 3;
      for (i = 0; i <= 0.5; i += 0.1) {
          var lon = 50 + i;
          console.log(lon, lat);
          var iconFeature = new ol.Feature({
              geometry: new ol.geom.Point(ol.proj.transform([lat, lon], 'EPSG:4326', 'EPSG:3857'))
          });
          iconFeature.setStyle(myStyle);
          features.push(iconFeature);
      }
      vectorSource = new ol.source.Vector({
          features: features
      });
      vectorLayer = new ol.layer.Vector({
          source: vectorSource
      });
      map.addLayer(vectorLayer);
    
      map.getView().fit(vectorLayer.getSource().getExtent(), map.getSize())
    

    【讨论】:

    • 如果这个答案对你有用,请不要忘记点赞,谢谢!
    • 感谢您的回复,但问题没有改变。请参阅jsfiddle.net/feg5um2t(尝试缩小)
    • 当缩小标记重叠时..标签也是如此...它们不应该重叠..您正在尝试做的...
    • 当我们缩小标记的图像时尊重 zindex 级别(自动),但标签始终是 zIndex 上级:( 每个标签的 zIndex 应该与图像的 zIndex 相同
    • 在 groups.google 上的 Alexandre Dubé 的帮助下解决了问题。以防万一读者的未来,mon 错误是由于:我尝试修改样式的 zIndex 之前将其应用到标记上,我尝试在每个标记上应用相同的“可变”样式
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-09
    • 2014-10-07
    • 1970-01-01
    • 2018-06-12
    • 1970-01-01
    • 2011-07-22
    • 2020-05-23
    相关资源
    最近更新 更多