2015-11-02 67 views

回答

6

對於帶有geometry function的標籤,您可以使用單獨的樣式,該標籤將爲標籤位置返回單個點。

var styles = [ 
    // Style for the label 
    new ol.style.Style({ 
    text: new ol.style.Text({..}), 
    geometry: function(feature) { 
     // expecting a MultiPolygon here 
     var interiorPoints = feature.getGeometry().getInteriorPoints(); 
     return interiorPoints.getPoint(0); 
    } 
    }), 
    // Style for the polygons 
    new ol.style.Style({ 
    stroke: new ol.style.Stroke({...}), 
    fill: new ol.style.Fill({...}) 
    }) 
]; 

http://jsfiddle.net/p0acpbtg/2/

+0

真是太好了! '+ 1' ...因此不喜歡'+ 1'。 –

+0

工程就像一個魅力!真棒。 – Enzo

+0

不適合我。它集中在多面體內的一個多邊形上。如果我將它更改爲'return interiorPoints.getPoint(1);'它以另一個多邊形爲中心。我怎樣才能讓它集中在多面體上? –