c# - Xamarin iOS - AddOverlays() only adding first polygon -
i following this tutorial adding polygons onto map in xamarin. implementing ios section of tutorial, because want add multiple polygons map instead of single polygon shown in tutorial, using addoverlays()
function takes in array of imkoverlay
objects, instead of addoverlay()
function takes 1 imkoverlay
object.
for reason of polygons being plotted @ same coordinates first polygon in list, similar issue this person had!
here code:
void addpolygonstomap() { overlaylist = new list<imkoverlay>(); (int = 0; < polygons.count; i++) { cllocationcoordinate2d[] coords = new cllocationcoordinate2d[polygons[i].count]; int index=0; foreach (var position in polygons[i]) { coords[index] = new cllocationcoordinate2d(position.latitude, position.longitude); index++; } var blockoverlay = mkpolygon.fromcoordinates(coords); overlaylist.add(blockoverlay); } imkoverlay[] imko = overlaylist.toarray(); nativemap.addoverlays(imko); }
you have edit code in mkoverlayrenderer getoverlayrenderer(mkmapview mapview, imkoverlay overlaywrapper)
in tutorial. remove if
statement or remove polygonrenderer == null &&
in if
statement, this:
mkoverlayrenderer getoverlayrenderer(mkmapview mapview, imkoverlay overlaywrapper) { if (!equals(overlaywrapper, null)) { var overlay = runtime.getnsobject(overlaywrapper.handle) imkoverlay; polygonrenderer = new mkpolygonrenderer(overlay mkpolygon) { fillcolor = uicolor.red, strokecolor = uicolor.blue, alpha = 0.4f, linewidth = 9 }; } return polygonrenderer; }
otherwise, return first polygonrenderer
including first coordinates group.
Comments
Post a Comment