9
$\begingroup$

When using Graphics, I can change the color of the object with the use of Mouseover.

 Graphics[{Opacity[0.9], {Mouseover[{Red, #}, {Green, #}]}} & /@ {Disk[{0, 0}], Text["Moi", {1.5, 0}], Disk[{3, 0}]}] (*Objects change color *) 

When trying the same approach with Geographics

countries = {"Spain", "Belgium", "Romania"}; GeoGraphics[{GeoStyling[Opacity[0.5]], Mouseover[{Red, Tooltip[Polygon[{Entity["Country", #]}], #]}, {Green, Tooltip[Polygon[{Entity["Country", #]}], #]}]} & /@ countries] 

Graphics are displayed but when mouse hovers on top of a country polygon, then an error message will toggle on the screen stating that "Coordinate Entity["Country","Spain"] should be a pair of numbers.....

What is the correct approach to make the polygon representing the country change colors when selected?

$\endgroup$
1
  • $\begingroup$ I can see it working since 10.1 (I cannot test with earlier versions). What was the version of the bug? I would like to write the bug header stating that the bug is fixed. If you prefer to do it, please feel free to proceed. $\endgroup$ Commented Oct 7, 2016 at 23:10

2 Answers 2

2
$\begingroup$

GeoGraphics seems to have some fragility. I post this as a way (unfortunately not Mouseover) to achieve some interactivity:

{spain, belgium, romania} = countries; h["Spain"] = spain; h["Belgium"] = belgium; h["Romania"] = romania; g[x_] := {Blue, h[x]}; cnt = {"Spain", "Belgium", "Romania"}; f = DynamicModule[{col = Black}, DynamicWrapper[Dynamic@Style[#, Bold, 20, col], If[CurrentValue["MouseOver"], col = Red; g[#] = {Red, EdgeForm[Black], h[#]} , col = Black; g[#] = {Blue, h[#]}]]] &; Framed[Row[{Dynamic@ GeoGraphics[g /@ cnt, ImageSize -> Large], Column[f /@ {"Spain", "Belgium", "Romania"}] 

enter image description here

This is a little unforgiving on my machine if I add options for the GeoGraphics object.

Just for variety (but do not run synchronously to avoid function definition conflicts):

f2 = DynamicModule[{col = Black}, DynamicWrapper[Dynamic@Style[#, Bold, 20, col], If[CurrentValue["MouseOver"], col = Red; g[#] = {GeoStyling["ReliefMap"], EdgeForm[Black], h[#]} , col = Black; g[#] = {Blue, h[#]}]]] &; Framed[Row[{Dynamic@ GeoGraphics[g /@ cnt, ImageSize -> Large], Column[f2 /@ {"Spain", "Belgium", "Romania"}]}]] 

enter image description here

$\endgroup$
5
$\begingroup$

Let's try something more basic that doesn't require GeoGraphics to interpret entities:

countries = CountryData[#, "FullPolygon"] & /@ {Entity["Country", "Spain"], Entity["Country", "Belgium"], Entity["Country", "Romania"]}; GeoGraphics[{ Mouseover[{Red, #}, {Blue, #}] & /@ countries }] 

OK, it still doesn't work so it seems like it's a bug.

Follow-up: the WRI support has notified the development team about this.

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.