cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Catalin_R
New Member

Canvas App Map component with GeoJSON

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Oyster
Frequent Visitor

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.

View solution in original post

7 REPLIES 7
Oyster
Frequent Visitor

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.

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.

 

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?

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

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.

Were you able to get LineString or MultiLineString working?

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

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (4,173)