OpenLayers: feature.setStyle overwrites style of Select interaction Unicorn Meta Zoo #1: Why...

Raising a bilingual kid. When should we introduce the majority language?

Marquee sign letters

When does Bran Stark remember Jamie pushing him?

"Working on a knee"

My admission is revoked after accepting the admission offer

Was Objective-C really a hindrance to Apple software development?

Mechanism of the formation of peracetic acid

How can I wire a 9-position switch so that each position turns on one more LED than the one before?

Has a Nobel Peace laureate ever been accused of war crimes?

What to do with someone that cheated their way though university and a PhD program?

Getting AggregateResult variables from Execute Anonymous Window

Protagonist's race is hidden - should I reveal it?

Is there an efficient way for synchronising audio events real-time with LEDs using an MCU?

Why isn't everyone flabbergasted about Bran's "gift"?

How would you suggest I follow up with coworkers about our deadline that's today?

What is the term for extremely loose Latin word order?

Determinant of a matrix with 2 equal rows

Why aren't road bicycle wheels tiny?

Is it appropriate to mention a relatable company blog post when you're asked about the company?

Are there existing rules/lore for MTG planeswalkers?

Stretch a Tikz tree

What is the numbering system used for the DSN dishes?

What is a 'Key' in computer science?

What's parked in Mil Moscow helicopter plant?



OpenLayers: feature.setStyle overwrites style of Select interaction



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar ManaraOpenLayers 3 interaction Select ProblemIs age based SLD styling possible in GeoServer?Openlayers 3 Select Interaction style functionOpenLayers 3 get interaction draw styleopenlayers3 restore original style of specific featureError loading geoJSON into map using OpenLayers v4.2.0Dynamically styling GeoJSON feature layer in OpenLayers 3?mapbox styling of vector tiles with many features in openlayers 4Any way to style LineString-features with Stroke and Fill?How to make dynamic labeling in a project for new features on QGIS?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















let's say I have a vector layer created from 2 features.




  • The vector layer has style set to green color.

  • There is a select interaction with a style set to red color (in other words, I want to click on a feature and make it turn red).

  • I set style of one of the features to blue color by calling feature.setStyle().


If I select the green feature, it shows up red.
If I select the blue feature, it stays blue.



Is that correct behaviour?



Following is the code snippet:



const geojsonObject = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
properties: {},
geometry: {
type: 'Polygon',
coordinates: [
[ [10.0, 40.0], [15.0, 40.0], [15.0, 50.0], [10.0, 50.0], [10.0, 40.0] ]
]
}
},
{
type: 'Feature',
properties: {},
geometry: {
type: 'Polygon',
coordinates: [
[ [16.0, 40.0], [20.0, 40.0], [20.0, 50.0], [16.0, 50.0], [16.0, 40.0] ]
]
}
}
]
};

const greenStyle = new Style({
stroke: new Stroke({color: 'green', width: 3}),
fill: new Fill({color: 'rgba(0, 255, 0, 0.1)'})
});

const redStyle = new Style({
stroke: new Stroke({color: 'red',width: 3}),
fill: new Fill({color: 'rgba(255, 0, 0, 0.1)'})
});

const blueStyle = new Style({
stroke: new Stroke({color: 'blue', width: 3}),
fill: new Fill({color: 'rgba(0, 0, 255, 0.1)'})
});

const vector = new VectorLayer({
source: new VectorSource({
features: (new GeoJSON()).readFeatures(geojsonObject, {featureProjection: 'EPSG:3857'})
}),
style: greenStyle
});

const select = new Select({
condition: function(mapBrowserEvent) {
return click(mapBrowserEvent) && altKeyOnly(mapBrowserEvent);
},
style: redStyle
});

map.addInteraction(select);
select.on('select', (e) => {
console.log('selected:', e);
});

const firstFeature = vector.getSource().getFeatures()[0];
firstFeature.setStyle(blueStyle);


setStyle overwrites style of Select interaction









share





























    0















    let's say I have a vector layer created from 2 features.




    • The vector layer has style set to green color.

    • There is a select interaction with a style set to red color (in other words, I want to click on a feature and make it turn red).

    • I set style of one of the features to blue color by calling feature.setStyle().


    If I select the green feature, it shows up red.
    If I select the blue feature, it stays blue.



    Is that correct behaviour?



    Following is the code snippet:



    const geojsonObject = {
    type: 'FeatureCollection',
    features: [
    {
    type: 'Feature',
    properties: {},
    geometry: {
    type: 'Polygon',
    coordinates: [
    [ [10.0, 40.0], [15.0, 40.0], [15.0, 50.0], [10.0, 50.0], [10.0, 40.0] ]
    ]
    }
    },
    {
    type: 'Feature',
    properties: {},
    geometry: {
    type: 'Polygon',
    coordinates: [
    [ [16.0, 40.0], [20.0, 40.0], [20.0, 50.0], [16.0, 50.0], [16.0, 40.0] ]
    ]
    }
    }
    ]
    };

    const greenStyle = new Style({
    stroke: new Stroke({color: 'green', width: 3}),
    fill: new Fill({color: 'rgba(0, 255, 0, 0.1)'})
    });

    const redStyle = new Style({
    stroke: new Stroke({color: 'red',width: 3}),
    fill: new Fill({color: 'rgba(255, 0, 0, 0.1)'})
    });

    const blueStyle = new Style({
    stroke: new Stroke({color: 'blue', width: 3}),
    fill: new Fill({color: 'rgba(0, 0, 255, 0.1)'})
    });

    const vector = new VectorLayer({
    source: new VectorSource({
    features: (new GeoJSON()).readFeatures(geojsonObject, {featureProjection: 'EPSG:3857'})
    }),
    style: greenStyle
    });

    const select = new Select({
    condition: function(mapBrowserEvent) {
    return click(mapBrowserEvent) && altKeyOnly(mapBrowserEvent);
    },
    style: redStyle
    });

    map.addInteraction(select);
    select.on('select', (e) => {
    console.log('selected:', e);
    });

    const firstFeature = vector.getSource().getFeatures()[0];
    firstFeature.setStyle(blueStyle);


    setStyle overwrites style of Select interaction









    share

























      0












      0








      0








      let's say I have a vector layer created from 2 features.




      • The vector layer has style set to green color.

      • There is a select interaction with a style set to red color (in other words, I want to click on a feature and make it turn red).

      • I set style of one of the features to blue color by calling feature.setStyle().


      If I select the green feature, it shows up red.
      If I select the blue feature, it stays blue.



      Is that correct behaviour?



      Following is the code snippet:



      const geojsonObject = {
      type: 'FeatureCollection',
      features: [
      {
      type: 'Feature',
      properties: {},
      geometry: {
      type: 'Polygon',
      coordinates: [
      [ [10.0, 40.0], [15.0, 40.0], [15.0, 50.0], [10.0, 50.0], [10.0, 40.0] ]
      ]
      }
      },
      {
      type: 'Feature',
      properties: {},
      geometry: {
      type: 'Polygon',
      coordinates: [
      [ [16.0, 40.0], [20.0, 40.0], [20.0, 50.0], [16.0, 50.0], [16.0, 40.0] ]
      ]
      }
      }
      ]
      };

      const greenStyle = new Style({
      stroke: new Stroke({color: 'green', width: 3}),
      fill: new Fill({color: 'rgba(0, 255, 0, 0.1)'})
      });

      const redStyle = new Style({
      stroke: new Stroke({color: 'red',width: 3}),
      fill: new Fill({color: 'rgba(255, 0, 0, 0.1)'})
      });

      const blueStyle = new Style({
      stroke: new Stroke({color: 'blue', width: 3}),
      fill: new Fill({color: 'rgba(0, 0, 255, 0.1)'})
      });

      const vector = new VectorLayer({
      source: new VectorSource({
      features: (new GeoJSON()).readFeatures(geojsonObject, {featureProjection: 'EPSG:3857'})
      }),
      style: greenStyle
      });

      const select = new Select({
      condition: function(mapBrowserEvent) {
      return click(mapBrowserEvent) && altKeyOnly(mapBrowserEvent);
      },
      style: redStyle
      });

      map.addInteraction(select);
      select.on('select', (e) => {
      console.log('selected:', e);
      });

      const firstFeature = vector.getSource().getFeatures()[0];
      firstFeature.setStyle(blueStyle);


      setStyle overwrites style of Select interaction









      share














      let's say I have a vector layer created from 2 features.




      • The vector layer has style set to green color.

      • There is a select interaction with a style set to red color (in other words, I want to click on a feature and make it turn red).

      • I set style of one of the features to blue color by calling feature.setStyle().


      If I select the green feature, it shows up red.
      If I select the blue feature, it stays blue.



      Is that correct behaviour?



      Following is the code snippet:



      const geojsonObject = {
      type: 'FeatureCollection',
      features: [
      {
      type: 'Feature',
      properties: {},
      geometry: {
      type: 'Polygon',
      coordinates: [
      [ [10.0, 40.0], [15.0, 40.0], [15.0, 50.0], [10.0, 50.0], [10.0, 40.0] ]
      ]
      }
      },
      {
      type: 'Feature',
      properties: {},
      geometry: {
      type: 'Polygon',
      coordinates: [
      [ [16.0, 40.0], [20.0, 40.0], [20.0, 50.0], [16.0, 50.0], [16.0, 40.0] ]
      ]
      }
      }
      ]
      };

      const greenStyle = new Style({
      stroke: new Stroke({color: 'green', width: 3}),
      fill: new Fill({color: 'rgba(0, 255, 0, 0.1)'})
      });

      const redStyle = new Style({
      stroke: new Stroke({color: 'red',width: 3}),
      fill: new Fill({color: 'rgba(255, 0, 0, 0.1)'})
      });

      const blueStyle = new Style({
      stroke: new Stroke({color: 'blue', width: 3}),
      fill: new Fill({color: 'rgba(0, 0, 255, 0.1)'})
      });

      const vector = new VectorLayer({
      source: new VectorSource({
      features: (new GeoJSON()).readFeatures(geojsonObject, {featureProjection: 'EPSG:3857'})
      }),
      style: greenStyle
      });

      const select = new Select({
      condition: function(mapBrowserEvent) {
      return click(mapBrowserEvent) && altKeyOnly(mapBrowserEvent);
      },
      style: redStyle
      });

      map.addInteraction(select);
      select.on('select', (e) => {
      console.log('selected:', e);
      });

      const firstFeature = vector.getSource().getFeatures()[0];
      firstFeature.setStyle(blueStyle);


      setStyle overwrites style of Select interaction







      openlayers style





      share












      share










      share



      share










      asked 3 mins ago









      Stanislav DušekStanislav Dušek

      615




      615






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "79"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f320664%2fopenlayers-feature-setstyle-overwrites-style-of-select-interaction%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f320664%2fopenlayers-feature-setstyle-overwrites-style-of-select-interaction%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Щит и меч (фильм) Содержание Названия серий | Сюжет |...

          is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

          Meter-Bus Содержание Параметры шины | Стандартизация |...