2016-11-12 207 views
0

早上好,z標籤上的索引

我在標記中的zindex標籤有問題。 ZIndex受到標記類型Image的尊重,但是當我嘗試添加標籤時:Zindex未應用於標籤上。 enter image description here

我使用的代碼見下文:

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

可能有人能告訴我,我在做什麼錯? 在此先感謝。

回答

0

請,檢查這個代碼,這是小提琴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()) 
+0

請不要忘記給予好評這個答案,如果它是對你有用,謝謝! – dev9

+0

感謝您的回覆,但問題不會改變。請參閱http://jsfiddle.net/feg5um2t/(嘗試縮小) – Slayes

+0

當縮小標記重疊時..所以是標籤...他們不應該重疊..你試圖做什麼... – dev9