2016-08-17 7 views
5

सुविधा के लिए टेक्स्ट लेबल जोड़ें: मेरे पास वर्तमान सेट अप है: fully functional fiddle example और जब भी मैं प्रत्येक बहुभुज सुविधा को ज़ूम करने में कामयाब रहा हूं, मैं प्रत्येक पर एक केंद्रीकृत टेक्स्ट लेबल भी प्रदर्शित करना चाहता हूं ... field_title वेरिएबल मिला get_fields विधि के भीतर। मुझे नहीं पता कि यह कैसे करना है और मेरे सभी गुगल इस आलेख के साथ आए हैं: http://openlayers.org/en/v3.3.0/examples/vector-labels.html जो मुझे पूरी तरह भ्रमित लगता है क्योंकि मैं ओएल के लिए थोड़ा नया हूं!ओपनलेयर 3:

+0

क्या आप एनिमेटिंग भाग को दूसरे प्रश्न पर ले जा सकते हैं? यह इस प्रारंभिक भ्रम में मदद कर सकता है। –

+0

@ जोनाटावाकर ने किया है। धन्यवाद। –

उत्तर

9

एक पाठ ol.Feature करने के लिए आप सुविधा में विवरण और set a style कि एक style function है स्टोर करेगा जोड़ने के लिए (कि सुविधा से वर्णन मिल जाएगा और यह दिखाने):

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

बिल्कुल सही, धन्यवाद! –

संबंधित मुद्दे