@@ -18,7 +18,7 @@ const source = new VectorSource({
1818/**
1919 * @type {import('ol/style/flat.js').FlatStyle }
2020 */
21- const style = {
21+ const baseStyle = {
2222 'fill-color' : [ 'get' , 'color' ] ,
2323 'text-value' : [ 'get' , 'label' ] ,
2424 'text-font' : 'bold 12px "Open Sans", "Arial Unicode MS", sans-serif' ,
@@ -27,6 +27,18 @@ const style = {
2727 'text-stroke-width' : 2 ,
2828} ;
2929
30+ /**
31+ * @type {import('ol/style/flat.js').FlatStyle }
32+ */
33+ const textStyle = {
34+ 'text-value' : [ 'get' , 'label' ] ,
35+ 'text-font' : 'bold 12px "Open Sans", "Arial Unicode MS", sans-serif' ,
36+ 'text-fill-color' : '#333' ,
37+ 'text-stroke-color' : 'rgba(255,255,255,0.8)' ,
38+ 'text-stroke-width' : 2 ,
39+ 'text-offset-y' : - 12 ,
40+ } ;
41+
3042/**
3143 * @param {number } count The number of features to create.
3244 * @param {number } numVertices Number of vertices for polygons
@@ -38,9 +50,15 @@ function resetData(count, numVertices) {
3850function main ( ) {
3951 createMap (
4052 ( map ) => {
53+ const style = getGuiParameterValue ( 'text' )
54+ ? { ...baseStyle , ...textStyle }
55+ : baseStyle ;
4156 map . addLayer ( new WebGLVectorLayer ( { source, properties : { style} } ) ) ;
4257 } ,
4358 ( map ) => {
59+ const style = getGuiParameterValue ( 'text' )
60+ ? { ...baseStyle , ...textStyle }
61+ : baseStyle ;
4462 map . addLayer ( new VectorLayer ( { source, style} ) ) ;
4563 } ,
4664 ) ;
@@ -82,11 +100,23 @@ function main() {
82100 true ,
83101 ( value , initial ) => {
84102 if ( value ) {
85- style [ 'stroke-width' ] = 2 ;
86- style [ 'stroke-color' ] = 'gray' ;
103+ baseStyle [ 'stroke-width' ] = 2 ;
104+ baseStyle [ 'stroke-color' ] = 'gray' ;
87105 } else {
88- delete style [ 'stroke-width' ] ;
89- delete style [ 'stroke-color' ] ;
106+ delete baseStyle [ 'stroke-width' ] ;
107+ delete baseStyle [ 'stroke-color' ] ;
108+ }
109+ regenerateLayer ( ) ;
110+ } ,
111+ ) ;
112+ registerGuiParameter (
113+ 'text' ,
114+ 'Show labels' ,
115+ [ 'yes' , 'no' ] ,
116+ false ,
117+ ( value , initial ) => {
118+ if ( initial ) {
119+ return ;
90120 }
91121 regenerateLayer ( ) ;
92122 } ,
0 commit comments