Message Boards Message Boards

0
|
3642 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

How to let GeoIdentify function work in dynamic mode?

Posted 3 years ago

When I try to use GeoIdentify in dynamic mode. It doesn't work. For example, I want to show the country name when mouse hover on Canada in GeoGraphic. It just print out the empty list. It there any way to solve this problem?

{
  GeoGraphics[Entity["Country","Canada"]],
  Dynamic[
  GeoIdentify[
  "Country",
  GeoPosition@MousePosition["Graphics"]
  ]
 ]
}

Output when mouse hover on Canada:

Output

POSTED BY: Robert Chen

Robert,

the way you do it you get the coordinates of the graphics - and not of GeoGraphics. You have to do a proper rescaling, and furthermore equidistant geo coordinates are necessary. I would do it like so:

gbbox = GeoBoundingBox[Entity["Country", "Canada"]];
{latrng, longrng} = Transpose[First /@ gbbox];
geopos[{x_, y_}] := GeoPosition[{Rescale[y, {0, 1}, latrng], Rescale[x, {0, 1}, longrng]}];
geopos[None] = {};

{GeoGraphics[GeoRange -> gbbox, ImageSize -> Large, GeoRangePadding -> None,
  GeoGridLines -> Automatic, GeoProjection -> "CylindricalEquidistant"], 
 Dynamic@GeoIdentify["Country", geopos[MousePosition["GraphicsScaled"]]]}

This should work, it identifies Canada, United States, Greenland; but there is a certain time delay.

POSTED BY: Henrik Schachner
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract