mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

fitBounds doesn't work sometimes

Open sky0917 opened this issue 3 years ago • 5 comments

mapbox-gl-js version:1.13.1

Question

hello,I use addLayer to show some polygons,when change the polygon data,I want to use fitBounds to get better view,most time,it worked well,but sometimes,some area is out of bounds,I don't know why.Am i doing something wrong, or is there a bug in fitbounds?Here is my code: this.map = new mapboxgl.Map( { container:'map', style:...some style, zoom:6, pitch:60, bearing:0, center:[113.45,34,81], hash :false, renderWorldCopies:false } )

when change the data,I use fitBounds, here is the code let bbox = turf.bbox(mapData) this.map.fitBounds([[bbox[0],bbox[1]],[bbox[2],bbox[3]]])

looking forward to your reply,thank you.

sky0917 avatar Aug 16 '22 02:08 sky0917

Unfortunately there's no way to diagnose an issue like this without a reproducible live test case — bits of quoted code aren't enough, it could be any number of things. Please provide one for us to be able to help you, using JSFiddle or a similar tool.

mourner avatar Aug 16 '22 14:08 mourner

Unfortunately there's no way to diagnose an issue like this without a reproducible live test case — bits of quoted code aren't enough, it could be any number of things. Please provide one for us to be able to help you, using JSFiddle or a similar tool.

thanks for your reply,I can't visit JSFiddle,I use the CodePen,this is the link,https://codepen.io/skyzhen/pen/vYRQQod?editors=1010,when you click btn 'test1',it works well;but when click 'test2' to change data,some area will out of the bound

sky0917 avatar Aug 17 '22 03:08 sky0917

邮件已收到,谢谢!

sky0917 avatar Oct 11 '22 08:10 sky0917