Bug with Polygon in Map component

Hello,

Is there a bug in Polygon component?

I need to get the coordinates of the vertices when the polygon changes position.

I touch the red polygon (for 2 seconds) and drag them, I get an error if I want to get the new points of the vertices.

Regards.
map_polygon.aia (2.1 KB)

You get this error i guess after dragging the polygon.

The polygon vertices should be defined at the end of the drag. This seems like a bug to me that it’s not. It’s now issue #1897.

1 Like

And now a corresponding pull request to fix the issue:

2 Likes

Thanks Evan, another question, please.

If I use Polygon1.Points to draw a polygon with “list of list”, it works … (Button1)

… but if I use Polygon1.Points with make a list (latitude longitude) clockwise, it doesn’t work. I get the error: “Invalid type String. Expected list.” (Button2)

make a list = (37.3558730222643 -5.981843233239488) (37.35677017922074 -5.982375383246109) (37.35704137088585 -5.981568574643461) (37.35618003489012 -5.98103213349532)


Regards.
Mapa_Polygono_2.aia (3.4 KB)

This is an issue with the type coercion only going one level deep. The Points property expects either numbers or a list (in the case of a multipolygon). Easy fix would be to substitute your text values for numerical values, but for convenience I can also make the casts internally.

After actually testing your app I realize I totally misunderstood what you were asking. Sorry about that. My original comment above is wrong and after checking the code it indeed does the right thing for Button1. Yes, the code for Button2 is wrong because it’s expecting the points as actually pairs (2-element lists). Your code is creating a list with a single very long string. The make a list block won’t convert a list-like string representation into a list–it just makes a list with the string as its sole element. If you wanted to write the points out, you’d want to use a list to csv table and list from csv table block to convert to/from string representation.

Thanks Evan, now it works.

I misunderstood the help about Points.
http://ai2.appinventor.mit.edu/reference/components/maps.html#Polygon
Points
Sets or gets the list of points that comprise the polygon. Points are given as (Latitude Longitude) pairs and should be given clockwise.

Now I build the list by: (Button2)

list from csv table text 37.3558730222643,-5.981843233239488\n37.35677017922074,-5.982375383246109\n37.35704137088585,-5.981568574643461\n37.35618003489012,-5.98103213349532\n

Regards.
Mapa_Polygono_3.aia (3.5 KB)

1 Like