none
DrawingManager Polygon RRS feed

  • Question

  • We are using the DrawingManager to allow users to select polygon area of layer data.

    What is happening is that it is possible via the DrawingManager to draw a line using the polygon tool instead of a polygon which results in a set of 3 points where the 1st and 3rd are the same point as expected. This isn't a valid polygon. Can a check be added for this or should I just continue with my check below?

    I am currently using the following where instanceof is true regardless so had to add check on length of coordinate array.

               

    if(polygons[0] instanceofMicrosoft.Maps.Polygon && polygons[0].geometry.rings[0].x.length >= 4)

    Thanks

    Tuesday, November 21, 2017 6:45 PM

Answers

  • There is a Geometry validation function built into the spatial math module designed with SQL server in mind. Here is an example code block:

    var polygon = //Your polygon.
    
    Microsoft.Maps.loadModule('Microsoft.Maps.SpatialMath', function () {
    
        polygon = Microsoft.Maps.SpatialMath.Geometry.makeValid(polygon);        
        
        //Do something with the polygon.
    });

    Documentation on the spatial math module can be found here: https://msdn.microsoft.com/en-us/library/mt712834.aspx

    We don't automatically validate polygons in the drawing tools as there is many users/applications that don't care about the polygon being valid as long as it looks the way they want it.


    [Blog] [twitter] [LinkedIn]

    Tuesday, November 21, 2017 9:14 PM

All replies

  • One additional note. If submitting the data from Drawing Manager to SQL Server be mindful of orientation of points. We had an issue a while back because SQL Server requires polygon points to be ordered in specific directions (outer/inner rings).

    The Drawing Manager doesn't care which direction the user draws the polygon so we had to add check in the back end by area (we are limited to North America so this works) and if needed, reorient the spatial object before using it in the layer query.

    Tuesday, November 21, 2017 7:34 PM
  • There is a Geometry validation function built into the spatial math module designed with SQL server in mind. Here is an example code block:

    var polygon = //Your polygon.
    
    Microsoft.Maps.loadModule('Microsoft.Maps.SpatialMath', function () {
    
        polygon = Microsoft.Maps.SpatialMath.Geometry.makeValid(polygon);        
        
        //Do something with the polygon.
    });

    Documentation on the spatial math module can be found here: https://msdn.microsoft.com/en-us/library/mt712834.aspx

    We don't automatically validate polygons in the drawing tools as there is many users/applications that don't care about the polygon being valid as long as it looks the way they want it.


    [Blog] [twitter] [LinkedIn]

    Tuesday, November 21, 2017 9:14 PM
  • Thanks for the quick response! I hadn't looked far enough into that module yet. Thanks again!
    Tuesday, November 21, 2017 11:33 PM