Select to view content in your preferred language

Assigning an occupant to a Unit in Custom Space Planner Application

336
0
01-04-2024 03:13 AM
AbhyanshuGupta
New Contributor III

Hi,

I have created a custom space planner app using the ArcGIS JS library. Now when I am trying to assign an occupant to a particular Unit i am able to do it, but i am facing one issue. As we require a point location (i.e x and y coordinates) which we can then assign the occupants geometry to that particular location, for the unit layers feature since the units feature geometry is stored as polygon, hence instead of having a single point, i am getting a collection of points called 'rings' which define the boundary of the unit features polygon. Now to assign the location of the unit to the occupant i have calculated the center of all the points in the rings field but the label is not coming in the exact center of the unit.

Is there any other way i can achieve this?

This the code code i've used for calculating the center of the Unit features point Ring: 

 const calculateCenter=(screenPoints)=>{
    var totalX = 0;
    var totalY = 0;

    screenPoints.forEach(screenPoint => {
    totalX += screenPoint[0];
    totalY += screenPoint[1];    
    });

    const averageX = totalX / screenPoints.length;
    const averageY = totalY / screenPoints.length;
    console.log('Average X:', averageX);
    console.log('Average Y:', averageY);
    return [averageX,averageY];
  }
3.png
0 Kudos
0 Replies