3mapslab / Leaflet.streetlabels

Display the street labels following polylines for Leaflet
ISC License
72 stars 13 forks source link

Changing line colours #20

Closed jackfrojpg closed 1 year ago

jackfrojpg commented 1 year ago

Hi, I've looked into the code a lot and done some research but I cannot figure it out:

How can I change the colour of the line on the road from blue to, e.g., red? And, how can I change the width/weight of the line?

Thanks

jdsantos commented 1 year ago

Hi there @jackfrojpg!

The color is not forced in the plugin. Nevertheless, you can change it like this (check out https://leafletjs.com/reference.html#path-option):

var streetLabelsRenderer = new L.StreetLabels({
    collisionFlg: true,
    propertyName: 'name',
    showLabelIf: function (layer) {
      return true; //layer.properties.type == "primary";
    },
    fontStyle: {
      dynamicFontSize: false,
      fontSize: 10,
      fontSizeUnit: "px",
      lineWidth: 4.0,
      fillStyle: "black",
      strokeStyle: "white",
    },
  });

  //Load the OPorto Dataset
  var oportoDataset = L.geoJSON(oporto, {
       style: function (feature) {
            return {
                    stroke: true,
                    color: "#ff0000", // red line
                    weight: 5, // width in pixels
            };
       }
  });

Cheers,

Jorge