Skip to first unread message
Assigned to ewpa...@gmail.com by farzeen....@gmail.com

UMR LISAH

unread,
Apr 4, 2018, 11:08:03 AM4/4/18
to MIT App Inventor Forum
Dear members,
I am actually trying to upload a FeatureCollection file in my map screen, but when uploading the file, it gives me only LineString with the same id: LineString1, LineString1, etc., and the PointsFromString boxes exhibited: [[],[],[]] (i.e. the lat long values are missing)


I tried to add quotes at each value, but without success. Here is the FeatureCollection file:

{"type":"FeatureCollection", "features": [
{"type":"Feature","geometry":{"type":"LineString","coordinates":[[43.4845,3.3209],[43.4846,3.3208],[43.4849,3.3207],[43.4852,3.3205],[43.4854,3.3204],[43.4856,3.3204],[43.486,3.3202],[43.4864,3.32]]},"properties":{"Id":173,"length":230.6,"comment":""}},
{"type":"Feature","geometry":{"type":"LineString","coordinates":[[43.4857,3.3202],[43.4857,3.3202],[43.4856,3.32],[43.4855,3.3195],[43.4863,3.3192],[43.4868,3.319]]},"properties":{"Id":212,"length":221.9,"comment":""}},
]}

If you have any idea of the problem?
Best regards

SteveJG

unread,
Apr 4, 2018, 11:28:30 AM4/4/18
to MIT App Inventor Forum
Here is a link to MIT's current Map tutorial which is  an intro tutorial on how the components work: https://drive.google.com/file/d/1LKnOihF9SdrKzOOQulFaP6vT1EQRz-5x/view?usp=sharing  

You need a GEOJSON file  (  http://geojson.org/ ) to manual code it.    Someone from MIT is going to have to explain how to use and confirm that the file used ias an extrnal feature file s actually compatible with the Map component.  There is no tutorial demonstrating this.

In order to get help with this, you might provide an example aia showing what you are trying to do.

The documentation for the Feature Collection is here 


Regards,
Steve

UMR LISAH

unread,
Apr 5, 2018, 3:14:48 AM4/5/18
to MIT App Inventor Forum
Dear Steve
Thank you very much for your answer. The enclosed tuto should greatly help me when I will succeed in uploading the geojson file.
Unfortunately, after reading all your comment, I cannot find the solution to my problem.
Considering your advice, I create a very simple aia file of the project, together with the geojson file (in .txt but it doesn't matter) and two print screens to better highlight the problem.
The FeatureCollection.txt file corresponds to the geojson features...

Best regards



TestMap.aia
After_upload.png
Before_upload.png
FeatureCollection.txt

SteveJG

unread,
Apr 5, 2018, 12:37:56 PM4/5/18
to MIT App Inventor Forum
I do not think anyone can specify a FeatureCollection using a file and directly import it to the app from a text file Umr.  MIT's documentation is vague.
There is either a bug that prevents importing a FeatureCollection this way or the file needs to be additionally processed with blocks in a complex operation and MIT has not provided any example. There does not seem to be a way to render a FeatureCollection using a json text file directly to the Map component.   Perhaps I am wrong; if there is a solution, the solution is not obvious from the documentation provided by MIT.

Here is an alternative way to display your trak information using two LineString components and the set LineString.PointsFromString block.  The base map must be reset using the set Map1.CenterFromString      (  latitude , longitude)  and an appropriate zoom value selected to ensure you see the display.

Perhaps this example will be useful.  Attached is an aia.  




Good luck with the MIT Map component.

One of the Wizards at MIT might comment on why a json FeatureCollection cannot be imported directly.  I believe the json must be broken 
down into a list of values that can be used to build the App Inventor required components.  How?  Only MIT knows.  Also,. there might be a bug that MIT is not aware of.


==============
Discussion about the FeatureCollection

An example provided by MIT I have renders a series of Markers using call Map.LoadFromUrl and then 
uses the  when Map1.GotFeatures to display the Markers renders the features on a Map.  Using various strategies, it was not possible to 
get a text file (rather than a url call) to do the same

I tried a few things unsuccessfuly.  The documentation implies the FeaturesFromGeoJSON block would work miracles

FeaturesFromGeoJSON
Populates the feature collection from a string containing GeoJSON content. Given the size of such strings, it is recommended to load the feature collection from assets or the web using the Source property.

Loading the identical geojson file provided as a link from  results in a Runtime error when I attempted to load from assets. So, no miracle.

==========================================

Regards,
Steve


TestMap (1).aia

Evan Patton

unread,
Apr 5, 2018, 5:05:02 PM4/5/18
to MIT App Inventor Forum
The fact that you are getting multiple LineStrings with the same name indicates a bug to me and I will file an issue.

Regarding loading of the content at runtime, you should be able to do the following:

1. Read the contents in using the File component
2. Use the Web component's JsonTextDecode method to convert the string into list-of-pairs representing the JSON content.
3. Use the "lookup in pairs" list block to retrieve the "features" property. Specify an empty list in the "not found" parameter.
4. Iterate over the list returned in 3 and use the Map's FeatureFromGeoJSON passing in the each entry to create the corresponding feature.

I may have some time to create a working example of this over the weekend, but the steps above should move you closer to your goal until I can fix the original issue.

Regards,
Evan

Evan Patton

unread,
Apr 5, 2018, 5:08:00 PM4/5/18
to MIT App Inventor Forum
This is filed as issue #1205.

Regards,
Evan
Message has been deleted

SteveJG

unread,
Apr 5, 2018, 6:17:13 PM4/5/18
to mitappinv...@googlegroups.com
@Evan   -  Welcome back.

Your procedures do allow loading of the pump.json file in your John Snow Cholera Map example without using the url.    Thanks for the work-around.  It works fine with Markers. Here are the blocks.

Step 1 is the file loading from assets (Button1).  This solution uses the code in Button3 to elicit steps 2,3 and 4 using the Procedudre.   The file takes time to load so this either needs to event handlers   or a Clock to create a small delay.  I chose two buttons for the example.



I'll see if I can provide a similar solution to Umr's attempt to use FeaturesCollection but uses LineStrings later this evening.  I might not get to it until Monday.

-- Steve

UMR LISAH

unread,
Apr 7, 2018, 11:48:10 AM4/7/18
to MIT App Inventor Forum
Dear all
I tried to follow the alternative way provided by Steve considering the PointsFromString procedure and a file gathering all coordinates of linestrings components (see attached screen capture), but I couldn't create a collection of a given number of linestrings. It looks possible for markers with "call Map1 Create.Marker" but not for linestrings, am I wrong?
If we could add this functionality for linestrings (also for polygons, let's be crazy), it would definitively remove the problem caused by the FeaturesFromGeoJSON procedure.
Best regards
Work_around_linestring_import.png

SteveJG

unread,
Apr 9, 2018, 10:59:45 AM4/9/18
to mitappinv...@googlegroups.com
Correct, with  markers you can  "call Map1 Create.Marker" but cannot do something similar for LineStrings 

Instead  why not create multiple  LineString objects at design time  Set the Visible to false and set it to true when you need them.  If you do that, you  can 
use a loop procedure to iterate through a text file that contains coordinates like these   (   [[43.4857,3.3202],[43.4857,3.3202],[43.4856,3.32],[43.4855,3.3195],[43.4863,3.3192],[43.4868,3.319]]\n[[43.4845,3.3209],[43.4846,3.3208],[43.4849,3.3207],[43.4852,3.3205],[43.4854,3.3204],[43.4856,3.3204],[43.486,3.3202],[43.4864,3.32]]    ) and populate the data in each LineString, set it Visible, then post each to your Map.  That should be relatively 'easy' to do with blocks.

Edit:  Code something like this for two traks  



Each trak is placed in quotes ("    ")  in a Text file like this  "[[43.4857,3.3202],[43.4857,3.3202],[43.4856,3.32],[43.4855,3.3195],[43.4863,3.3192],[43.4868,3.319]]","[[43.4845,3.3209],[43.4846,3.3208],[43.4849,3.3207],[43.4852,3.3205],[43.4854,3.3204],[43.4856,3.3204],[43.486,3.3202],[43.4864,3.32]]"    .  There are two LineString objects placed on the Map (LineString1 and LineString2)  

Add more LineString objects if you need to display more traks.  

Regards,
Steve


UMR LISAH

unread,
Apr 11, 2018, 6:37:02 AM4/11/18
to MIT App Inventor Forum
Dear Steve
The idea is interesting, but I need to automatize the creation of multiple LineStrings objects per se! Because I provided only three linestrings objects in my example, but my complete FeatureCollection gathers thoushands of linestrings!
Best regards

SteveJG

unread,
Apr 11, 2018, 9:03:48 AM4/11/18
to mitappinv...@googlegroups.com
Thousands?  Then expect significant performance issues.   Why?   

Map objects depends entirely on the osmdroid library to interface to OpenStreetMaps.  App Inventor 2  Map component is based on the osmdroid library so you should be aware of the limitations discussed below.   To use runtime LineString objects, MIT would have to add the capability to the LineString component.  At the moment, you can only add design time LineString objects.

-----------------------------------

How many icons can I put on the map?
The answer is greatly dependent on what hardware the osmdroid based app is running on. A Samsung S5 (no endorsement intended) ran just fine at 3k icons and was noticeably choppy at 6k icons. Your mileage may vary. X86 Android running on modern hardware will perform great at even higher numbers. However, it's recommended to limit the amount of stuff you're rendering, if at all possible.

If you're also drawing paths, lines, polygons, etc, then this also changes the equation. Drawing multipoint graphics is computationally more expensive and thus negatively affects performance under higher loads. To mitigate performance issues with multipoint graphics, one strategy would be to reduce the number of points handed off to the map engine when at a higher zoom level (numerically lower), then increase the fidelity as the user zoom's in. In effect, you would be clipping the visible data at the map view bounds so that the map view only "knows" about what's on screen and doesn't have to loop through all 10k icons that you want on the map. Although you can give the map view all 10k objects, but every time the map moves or zooms, it will iterate over all 10k items to calculate where to draw them (if at all). Using this mechanism paired with map motion listeners and a database query that supports geographic bounds, you can support a rich experience for users with lots of data and still have reasonable performance.
-------------------------------------------
Realistically, you may not ever be able to do exactly what you expect to do and have to redesign your app to display what is possible   One option might be  to reuse a single LineString  and use it to display all your tracks simultaneously   or  you could select and view only one of the thousands of traks at a time?    

You also might get very lucky and MIT discovers it is possible to add runtime LineStrings and provides them the next time they update the component or does something similar with FeatureCollection (your original question).   My experience with LineString is that a large linestring may crash the app.  I expect this happens because multipoint graphics use LOTS of memory and may use up all a device's system memory.  Just experiment and find out what works.

 Good luck Umr.

Regards,
Steve

Reply all
Reply to author
Forward
0 new messages