cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Super User
Super User

RAND: Keep Map Marker in a Certain Area of Screen

Hello,

I don't have much experience using the math functions within PowerApps. Looking for some guidance here. 

Scenario:

  • Using PowerApps as a rapid, click-thru prototype creation tool
  • Have a map image on the screen
  • Have a map pin on the screen
  • When user selects an item in a Gallery, I want the Map Pin to popup on the map, BUT ONLY WITHIN A CERTAIN AREA OF THE SCREEN

Questions:

  • I can control the visibility of the Map Pin based on Gallery selection.
  • But how do I easily assign some randomness to the Map Pin X and Y to give a feel of being dynamic?
  • I don't want the map pin to show up in the middle of the Pacific for example Smiley Happy

Specifics:

  • Map image dims: X: 330, Y: 120, Width: 1000, Height: 550

Thanks for the insights!

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Super User
Super User

Re: RAND: Keep Map Marker in a Certain Area of Screen

Or this if you want it to dynamically adjust to the image size and placement.

UpdateContext({randomX:Round((Rand()*imgMap.Width),0)+imgMap.X})
UpdateContext({random:Round((Rand()*imgMap.Height),0)+imgMap.Y})


-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Super User
Super User

Re: RAND: Keep Map Marker in a Certain Area of Screen

Sweet! Thanks for the guidance @Pstork1

Heres what I finally went with:

Set(varRandX, (Rand() * (imgMap.Width - icnMapPin.Width)) + imgMap.X);       
Set(varRandY, (Rand() * (imgMap.Height - icnMapPin.Height)) + imgMap.Y)

Key was subtracting the MapPin.Width and .Height from the map to create a "buffer" for the pin itself. 

 

7 REPLIES 7
Super User
Super User

Re: RAND: Keep Map Marker in a Certain Area of Screen

Hm... Thought this would work, but nope:

  • OnSelect of the Gallery, 

 

Set(varRandX, Rand() * (1330 - 336));
Set(varRandY, Rand() * (850 - 140))
  • X and Y of Map Pin Icon
    • varRandX, varRandY

 

Super User
Super User

Re: RAND: Keep Map Marker in a Certain Area of Screen

Since this appears to be for some kind of a demo.  Have you considered making a collection of location coordinates that map to locations on your map and then using Rand() to pick the index of one of those?

UpdateContext({random:Round((Rand()*25),0)})


-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Super User
Super User

Re: RAND: Keep Map Marker in a Certain Area of Screen

Hi @Pstork1 , 

Thanks for the reply. This would be a good solution if I was calling an API and bringing back a map with actual coordinates. As you said, I'm demoing and just need to make the Map Pin randomly stay within the bounds of the map image. 

 

Just tried this to no avail:

Set(varRandX, Rand() * (imgMap.Width + imgMap.X));
Set(varRandY, Rand() * (imgMap.Height - imgMap.Y))
Super User
Super User

Re: RAND: Keep Map Marker in a Certain Area of Screen

This won't keep it from showing up in inappropriate places on the map.  But if you just want to make sure its inside the boundaries try this:

UpdateContext({randomX:Round((Rand()*1000),0)+300})
UpdateContext({random:Round((Rand()*550),0)+120})


-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Super User
Super User

Re: RAND: Keep Map Marker in a Certain Area of Screen

Or this if you want it to dynamically adjust to the image size and placement.

UpdateContext({randomX:Round((Rand()*imgMap.Width),0)+imgMap.X})
UpdateContext({random:Round((Rand()*imgMap.Height),0)+imgMap.Y})


-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Super User
Super User

Re: RAND: Keep Map Marker in a Certain Area of Screen

Sweet! Thanks for the guidance @Pstork1

Heres what I finally went with:

Set(varRandX, (Rand() * (imgMap.Width - icnMapPin.Width)) + imgMap.X);       
Set(varRandY, (Rand() * (imgMap.Height - icnMapPin.Height)) + imgMap.Y)

Key was subtracting the MapPin.Width and .Height from the map to create a "buffer" for the pin itself. 

 

Super User
Super User

Re: RAND: Keep Map Marker in a Certain Area of Screen

I didn't think about that.  Good catch,



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Helpful resources

Announcements
firstImage

PowerApps Monthly Community Call!

Join us next Wednesday for our Demo Extravaganza, October 16, 2019 8am PDT.

firstImage

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Top Community Contributors for September  2019

Top Community Contributors for September 2019 🎉🎉

Let's thank our top community contributors

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 404 members 5,600 guests
Please welcome our newest community members: