Dessiner n polygones dans une Map

49 views
Skip to first unread message
Assigned to ewpa...@gmail.com by steve....@gmail.com

franck PERRET

unread,
Nov 2, 2019, 8:16:52 AM11/2/19
to MIT App Inventor Forum
Dans une Map je veux dessiner entre 1 et n polygones.
Je ne sais pas au départ combien il y a de polygones dans la liste.

Les coordonnées des sommets des  polygones sont placées dans une liste de la forme [[45.91635,6.67025],[45.91742,6.69222],[45.90655,6.67076]]

Comment faire pour ajouter dynamiquement  un nouveau polygone dans une Map?

Merci

SteveJG

unread,
Nov 2, 2019, 9:45:53 AM11/2/19
to mitappinv...@googlegroups.com
I believe it might be impossible to create a Polygon dynamically Franck.  The only Map component that can be created dynamically is a Marker.  Markers can also be created dynamically using the CreateMarker method and configured using the "Any Component" blocks.    There is no CreatePolygon Block.

Map components  describes what a developer can do with the existing Map Blocks. 

Developers cannot add new polygons, the Polygons must already exist on the map to use them.  Drag several Polygons on to the Map.   You can modify the coordinates of existing Polygons.  Place several design time Polygons on the Map, hide them (Polygon.Visible=false)and then assign coordinates to them using   set Polygon1.PointsFrom string     , Polygon2.PointsFromString   as may be required and then Polygon1.Visible=true   Polygon2.Visible = true.   Or, similarly using Polygon1.Points etc.

Points
Sets or gets the list of points that comprise the polygon. Points are given as (Latitude Longitude) pairs and should be given clockwise.
PointsFromString
Sets the list of points from a string in GeoJSON format.

Have you tried that?

Another way to 'add' Polygons might be to include them in a FeatureCollection.  This is more complicated.  Modify the contents of a FeatureCollection using a GEOJSON file.   Perhaps
 Features
Sets or gets a list of features present on the Map. Setting this to an empty list will clear the Map.
or using the AnyComponent version


What you end up doing depends on what your app is supposed to do and why you need dynamic polygons.

The first method works fine.  I have used the second method to modify a FeatureCollection but not one containing Polygons.   Do some experimenting and let us know if you are successful.  You can create dynamic Polygons by using the FeatureCollection1.FeaturesFromGeoJSON block.   I'll try to post an example later today.


Regards,
Steve

Juan Antonio

unread,
Nov 2, 2019, 11:38:48 AM11/2/19
to mitappinv...@googlegroups.com
As Steve wrote...

poligono4.png




Mapa_Polygono.aia

SteveJG

unread,
Nov 2, 2019, 5:00:11 PM11/2/19
to MIT App Inventor Forum
Juan Antonio shows a neat simple example on how you could design your app. It might be all you need Franck.  You might like to experiment with other ways.

I discovered it is possible to create a 'dynamic' polygon.  Use the FeatureCollection FeaturesFromGeoJSON block, setting it to a geojson. I just dragged and dropped the geojson into a Text block.  You can use several methods to populate the FeatureCollection.  Drag and drop is simple. The Polygons created with the FeatureCollection cannot be hidden once created. Design time Polygons can be visible or hidden. 

FCplayground2.png




 The FeatureCollection.Visible = false  has a bug and will not hide these FeatureCollection polygons.  

FCruntimeError.PNG

I tried setting the FC to an 'empty' geojson; 
{
  "type": "FeatureCollection",
  "features": []
}

as a work around to try to erase the FeatureCollection.  Setting to an empty geojson adds to the existing FeatureCollection geojson. It does 
not 'erase' the existing FeatureCollection.

An app to play with
The attached aia creates a Polygon playground for experimentation.  Polygon1 and Polygon2 are two default design time polygons.  The two elaborate polygons are created using the online 
geojson.io  to create geojson files using the Fuschia circled tool.  Create the polygon, then copy the generated geojson script to the right into your app.

FCPolygonGeoJSON.PNG


  Button 6 (Other) contains various disabled strategies I experimented with to try to 'erase' an existing FeatureCollection image on the Map.  None of them worked for me.

FCplaygroundBlocks.PNG



The app Buttons

Original Coordinates places a design time polygon, Polygon1
Modified Coordinates changes the 'Original'polygon boundaries
Hide/Show hides and shows Polygon1 and Polygon2.
Color toggles Polygon2 color
FC spawns a red polygon using a geojson script in a FeatureCollection call.
FC2 spawns a red star polygon as FC the same way.

Click on the star polygon or the red other large red polygon in the Map;  the runtime component name appears in Label1.  However,
that run time component name sadly does not work in the FeatureCollection any component Block  component puzzle piece (another bug??)

Experiment
Go play with this stuff.  Something here might help you build your app.

Anyone have any ideas about how to hide the FeatureCollection?

Regards,
Steve

MultipleMapPolygon.aia

Premiere Sapat

unread,
Nov 3, 2019, 2:34:10 PM11/3/19
to MIT App Inventor Forum
Merci Beaucoup pour ton fichier

Je l ai bien regardé et c est très bien

C est exactement ce que je veux faire.

peux tu faire une version plus simple avec juste une liste contenant les coordonnées des sommets

[[45.90328,6.6863],[45.90309,6.68749],[45.90227,6.68743],[45.90129,6.68681],[45.90129,6.68527],[45.90304,6.68491]]

transformer cette liste en geojson pour les mettre dans un FeatureCollection

Faire ca avec un ploygone puis avec plusieurs

Merci


SteveJG

unread,
Nov 3, 2019, 2:48:33 PM11/3/19
to MIT App Inventor Forum
I can tell you how you might be able to do it.

Here is the 'star' polygon geojson script:


{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -71.10969543457031,
              42.397600949012876
            ],
            [
              -71.11106872558594,
              42.39557261051849
            ],
            [
              -71.1309814453125,
              42.37883631647602
            ],
            [
              -71.11450195312499,
              42.38086519582321
            ],
            [
              -71.09527587890625,
              42.386951440524854
            ],
            [
              -71.08497619628906,
              42.379850764344134
            ],
            [
              -71.07742309570312,
              42.39050147746088
            ],
            [
              -71.06849670410156,
              42.40064333382955
            ],
            [
              -71.09321594238281,
              42.40267150842343
            ],
            [
              -71.10145568847656,
              42.430552260619564
            ],
            [
              -71.10969543457031,
              42.397600949012876
            ]
          ]
        ]
      }
    }
  ]
}


This might work (I simply replace the coordinates with your coordinates in the script)


{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [
 [[45.90328,6.6863], [45.90309,6.68749], [45.90227,6.68743], [45.90129,6.68681], [45.90129,6.68527], [45.90304,6.68491]]
        ]
      }
    }
  ]
}


Does the 'converted' geojson FeatureCollection work?   I certainly do not know.  Why not test it in your app Franck?  What happens?

If not, go to the geojson.io web page and create the coordinates there using the Polygon tool at that site.

-- Steve
Message has been deleted

franck PERRET

unread,
Nov 3, 2019, 4:40:17 PM11/3/19
to MIT App Inventor Forum
Dans cette application
1) je centre la carte sur ma position
2) je dessine des polygones en tapant sur la carte.
3) je fini les polygones (pour les fermer)
4) j enregistre les polygones dans un fichier Google Sheets
(j'ai vidé le ficher pour que vous puissiez y mettre vos polygones)

5) je peux lire les polygone enregistrés dans le fichier Google Sheets

6) Le bouton "Dessiner tout les polygones" doit prendre tout les polygones dans la liste "ListeDesPolygones"
C'est cette étape que je n'arrive pas a faire.

Merci

Franck
Carte2(1).aia
Reply all
Reply to author
Forward
0 new messages