Select to view content in your preferred language

Can we create our own toScreen method?

352
3
04-25-2023 08:38 AM
PrashantR
New Contributor III

I am using toScreen method of map to convert the map points into screen points, which are then used to calculate the extents of a graphic drawn in the graphic layer in screen points. These screen points changes every time we move the map or zoom in/out. I have to recalculate the screen points again every time map is moved to keep the extents updated. 

My goal is to keep track of map extents in screen points of each graphic drawn. But the recalculation takes a lot of time if the number of graphics are high. So I am trying to make use of web workers to do the calculation but can't use the same toScreen method in web worker. 

Can we create our own toScreen method that can be added in web worker to do the calculation in seperate thread? I just need to understand how the screen points are calculated in map.

0 Kudos
3 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

Can you please tell me what are you trying to do by achieving what you described above? Only asking because there may an easier solution. 

 

Thanks,

 

0 Kudos
PrashantR
New Contributor III

Hi @UndralBatsukh ,

Thanks for the response!

Let me elaborate on what I am exactly trying to do.

I have a graphics layer and I want to draw graphics in such a way that it does not overlap any other existing graphic.  I am able to do it by calculating the extents of each graphic in screen points and then check for any intersection with existing extents while drawing the new graphic. This way I am able to try multiple positions for the graphic to draw and use the position where there is no overlap.

This works fine but the only issue is that it is very expensive to recalculate the screen points every time user moves the map  as the screenpoints changes. So everytime I have to recalculate the extents for each graphic. I also want to add a feature where if I zoom in then I would like to redraw the entire graphic layer without any overlapping graphics, this also takes at least 3-4 seconds and it block the UI.

To keep the UI responsive, I thought of using web workers to  do the calculation. But we can't access the toScreen(Or any method from main thread) in web worker as it is a seperate thread and does not have access to DOM & window object. 

So I was wondering if we could create our own toScreen method in web worker that does the exact same this as MapView's toScreen method that would do it. 

Do you think this is possible? Or any other solution that can help me here...?

Thanks again for the help!

 

0 Kudos
UndralBatsukh
Esri Regular Contributor

Hi there, 

Please take a look at this codepen as this shows how to transform map points to screen points:  https://codepen.io/ycabon/pen/ExdXXjP?editors=0011 

0 Kudos