Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[iOS] Distorted polygons at certain zoom level #3260

Closed
BFTE opened this issue Dec 11, 2015 · 14 comments
Closed

[iOS] Distorted polygons at certain zoom level #3260

BFTE opened this issue Dec 11, 2015 · 14 comments
Labels
archived Archived because of inactivity Core The cross-platform C++ core, aka mbgl

Comments

@BFTE
Copy link

BFTE commented Dec 11, 2015

Below some zoom level I add to map view set of MGLPolygon objects (sometimes more than 50) with correct GeoJSON. Everything works great until I start zooming in/out. At certain zoom level some polygons are getting distorted, when I zoom out polygons back to correct shape. I did screenshots for better understanding. It does not happen every time when I zoom in, but sometimes and I have no idea what is the reason of this behaviour.

To add polygons to map I use map view methods (on both there is the same problem):
addAnnotataions: or addOverlays:

Using latest sdk release: ios-v3.0.1, but in earlier versions this problem also occurs.

Thanks!

polygon-distort

polygon-distort-big

polygon-correct-big

@jfirebaugh
Copy link
Contributor

Can you provide the coordinates for one of these examples?

@BFTE
Copy link
Author

BFTE commented Dec 11, 2015

Sure, for the second one (lat, long):
(42.656797, -73.763816),
(42.654142, -73.766568),
(42.654698, -73.767577),
(42.654556, -73.767748),
(42.653984, -73.766778),
(42.652931, -73.767700),
(42.652509, -73.766981),
(42.656529, -73.763216),
(42.656797, -73.763816)

@kkaefer
Copy link
Member

kkaefer commented Dec 14, 2015

/cc @mourner

@mourner
Copy link
Member

mourner commented Dec 14, 2015

@kkaefer earcut is not merged into master yet, so this must be libtess/clipper-related, right?

@jfirebaugh
Copy link
Contributor

Or geojson-vt-cpp related.

@mourner
Copy link
Member

mourner commented Dec 14, 2015

For the record, these coords work fine on GL JS. Now need to dig into native...

@mourner
Copy link
Member

mourner commented Dec 14, 2015

GeoJSON-VT C++ debug viz also seems fine on these coordinates.

@BFTE
Copy link
Author

BFTE commented Dec 14, 2015

It's hard to reproduce in a clear way and give you some path. Maybe more details will be helpful. In my case map view has many filled polygons. Usually there is one big polygon which represents some kind of city area. Inside that polygon are placed smallest polygons like the ones I presented above. Above certain zoom level inner polygons are OK, but when I zoom in, some of them changes their shape like in attached screens. It does not occur always to the specific polygon; sometimes everything is OK, sometimes not.

I'm not sure if this is related issue, but I also got this crash very often: #2926

@mourner
Copy link
Member

mourner commented Dec 14, 2015

Interesting. @BFTE does the same thing (plus the crash) happen with the master version of mapbox-gl-native?

@BFTE
Copy link
Author

BFTE commented Dec 15, 2015

I could not check, I got some errors building static lib from sources (e81f3f3) using make ipackage:
make: *** [ipackage] Error 65

CompileC build/mbgl.build/Release-iphoneos/platform-ios.build/Objects-normal/arm64/async_task.o /../MapboxLib/mapbox-gl-native/platform/default/async_task.cpp normal arm64 c++ com.apple.compilers.llvm.clang.1_0.compiler
CompileC build/mbgl.build/Release-iphoneos/platform-ios.build/Objects-normal/arm64/timer.o /../MapboxLib/mapbox-gl-native/platform/default/timer.cpp normal arm64 c++ com.apple.compilers.llvm.clang.1_0.compiler
CompileC build/mbgl.build/Release-iphoneos/platform-ios.build/Objects-normal/arm64/run_loop.o /../MapboxLib/mapbox-gl-native/platform/default/run_loop.cpp normal arm64 c++ com.apple.compilers.llvm.clang.1_0.compiler
...
Libtool build/mbgl.build/Release-iphoneos/platform-ios.build/Objects-normal/arm64/libmbgl-platform-ios.a normal arm64
Libtool build/mbgl.build/Release-iphoneos/platform-ios.build/Objects-normal/armv7/libmbgl-platform-ios.a normal armv7
Libtool build/mbgl.build/Release-iphoneos/platform-ios.build/Objects-normal/armv7s/libmbgl-platform-ios.a normal armv7s
CreateUniversalBinary build/Release-iphoneos/libmbgl-platform-ios.a normal arm64\ armv7\ armv7s
Strip build/Release-iphoneos/libmbgl-platform-ios.a

@BFTE
Copy link
Author

BFTE commented Jan 26, 2016

Hi, still getting this issue when zooming in ios-v3.1.0-pre.1 (556690f), dynamic framework linked:

hub-area-issue-3 1 0

@ygweric
Copy link

ygweric commented Jul 7, 2016

I meet the same bug and find get the solution in the end.

How to reproduce

In swift my project, I store the polygon point array in a array shape of Class Paddock, create the MGLPolygon with following code :

let pointer: UnsafeMutablePointer<CLLocationCoordinate2D> = UnsafeMutablePointer(paddock.shape)
let polygon = MGLPolygon(coordinates: pointer, count: UInt(paddock.shape.count))

convert array to UnsafeMutablePointer, and past them to the MGLPolygon, then there is always distorted polygon .

How to fix it

First way: create a new array and cope the original array to the new array, so we can use the new array as the official demo

var coordinates = [CLLocationCoordinate2D]()        
for point in paddock.shape {
    coordinates.append(point)
}
let polygon = MGLPolygon(coordinates: &coordinates, count: UInt(paddock.shape.count))

Second way: in the array of our class, add setter and getter, so we can pass our array to the MGLPolygon directly.

why

It is special about the UnsafeMutablePointer, so I think I can't convert array to UnsafeMutablePointer directly in this case.

Anyone know that is way detailed?

@JacobJT
Copy link

JacobJT commented Feb 27, 2018

#3074 seems to have been the issue for me - I was not closing my paths. Odd how it appears to work fine.. I do notice the documentation says that a polygon is a closed path, but the data I had used with Google Maps to create polygons didn't have the repeated coordinate at the end, and when I started displaying polygons it worked fine without checking for it / adding it in. I might update documentation to reflect that a closed path is a requirement or behavior may be undefined.

@stale
Copy link

stale bot commented Oct 27, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the archived Archived because of inactivity label Oct 27, 2018
@kkaefer kkaefer closed this as completed Nov 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived Archived because of inactivity Core The cross-platform C++ core, aka mbgl
Projects
None yet
Development

No branches or pull requests

7 participants