1 (edited by mcb 2021-09-14 17:57:00)

Topic: [SOLVED] Drawing a square from top left and bottom right coords?

I just wanted to see if there was a method I was missing, or maybe if you knew of a good way that I could draw a square on the map based on top left and bottom right coordinates?

I figured I could try to find the center point between them and draw a square, but then how do I figure out the scale so the square stops are the coordinates?

or maybe you have a better approach?

Thanks in advance

Re: [SOLVED] Drawing a square from top left and bottom right coords?

Hello.

There are many ways to do this for example OnlineMapsDrawingRect + OnlineMaps.GetCorners.
https://infinity-code.com/doxygen/onlin … gRect.html
https://infinity-code.com/doxygen/onlin … d91edd9f1c

The best way depends a lot on what this square is for.

Kind Regards,
Infinity Code Team.

uContext is Editor PowerPack (more than 50 tools) that take your workflow in Unity Editor to a next level, simplifies working with content, adds new features, corrects and improves the editor’s built-in behaviors. Click here to download uContext Basic for free.

3 (edited by mcb 2021-09-13 17:26:41)

Re: [SOLVED] Drawing a square from top left and bottom right coords?

Thanks for the response.

Basically, I'm going to draw a square and make it clickable, and allow the user to easily jump to this location. 
There could be several of these squares drawn at once.

I have a simple 2d map that will serve as a context map of sorts, and it will have these "buttons" on it representing all of the important areas.

I'm using data provided to me from a 3rd party and all they give are the TL and BR coords for each area.

A 2nd 3D map will display the zoomed in version of these selected areas

Re: [SOLVED] Drawing a square from top left and bottom right coords?

I wasn't able to figure out how to use what you referenced for my need, but this was my solution:

List<Vector2> squareCorners = new List<Vector2>();

//grab the 2 I know of
Vector2 NWcorner = new Vector2( (float)NW.longitude, (float)NW.latitude);
Vector2 SEcorner = new Vector2( (float)SE.longitude, (float)SE.latitude);

// now get the other 2
Vector2 NEcorner = new Vector2( Math.Max(NWcorner.x, SEcorner.x), Math.Max(NWcorner.y, SEcorner.y );
Vector2 SWcorner = new Vector2( Math.Min(NWcorner.x, SEcorner.x), Math.Min(NWcorner.y, SEcorner.y );

// add them all to the list
squareCorners.Add(NWcorner);
squareCorners.Add(NEcorner);
squareCorners.Add(SEcorner);
squareCorners.Add(SWcorner);

// create the poly
OnlineMapsDrawingPoly mySquare = new OnlineMapsDrawingPoly(squareCorners, Color.gree, 1.0f, Color.cyan);
// add it to the map
OnlineMapsDrawingElementManager.AddItem(mySquare);

This does work.

Now I'm on to making it clickable, which I think I can handle