Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

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]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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