Dynamically changing the layer order is not possible #939
文章推薦指數: 80 %
Hello, In my use case I have a list of layers whose order can be messed up with. I made this sandbox to test the behaviour of inverting the ...
Skiptocontent
{{message}}
visgl
/
react-map-gl
Public
Notifications
Fork
1.2k
Star
6.6k
Code
Issues
11
Pullrequests
5
Discussions
Actions
Security
Insights
More
Code
Issues
Pullrequests
Discussions
Actions
Security
Insights
Newissue
Haveaquestionaboutthisproject?SignupforafreeGitHubaccounttoopenanissueandcontactitsmaintainersandthecommunity.
Pickausername
EmailAddress
Password
SignupforGitHub
Byclicking“SignupforGitHub”,youagreetoourtermsofserviceand
privacystatement.We’lloccasionallysendyouaccountrelatedemails.
AlreadyonGitHub?
Signin
toyouraccount
Jumptobottom
Dynamicallychangingthelayerorderisnotpossible
#939
Open
adrienjopenedthisissue
Nov13,2019
·5comments
Open
Dynamicallychangingthelayerorderisnotpossible
#939
adrienjopenedthisissue
Nov13,2019
·5comments
Labels
feature
Comments
Copylink
adrienj
commented
Nov13,2019
•
edited
Hello,InmyusecaseIhavealistoflayerswhoseordercanbemessedupwith.
Imadethissandboxtotestthebehaviourofinvertingthesecondandthirditemsinalistoffour.Theseconditemisputatthetopofthelayering.
Reproducethebug:
https://codesandbox.io/s/shy-waterfall-fwky3
Itriedaddingthearrayindexinthelayerkeybutthethirdlayergoestothetopinsteadofbellowtheforth.Maybethisisbecausetheforthlayer'skeydidn'tchange,soitisnotkeptaboveallotherlayers?
Ialsotriedusingarandomkeyforthelayers.Thiseliminatestheorderissuebutmightbebadforperformance.InthesecondsandboxItriedtodynamicallychangethekeyofthelayersonlyafterachangeinorderandnotoneveryrender.
Expectedbehaviour:
https://codesandbox.io/s/brave-firefly-zr9oc
Ifafixmightbreakotherusecases,maybeanewproptotheLayercomponentthatspecifywewanttokeeptheordercouldbepossible?
Thanks
Thetextwasupdatedsuccessfully,buttheseerrorswereencountered:
Allreactions
Copylink
Collaborator
Pessimistress
commented
Jan6,2020
YoushouldbeabletoreorderbychangingthebeforeIdprop.
👍
1
chriszrcreactedwiththumbsupemoji
Allreactions
👍
1reaction
Sorry,somethingwentwrong.
Copylink
yurivangeffen
commented
Apr29,2020
Ipersonallyfindthisaveryminimalsolutionthatdoesn'treallyworkifyouwanttoswitchlayersinandoutdynamically.Nowallofasuddenmylayercomponentsneedtoknowofthestateofallotherlayers,weitherthey'reshownornot,etc...Iknowthisiswhat'sexposedbymapbox,butisthereanotherwaytodoorderingproperly,throughkeyforexample?
👍
3
adrienj,maxwell-oroark,andMattReimerreactedwiththumbsupemoji
Allreactions
👍
3reactions
Sorry,somethingwentwrong.
Copylink
yurivangeffen
commented
May7,2020
Iusedadifferentwayoffixingthisformyspecificusecase:
Createsomelayersthatarealwayssortedrelativetoeachother.Theyshouldn'thaveanycontent,sowhatIdoisusethe'background'typeandsetvisibilityto'none',e.g.:
['baselayer','some_other_layer','yet_another_one'].map(name=>{
return(
延伸文章資訊
- 1Layer — Urbica React Map GL
Except for layers of the background type, each layer needs to refer to a source. Layers take the ...
- 2Urbica React Mapbox GL JS - GitHub
React Component Library for Mapbox GL JS. Mapbox GL JS is a JavaScript library that renders inter...
- 3how can i add source and layer to my react-map-gl
i'm trying to add source and layers on my map and it's not rendering ... import ReactMapGL, {Sour...
- 4react-map-gl examples - CodeSandbox
Learn how to use react-map-gl by viewing and forking react-map-gl example apps on ... that provid...
- 5Layer - react-map-gl
This component allows apps to create a map layer using React. import * as React from 'react'; imp...