0
$\begingroup$

I'm trying to write a code that displays an entire shapefile color-coded by one variable, and then as the mouse is moving it shows the local regional area of interest with all its data

Got a working code, but it doesn't seem efficient as I'm overlaying two different graphics, one with zero opacity. Is there a better way of implementing the code?

(Edit: Using Mathematica 9.0)

data = Import["http://exampledata.wolfram.com/usamap.zip", "Data"][[2]];
{Labels, BlockData} = Map[("LabeledData" /. data) /. Rule[a_, b_] :> # &, {a, b}];
ColorBy = "AREA";
Data4Color = ColorBy /. ("LabeledData" /. data);
Geometry = "Geometry" /. data;
labeled = {Data4Color, Geometry} // Transpose;
gathered = GatherBy[labeled, First@# &];
(* http://mathematica.stackexchange.com/a/20207/8757 *)
InteractiveToolTip =
  Table[
    Tooltip[Geometry[[i]], {Graphics[Geometry[[i]]], 
    TableForm[{Labels, BlockData[[All, i]]} // Transpose]}], 
    {i, Dimensions[Geometry][[1]]}];  
h1 = MapIndexed[{ColorData[1] @@ #2, Tooltip[#[[All, 2]], #[[1, 1]]]} &, gathered];
Graphics[{h1, {Opacity[0], InteractiveToolTip}}, ImageSize -> Full]

Mathematica graphics

$\endgroup$
1
$\begingroup$

Trying to modify your code as little as possible:

{Labels, BlockData} = Map[("LabeledData" /. data) /. Rule[a_, b_] :> # &, {a, b}];
ColorBy = "AREA";
Data4Color = ColorBy /. ("LabeledData" /. data);
Geometry = "Geometry" /. data;
labeled = {Data4Color, Geometry, Transpose@BlockData}\[Transpose];
gathered = GatherBy[labeled, First@# &];
h1 = MapIndexed[{Tooltip[{ColorData[1] @@ #2, #[[All, 2]]}, 
                {Graphics@#[[All, 2]], TableForm[{Labels, Sequence @@ #[[All, 3]]} //Transpose]}]}&,
               gathered];
Graphics[h1, ImageSize -> Full]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.