Comments (17)
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.
@kneemer i loaded your fork a handful of times and i was able to repro reported error once there too.
from esri-leaflet-renderers.
@jgravois I saw the error just now when I first clicked on my fork but refreshed and now cannot reproduce.
from esri-leaflet-renderers.
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.
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.
If this has to be solved in esri-leaflet, should I create an issue over there?
from esri-leaflet-renderers.
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.
from esri-leaflet-renderers.
@jgravois, I reproduced with your fiddle by setting more than opacity on the constructor style, updated fiddle
from esri-leaflet-renderers.
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
from esri-leaflet-renderers.
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.
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.
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.
@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:
- Calling this function before the layer is fully initialized will result in no change to the style because layer.options.style will be undefined
- 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.
i like this.
just a note, it is necessary to set fillOpacity
if you want partially transparent polygons.
from esri-leaflet-renderers.
@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.
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.
okay. closing, but happy to chat more if anyone has any questions.
from esri-leaflet-renderers.
Related Issues (20)
- About the main file HOT 3
- add support for text symbols HOT 6
- setWhere callback is not called HOT 3
- featureLayer throws 'this.options.userDefinedStyle is not a function' intermittently HOT 7
- Unable to use plugin via AMD HOT 7
- Unable to build under node v7.7.4 HOT 1
- picture marker symbols in custom panes don't draw in drupal (and other CMSs) HOT 19
- Next release? HOT 3
- service symbology not honored when field names are lower-case HOT 7
- Default Marker show up after clustering with esri-leaflet-cluster HOT 1
- Support valueExpression property of renderer. HOT 2
- Make esri-leaflet et al peerDependencies HOT 4
- Cluster HOT 5
- Uncaught TypeError: Cannot read property 'options' of undefined HOT 1
- initHooks are not setted using import style HOT 3
- TypeError: Cannot read properties of undefined (reading 'addInitHook') HOT 10
- Hi When deploying a docker the package gives this error and does not render a map HOT 2
- Support for esri leaflet 3 HOT 8
- Rendering/Redrawing layers created from ArcGIS point features fails due to Uncaught TypeError HOT 3
- Is it possible to use the plug-in to generate an image from symbol JSON for use outside of map
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esri-leaflet-renderers.