1

I'm trying to set the transparency of the polygons on the map. This works and I can save them in the database with this code:

$('#constructii_trasp').on('change', function(){
                            var constructii_transp = $('#constructii_trasp').val();
                            var valoare_transp = constructii_transp / 100
                            console.log(valoare_transp);
                            
                            
                            
                            $.post( "ser_edit_pdf.php", 
                                 {
                                      save_setari_transparenta_constructii: 1,
                                      transp_constructii: valoare_transp
                                 },
                                 function( data ) {
                                    console.log('save setup');
                                    console.log(data);
                                    var color = JSON.parse(data);
                        
                                      constructii.setOpacity(color.opacity_constructii); 
                                    
                                    })
                              
                            
                        });

The style in function :

features.forEach(function(feature){
                                                    feature.setId(undefined);
                                                    feature.getGeometry().transform('EPSG:31700', 'EPSG:3857');
                                                    
                                                    
                                                var const_stile = new ol.style.Style({
                                                    fill: new ol.style.Fill({color: color.color_constructii}),
                                                    stroke: new ol.style.Stroke({
                                                      color: [0,51,204], width: 1
                                                    }),
                                                  text: new ol.style.Text({
                                                    font: 'bold 11px "Open Sans", "Arial Unicode MS", "sans-serif"',
                                                    placement: 'center',
                                                    fill: new ol.style.Fill({
                                                      color: 'white'
                                                    })
                                                  })
                                                });
                                                
                                                
                                            
                                               
                                                var id_pdf = "";
                                                
                                              
                                                
                                                 var data = "N:"+feature.get('numar_const')+"/F:"+feature.get('folosinta')+"/S:"+feature.get('suprafata')+" MP.";
                                                
                                                if(feature.get('layer') == "CONSTRUCTIE"){
                                                    const_stile.getText().setText(data);
                                                    feature.setStyle(const_stile);
                                                }
                                                
                                               
                                             
                                                 
                                                });
                                                
                                                if (found_extent == 0) {
                                                    features.forEach(function(feature){
                                                        
                                                        ol.extent.extend(extent, feature.getGeometry().getExtent());
                                                    });
                                                }
                                                
                                                vectorSource.constructii.clear();
                                                vectorSource.constructii.addFeatures(features);
                                                

But when I set a value for the opacity of the polygons, the polygon delimitation line disappears ...

I would like the delimitation line not to be opaque and to remain drawn, but only the interior of the polygon to decrease in transparency.

3
  • can you add a picture of what you do see and what you would like to see
    – Ian Turton
    Commented Dec 11, 2020 at 8:57
  • And edit your code (remove unnecessary leading spaces) so it can be readable.
    – TomazicM
    Commented Dec 11, 2020 at 9:25
  • Check the openlayers example of polygon styles: openlayers.org/en/latest/examples/polygon-styles.html. The stroke style refers to the delimitation line, if I understood your question correctly.
    – gHupf
    Commented Dec 11, 2020 at 9:31

1 Answer 1

1

You should set the opacity as the alpha component of the fill color instead of setting the opacity of the whole layer

 var colorArray = ol.color.asArray(color.color_constructii).slice(0, 3).concat([color.opacity_constructii]);
 var const_stile = new ol.style.Style({
     fill: new ol.style.Fill({color: colorArray}),
     ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.