nativescript-mapbox icon indicating copy to clipboard operation
nativescript-mapbox copied to clipboard

Remove all polygons/polylines don't work on iOS

Open AntoineBouquet opened this issue 6 years ago • 1 comments

Hello,

I was trying to draw on the map some one polygon and some polylines following the user walk and I needed to create my own method to refresh these. Concretly, this method consist to remove all polygon/polylines and after recreate these.

So I use something like for the polygon

this.mapbox.removePolygons().then(() => {
    return this.mapbox.addPolygon({
        id: 1
        fillColor: new Color(color),
        fillOpacity: 0.7,
        // stroke-related properties are only effective on iOS
        strokeWidth: 0,
        points: coords
    })
})

removePolygons() without parameter works on Android, but on iOS it does not remove any polygon. The workaround for this is to give an id at the creation of each polygon/polylines, and add this identifier in the method parameters.

Could it be improved in future release ?

PS : If i give the identifier "0" to my polygon or polyline, it does not create the object with the ID 0 in iOS, but with an unique ID based on the current time. Need to be improved too ?

Thanks in advance, Antoine

AntoineBouquet avatar Feb 01 '19 16:02 AntoineBouquet

@AntoineBouquet Hey I have encountered the same issue. After debugging for a while I think I might find the cause of that. You have to set the polyline id any number other than 0. I looked into the source code, when a polyline is added, this code will be excused var polylineID = "polyline_" + (options.id || new Date().getTime()); If the id is 0, it will just bypass options.id and create a new id with new Date().getTime(). I changed the id to other numbers and it worked for me. I don't know why it works on Android but not IOS though.

shujingl avatar Nov 12 '19 18:11 shujingl