Merge Polygons in JavaScript API 4.14

2051
4
Jump to solution
02-03-2020 06:08 PM
MikeV
by
New Contributor II

I have several polygons that I'd like not to overlap on the map at the points that they merge at. If I have separate latitude/longitude coordinate sets for all the polygons, how can I accomplish this? In the image below, I want the two circles filled in but not overlapping.

 

0 Kudos
1 Solution

Accepted Solutions
LeoLiu1
Occasional Contributor

Can you try this:

make sure spatialReference is set for each polygon json, for example:.

var polygon = { type: "polygon", rings: paths, "spatialReference": {"wkid": 4326} };

And then make sure array's type is polygon: 

polygons.push(new Polygon(polygon));

If the above doesn't work, can you please share more pieces of codes with a screen shot of the error from your browser's console?

View solution in original post

4 Replies
LeoLiu1
Occasional Contributor
0 Kudos
MikeV
by
New Contributor II

I'm trying to use geometryEngine.union() with no success. I have several polygons defined like this where paths is an array of lat/long coordinates:

var polygon = { type: "polygon", rings: paths };

I then push each polygon into an array like this:

polygons.push(polygon);

At that point I use

var joinedPolygons = geometryEngine.union(polygons);

The API then throws an error that 'd is undefined'. What am I doing wrong?

0 Kudos
LeoLiu1
Occasional Contributor

Can you try this:

make sure spatialReference is set for each polygon json, for example:.

var polygon = { type: "polygon", rings: paths, "spatialReference": {"wkid": 4326} };

And then make sure array's type is polygon: 

polygons.push(new Polygon(polygon));

If the above doesn't work, can you please share more pieces of codes with a screen shot of the error from your browser's console?

MikeV
by
New Contributor II

Thanks, geometryEngine.union() works with your advice. The explicit cast to a Polygon before pushing it into my array is what was missing in my code.

0 Kudos