0

I'm attempting to change the styling of a line segment when clicked on a layer that has 4 segments. Only one segment's style would be changed at a time. Each segment has it's own column within a CARTO dataset. I was wondering if it was possible to accomplish this using only one dataset and not creating separate datasets for each segment? As of now when a line segment is clicked, all segments get the new styling applied.

Example of what I am trying to accomplish:

enter image description here

Below is the code I am using to change the styling:

routeLayer.on('featureClicked', featureEvent => {
  routeStyle.setContent(`
    #layer {
        line-width: 6;
        line-color: #c1d82f;
        line-opacity: 1;
     }
  `);
});

JSFiddle example.

0

I resolved my issue using CartoCSS conditional styling.

routeLayer.on('featureClicked', featureEvent => {
  console.log(featureEvent.data.name);
  routeStyle.setContent(`
    #layer {
      line-width: 6;
      line-color: #0067b1;
      line-opacity: 1;

      [name = '` + featureEvent.data.name + `']{
        line-width: 6;
        line-color: #c1d82f;
        line-opacity: 1;
      }
    }
  `);
});
|improve this answer|||||

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.