Mouse position to Location translation problem
I'm running into an issue where, when clicking on the map (myMap in the mapView component), I get good mouseX and mouseY values (800x600 grid). When I pass those values to get the lat/lon, I get strange and inconsistent results.
For example, starting around the equator in the Pacific (0,-180), I get a lat,lon of -60, -22.
At the equator and PM (0,0), I get a lat/lon of about -62,158.
Rounding the bend to the Pacific again (0,180), I get a lat/lon of -61,335.
var well:Sprite = Sprite(mapView.myMap.map.grid.getChildByName("well"));
var clickLoc:Location = mapView.myMap.map.pointLocation(new Point(mapView.mouseX, mapView.mouseY), well);
Normally, I'd assumed I'd screwed up the initial settings of the map, but when plotting markers by lat/lon, they are positioned perfectly (a marker in St. Louis ends up in St. Louis, etc.).
------------------
Additional info:
As I scroll in and keep the mouse in the same position (402,223) as (mouseX,mouseY), the lat/lon progress through the zooms as:
2 -63.81145077411647, 155.60263677699368
3 -37.56895063192593, 78.45909284629047
4 -18.762921686386715, 39.88732088093884
5 -8.335640387337225, 20.60143489826303
6 -2.9926624140133717, 10.958491906925131
7 -0.3084336961755266, 6.137020411256181
For example, starting around the equator in the Pacific (0,-180), I get a lat,lon of -60, -22.
At the equator and PM (0,0), I get a lat/lon of about -62,158.
Rounding the bend to the Pacific again (0,180), I get a lat/lon of -61,335.
var well:Sprite = Sprite(mapView.myMap.map.grid.getChildByName("well"));
var clickLoc:Location = mapView.myMap.map.pointLocation(new Point(mapView.mouseX, mapView.mouseY), well);
Normally, I'd assumed I'd screwed up the initial settings of the map, but when plotting markers by lat/lon, they are positioned perfectly (a marker in St. Louis ends up in St. Louis, etc.).
------------------
Additional info:
As I scroll in and keep the mouse in the same position (402,223) as (mouseX,mouseY), the lat/lon progress through the zooms as:
2 -63.81145077411647, 155.60263677699368
3 -37.56895063192593, 78.45909284629047
4 -18.762921686386715, 39.88732088093884
5 -8.335640387337225, 20.60143489826303
6 -2.9926624140133717, 10.958491906925131
7 -0.3084336961755266, 6.137020411256181
2
people have this question
I have this question, too!
Tell me when someone answers.
The more people who ask this question, the more it gets noticed.
The more people who ask this question, the more it gets noticed.
The best answer from the company
-
You don't need to pass a reference to the well or the grid at all. The default context is actually the grid, which gives correct results as you've found. Specifying a context yourself is optional.
I suspect that the well scaleX and scaleY were messing up your values, or that it's something to do with the well being positioned at (width/2, height/2) and not (0,0).
You shouldn't need to look further than the Map object (not the Flex map) to find most of these common operations.
The company says
this answers the question
Create a customer community for your own organization
Plans starting at $19/month
-
Inappropriate?Ah... grid... instead of a "well" sprite, I needed to call the "grid" sprite
I’m happy
-
Inappropriate?You don't need to pass a reference to the well or the grid at all. The default context is actually the grid, which gives correct results as you've found. Specifying a context yourself is optional.
I suspect that the well scaleX and scaleY were messing up your values, or that it's something to do with the well being positioned at (width/2, height/2) and not (0,0).
You shouldn't need to look further than the Map object (not the Flex map) to find most of these common operations.
The company says
this answers the question
-
Inappropriate?The context isn't optional in AS3/flex. When I leave it out, I get this error:
1136: Incorrect number of arguments. Expected 2.
I'm not sure how to use pointLocation given the examples seen. Any suggestions on what to use for context? -
Inappropriate?Try passing in map or map.grid as the context, see if that helps?
Loading Profile...



EMPLOYEE
