Topic: Multi polygon can't Draw

I am using Unity application   I try to Draw multi polygon  but only  show last poly in array
This is my code


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MPolygon : MonoBehaviour
{

    public OnlineMaps map;  //
    public Texture2D markerTexture;
    public List<OnlineMapsMarker> markers = new List<OnlineMapsMarker>();//
    public OnlineMapsDrawingPoly polygon;//
    public List<OnlineMapsDrawingPoly> Polygon_S = new List<OnlineMapsDrawingPoly>();

    public List<Vector2> Polygon_LatLong;

    // Start is called before the first frame update
    void Start()
    {
     
        Vector2 cursorCoords;
        // Frist Poly
        Polygon_LatLong.Clear();
        Polygon_LatLong.Add(new Vector2(58.23256f, 23.59701f));
        Polygon_LatLong.Add(new Vector2(58.23246f, 23.59685f));
        Polygon_LatLong.Add(new Vector2(58.23221f, 23.59699f));
        Polygon_LatLong.Add(new Vector2(58.23231f, 23.59715f));

        polygon = new OnlineMapsDrawingPoly(Polygon_LatLong, Color.blue, 2, new Color(1, 1, 1, 0.3f));
        OnlineMapsDrawingElementManager.AddItem(polygon);
        //Polygon_S.Add(polygon);
        //OnlineMapsDrawingElementManager.AddItems(Polygon_S);

        ///'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        ///Second Poly
        Polygon_LatLong.Clear();
        Polygon_LatLong.Add(new Vector2(58.2326f, 23.59728f));
        Polygon_LatLong.Add(new Vector2(58.2326f, 23.59707f));
        Polygon_LatLong.Add(new Vector2(58.23256f, 23.59701f));
        Polygon_LatLong.Add(new Vector2(58.23231f, 23.59715f));
        Polygon_LatLong.Add(new Vector2(58.23231f, 23.59728f));

        polygon = new OnlineMapsDrawingPoly(Polygon_LatLong, Color.red, 2, new Color(1, 1, 1, 0.3f));
        OnlineMapsDrawingElementManager.AddItem(polygon);
        //Polygon_S.Add(polygon);
       // //OnlineMapsDrawingElementManager.AddItems(Polygon_S);



        Vector2 center = new Vector2(58.2326f, 23.59728f);
        int zoom = 10;
        OnlineMaps.instance.position = center;
        OnlineMaps.instance.zoom = zoom;
    }


My code is file attched

Please I need help Guys

Re: Multi polygon can't Draw

Hello.

The polygon and line store reference to original IEnumerable (in this case, the list) that you passed them.
You reuse the list, so you have two polygon with the same points, because both polygons refer to the same list.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Multi polygon can't Draw

Thanks for replay

I have  got your point ,but I need more clearance
your main should be make  every polygon  one array like this

    public OnlineMaps map;  //
    public Texture2D markerTexture;
    public List<OnlineMapsMarker> markers = new List<OnlineMapsMarker>();//
    public OnlineMapsDrawingPoly polygon;//
    public List<OnlineMapsDrawingPoly> Polygon_S = new List<OnlineMapsDrawingPoly>();

    public List<Vector2> Polygon_LatLong;
    public List<Vector2> Polygon_LatLong2;

       Polygon_LatLong.Add(new Vector2(58.23256f, 23.59701f));
        Polygon_LatLong.Add(new Vector2(58.23246f, 23.59685f));
        Polygon_LatLong.Add(new Vector2(58.23221f, 23.59699f));
        Polygon_LatLong.Add(new Vector2(58.23231f, 23.59715f));


        OnlineMaps api = OnlineMaps.instance;
        polygon = new OnlineMapsDrawingPoly(Polygon_LatLong, Color.blue, 2, new Color(1, 1, 1, 0.3f));
        OnlineMapsDrawingElementManager.AddItem(polygon);


        Polygon_LatLong2.Clear();
        Polygon_LatLong2.Add(new Vector2(58.2326f, 23.59728f));
        Polygon_LatLong2.Add(new Vector2(58.2326f, 23.59707f));
        Polygon_LatLong2.Add(new Vector2(58.23256f, 23.59701f));
        Polygon_LatLong2.Add(new Vector2(58.23231f, 23.59715f));
        Polygon_LatLong2.Add(new Vector2(58.23231f, 23.59728f));

        polygon = new OnlineMapsDrawingPoly(Polygon_LatLong2, Color.red, 2, new Color(1, 1, 1, 0.3f));
        OnlineMapsDrawingElementManager.AddItem(polygon);



but if  I have 1000  polygons how to deal with that
I try make  list in list but only draw only one Polygon

Re: Multi polygon can't Draw

Just create a new list for each polygon, or convert the list to an array:

polygon = new OnlineMapsDrawingPoly(Polygon_LatLong.ToArray(), Color.blue, 2, new Color(1, 1, 1, 0.3f));
Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Multi polygon can't Draw

Thanks thanks thanks alot
problem solve