web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Canvas App Map compone...
Power Apps
Answered

Canvas App Map component with GeoJSON

(1) ShareShare
ReportReport
Posted on by 5

I'm working on a Canvas App that uses the Map component combined with the Address Input component to locate an address on a map and update a record with all the address components. So far so good.
The second requirement that I have is to draw custom areas on the map based on GeoJSON data and check if the given address is inside any of the areas. The Map component seems to support drawing shapes since there are several fields in the 'Advanced' tab that reference custom shapes (see screenshot). The problem is that I can't find any information regarding how to input/format the data. The documentation for the Map component doesn't even mention these fields. I'm assuming its farely new. 

So far I've tried simply inputing some GeoJSON data directly into the fields with no luck. No errors given, but nothing happens. Here is my GeoJSON:

 

{
 type: "Feature"; 
 properties: { Id: "01"; Name: "Test" };
 geometry: {
 type: "Polygon"; 
 coordinates: [
 [
 [ -3,70256; 40,4165 ];
 [ 121,45806; 31,22222 ];
 [ 15,28318; -4,26613 ]
 ]
 ]
 }
}

 

 

Can anyone point me in the right direction?

Categories:
I have the same question (0)
  • Verified answer
    Oyster Profile Picture
    31 on at

    Ok, i tihnk i figured it out, I was just about to post this issue myself when I thought I'd give it another try. The key is that the Map is looking for a table the same way it does with pin items. You have to point to Shape_items property to the table, the ShapeGeoJSONObjects to the column in that table for the geojson, and the ShapeLabels to the label column. for example, to get a square on the map:
    first i used a button to build the table like this:

    ClearCollect(JSONTable,{Label:"Test",GeoJSON:"{
     "&Char(34)&"type"&Char(34)&": "&Char(34)&"Feature"&Char(34)&",
     "&Char(34)&"properties"&Char(34)&": {
     "&Char(34)&"subType"&Char(34)&": "&Char(34)&"Rectangle"&Char(34)&",
     "&Char(34)&"label"&Char(34)&": "&Char(34)&"Test"&Char(34)&"
     },
     "&Char(34)&"geometry"&Char(34)&": {
     "&Char(34)&"type"&Char(34)&": "&Char(34)&"Polygon"&Char(34)&",
     "&Char(34)&"coordinates"&Char(34)&": [
     [
     [
     -122.15157507933301,
     47.654932139261234
     ],
     [
     -122.11741446531913,
     47.654932139261234
     ],
     [
     -122.11741446531913,
     47.62555383689849
     ],
     [
     -122.15157507933301,
     47.62555383689849
     ],
     [
     -122.15157507933301,
     47.654932139261234
     ]
     ]
     ]
     }
    }"})

    As you can see, the text has to use double quotes, so you'll have to use the char function to get the quotes in there. I then set the maps properties like this:
    Shapes_Items = JSONTable
    ShapesGeoJSONObjects = JSONTable.GeoJSON

    ShapesLabels = JSONTable.Label

    the map displays this:
    Screenshot 2021-02-26 121825.jpg

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    I only just barely got this to work, as I'm trying to get a map to display a rather large set of polygons. I tried your geojson and it gave me an error saying it cold not be displayed, you may need to tweak it to get it to a format it's expecting. I'll keep working on figuring out to rules to this control, but hopefully this gets you somewhere.

  • worklist Profile Picture
    9 on at

    Thanks for this!

    Was wondering if you've had any luck with LineString type shapes, rather than polygons.  

    I've been able to get it to work for polygons, based on your comments, but not for simple lines.

     

  • aerojean Profile Picture
    66 on at

    I'm also trying to get lines drawn and Power Apps appears not to support all GeoJson Geometry object types. The only figures I've been able to get to show are Polygon or MultiPolygon. You can use MultiPolygon geometry type for multiple unconnected lines, which is what I'm doing.

     

    I'm now trying to change the line width of the lines drawn because they're too thin and difficult to see. Do you know if there is any way to change line weight?

  • pjdiii Profile Picture
    30 on at

    Did you ever figure out a solution? I'm having the same issue.

  • aerojean Profile Picture
    66 on at

    I was never able to change the line width. What I did was create a polygon rectangle that was thin enough to look like a line and fill it with a color.

  • pjdiii Profile Picture
    30 on at

    Were you able to get LineString or MultiLineString working?

  • aerojean Profile Picture
    66 on at

    I was not able to. It doesn't seem to support all GeoJson geometry objects. It's why I had to resort to workarounds.

  • Ethan_Power Profile Picture
    115 on at

    Microsoft probably updated the Map component since you first asked, but LineString type GeoJSON works for me. 

    Here is the GeoJSON code that I used:

    {
     "type": "FeatureCollection",
     "name": "Alpha Locations (Polyline Linestring)",
     "crs": {
     "type": "name",
     "properties": {
     "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
     }
     },
     "features": [
     {
     "type": "Feature",
     "properties": {
     "Name": "Polyline Linestring"
     },
     "geometry": {
     "type": "LineString",
     "coordinates": [
     [-98.941861480100002, 29.898518744499999],
     [-98.941995597299993, 29.898624027299999],
     [-98.942111800600003, 29.898749628],
     [-98.942853212299994, 29.8994047851],
     [-98.991993728, 29.900564107499999]
     ]
     }
     }
     ]
    }

     

  • pjdiii Profile Picture
    30 on at

    Thanks I did get it to work with LineString. My GEOJson had to be dynamic. So I came up with using a variable as a template and then substituting the properties.. In addition, I had a requirement to put a Label 1/2 way between the points. 

    Set(GeoLineTemplate,"{
     ""type"": ""Feature"",
     ""properties"": {
     ""_azureMapsShapeId"": ""THEGUID"",
     ""selected"": true
     },
     ""id"": ""THEGUID"",
     ""geometry"": {
     ""type"": ""LineString"",
     ""coordinates"": [
     [
     POINTA_LONG,
     POINTA_LAT
     ],
     [
     POINTB_LONG,
     POINTB_LAT ]
     ]
     }

     

     ForAll(data As LD,
     Collect(JSONTable,
     {
     Label: LD.Label,
     Shape_Name: ".",
     Shape_GeoJSON: 
     Substitute(
     Substitute(
     Substitute(
     Substitute( 
     Substitute(GeoLineTemplate, "POINTA_LONG", LD.Longitude),
     "POINTA_LAT", LD.Latitude
     ),
     "POINTB_LONG", LD.EndLongitude
     ),
     "POINTB_LAT", LD.EndLatitude
     ),
     "THEGUID", GUID()
     )
     }); // end of collect()
    
     Collect(JSONTable,
     {
     Label: LD.Label,
     Shape_Name: LD.Distance &"' " & LookUp(localCollection, ID=LD.id).Title,
     Shape_GeoJSON: 
     Substitute(
     Substitute(
     Substitute(
     Substitute( 
     Substitute(GeoLineTemplate, "POINTA_LONG", (LD.Longitude+LD.EndLongitude)/2),
     "POINTA_LAT", (LD.Latitude+LD.EndLatitude)/2
     ),
     "POINTB_LONG", (LD.Longitude+LD.Longitude)/2
     ),
     "POINTB_LAT", (LD.Latitude+LD.Latitude)/2
     ),
     "THEGUID", GUID()
     )
     });//end of collect
     ); // end of ForAll

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard