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 
     });

1 Answer 1

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).

4
  • I'm sorry but it didn't work for me I can't understand why :(
    – b-eyes
    Commented Dec 26, 2014 at 17:58
  • What does your line look like? Are you sure that you don't a problem with your source? Commented Dec 26, 2014 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
    Commented Dec 26, 2014 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. Commented Dec 28, 2014 at 11:42

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.