简体   繁体   中英

Leaflet layers, check if a feature.properties exist

I have two layers with markers in a leaflet map. One have a property "rotation", not the other one. How can I determine if my layer have the property "rotation" or no, in order to be able to set a rotation for my markers I want to rotate ?

I tried but it doesn't works :

 if (feature.properties.rotation){ var rotate = feature.properties.rotation; } else if (feature.properties.rotation === undefined){ var rotate = 0; } style = { rotation: rotate };

Ok, I fixed it using .hasOwnProperty()

Here is the code :

 if (feature.hasOwnProperty('rotation')){ var rotate = feature.properties.rotation; } else { var rotate = 0; } style = { rotation: rotate };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM