Code Monkey home page Code Monkey logo

Comments (17)

kneemer avatar kneemer commented on June 11, 2024

I'm not sure what is going on here @daniel-sabourin, I forked your fiddle and put in a different feature service feature service and it works as expected. I chose one that had the same geometry type and renderer. In your fiddle, if you put in another timeout and call resetStyle on the feature layer it goes back to the published symbology so for some reason it is being overwritten by setStyle instead of merging the styles.

from esri-leaflet-renderers.

jgravois avatar jgravois commented on June 11, 2024

@kneemer i loaded your fork a handful of times and i was able to repro reported error once there too.

from esri-leaflet-renderers.

kneemer avatar kneemer commented on June 11, 2024

@jgravois I saw the error just now when I first clicked on my fork but refreshed and now cannot reproduce.

from esri-leaflet-renderers.

daniel-sabourin avatar daniel-sabourin commented on June 11, 2024

The issue seems to occur whenever new features are downloaded after the opacity has been changed. The reason why your fiddle works most of the time is that all the features are downloaded before the opacity change occurs.

Another fiddle with another service, this time with polygons

from esri-leaflet-renderers.

kneemer avatar kneemer commented on June 11, 2024

It does appear that way. Currently, all the renderer does is define the style function for the feature layer after the layer is initialized and the esri-leaflet plugin handles it after that. It does not hook into any other events. This may have to be resolved in the esri-leaflet plugin, the style is there it is just not being applied when the new features download. I updated your polygon fiddle to reset the style and reapply the opacity after the features are downloaded and it gets the proper styles.

from esri-leaflet-renderers.

daniel-sabourin avatar daniel-sabourin commented on June 11, 2024

If this has to be solved in esri-leaflet, should I create an issue over there?

from esri-leaflet-renderers.

jgravois avatar jgravois commented on June 11, 2024

should I create an issue over there?

let's continue trying to identify a repo case here first. when i remove renderers from the equation and just define one style in the constructor and another later, i don't see the problem.

fiddle

from esri-leaflet-renderers.

kneemer avatar kneemer commented on June 11, 2024

@jgravois, I reproduced with your fiddle by setting more than opacity on the constructor style, updated fiddle

from esri-leaflet-renderers.

daniel-sabourin avatar daniel-sabourin commented on June 11, 2024

My workaround right now has been to call resetStyle() and setStyle() on FeatureLayer load. It's not ideal, but it works. The leaflet style shows briefly, and then is applied properly

fiddle

from esri-leaflet-renderers.

jgravois avatar jgravois commented on June 11, 2024

I reproduced with your fiddle by setting more than opacity...

thanks for this. it helped me remember that we don't mixin individual properties when someone calls setStyle(). we overwrite the renderer completely. because of this, its up to @daniel-sabourin to provide all the appropriate style info himself at that time.

what would be the most helpful thing the APIs could do? perhaps to provide public access to the previously defined mixed in, server side rendering style for reuse?

from esri-leaflet-renderers.

daniel-sabourin avatar daniel-sabourin commented on June 11, 2024

If I'm required to provide all style information myself, I should be able to get the currently applied style. That way I can merge in opacity and call setStyle.

Something as simple as getStyle() should suffice.

from esri-leaflet-renderers.

jgravois avatar jgravois commented on June 11, 2024

Something as simple as getStyle() should suffice.

in esri-leaflet core you can already use fl.options.style. in renderers, we swap in a more complex function to do our 'mixing in'.

let me and @kneemer chew a bit. we'll figure something out.

from esri-leaflet-renderers.

kneemer avatar kneemer commented on June 11, 2024

@daniel-sabourin, @jgravois, renderers binds a style function to fl.options.style so it will be available on the feature layer once it is initialized. It is possible to have a style function just using esri-leaflet as well example.

I updated the both fiddles with the following function to read styles and update opacity on it, with renderer plugin and just esri-leaflet

function setLayerOpacity(layer, opacity){
  if (layer.options.style) {
    var combinedStyle = (typeof layer.options.style === 'function') ? layer.options.style() : layer.options.style;          
    combinedStyle.opacity = opacity;
    layer.setStyle(combinedStyle) 
  }
}

Two things to note:

  1. Calling this function before the layer is fully initialized will result in no change to the style because layer.options.style will be undefined
  2. The function above will only work for simple renderers, if you have a unique value or class break renderer you would need to pass a feature into the style function.

from esri-leaflet-renderers.

jgravois avatar jgravois commented on June 11, 2024

i like this.
just a note, it is necessary to set fillOpacity if you want partially transparent polygons.

from esri-leaflet-renderers.

daniel-sabourin avatar daniel-sabourin commented on June 11, 2024

@kneemer This looks like a pretty good solution. Just a note for your solution, you forgot to rename your variables to use layer, instead of fl

from esri-leaflet-renderers.

kneemer avatar kneemer commented on June 11, 2024

Thanks for the feedback @daniel-sabourin, I've updated the comment and fiddles to use the layer parameter instead of fl.

from esri-leaflet-renderers.

jgravois avatar jgravois commented on June 11, 2024

okay. closing, but happy to chat more if anyone has any questions.

from esri-leaflet-renderers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.