2016-08-17 15 views
5

私は現在の設定をfully functional fiddle exampleとしていますが、各ポリゴンフィーチャをズームして管理していますが、それぞれに集中テキストラベルを表示したいと思います... field_title変数が見つかりました方法はget_fieldsです。私はこれをどうやってやるべきかわからず、私のグーグル・グーグル・グーグルはすべてこの記事を読んでいます:http://openlayers.org/en/v3.3.0/examples/vector-labels.html私はまったく新しくOLになってしまいました。Openlayers 3:機能にテキストラベルを追加

+0

アニメーションパーツを別の質問に移動できますか?この最初の混乱に役立ちます。 @JonatasWalkerがやった。 –

+0

ありがとう。 –

答えて

9

あなたはstyle function(つまり機能から説明を取得し、それを表示します)での機能の記述とset a style格納するol.Featureにテキストを追加するには:

field_polygon.set('description', field_title); 
field_polygon.setStyle(styleFunction); 

function styleFunction() { 
    return [ 
    new ol.style.Style({ 
     fill: new ol.style.Fill({ 
     color: 'rgba(255,255,255,0.4)' 
     }), 
     stroke: new ol.style.Stroke({ 
     color: '#3399CC', 
     width: 1.25 
     }), 
     text: new ol.style.Text({ 
     font: '12px Calibri,sans-serif', 
     fill: new ol.style.Fill({ color: '#000' }), 
     stroke: new ol.style.Stroke({ 
      color: '#fff', width: 2 
     }), 
     // get the text from the feature - `this` is ol.Feature 
     // and show only under certain resolution 
     text: map.getView().getZoom() > 12 ? this.get('description') : '' 
     }) 
    }) 
    ]; 
} 

Your fiddleを。

+0

これは素晴らしいです!ありがとうございました!特定のズームレベルの上にテキストを表示するにはどうすればよいですか? –

+1

更新された回答を参照してください。 'map.getView()。getZoom()> 12? this.get( 'description'): '' ' –

+0

パーフェクト、ありがとう! –

関連する問題