5

I want to display a dashed line in a vector layer, as the it's shown in the Documentation there is a propriety called lineDash , but it didn't work for me here my code :

 var iconStyle_line = new ol.style.Style({//  My style definition 
          fill: new ol.style.Fill({
          color: 'rgba(221, 99, 0, 0.5)'
          }),
          stroke: new ol.style.Stroke({
          color: 'rgba(221, 99, 0, 0.5)',
          width: 3,
          lineDash: [4]
          })
     });

 var vectorSource_line = new ol.source.Vector();//  My vector source

 var vector_line = new ol.layer.Vector({

         source: vectorSource_line,
         style: iconStyle_line 
     });
10

Try this:

var iconStyle_line = new ol.style.Style({//  My style definition 
      fill: new ol.style.Fill({
      color: 'rgba(221, 99, 0, 0.5)'
      }),
      stroke: new ol.style.Stroke({
      color: 'rgba(221, 99, 0, 0.5)',
      width: 3,
      lineDash: [4,4] // <-Here is the change. first line then space. try [40,40] if not shown as dash
      })
 });

Be careful about the 'LineDash' values if you program for mobile devices. Then [4,4] is not visible on a small screen with high resolution. Use e.g. [15,15] and store the resolution in a variable which changes with the device (PC or mobile).

  • I'm sorry but it didn't work for me I can't understand why :( – b-eyes Dec 26 '14 at 17:58
  • What does your line look like? Are you sure that you don't a problem with your source? – Anders Finn Jørgensen Dec 26 '14 at 18:04
  • I did exactly what @Anders wrote but nothing changed , I don't think that there is a problem with the source because I can add a lineString vector normally and it is shown as a simple line without dashes – b-eyes Dec 26 '14 at 18:08
  • 2
    Hi again. Does the line appears but without dash or have you no line at all? If the line appears try [40,40] to see if you got dash. The unit of dash is pixels and if your screen is very high def, you will maybe not see the dash, even if it is there. – Anders Finn Jørgensen Dec 28 '14 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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