Here is my naive attempt to ome up with informative tooltips:
Tooltips
Following the definitions from the Notebook
lsCells =
Cases[grHist[[1]],
Tooltip[h_Polygon /; MatrixQ[h[[1]]],
pop_ /; NumberQ[pop] && pop > 3] :> <|"Cell" -> h,
"Population" -> pop|>, \[Infinity]];
lsCells =
Map[Append[#, "Center" -> Mean[PolygonCoordinates[#["Cell"]]]] &,
lsCells];
And extrakting the plot dimensions and scaling:
absOps = AbsoluteOptions[grHist[[1]]];
We now have to scale between Geographic coordinates
GeoRange /. absOps
(* {{47.0295, 55.4005}, {5.5195, 15.4305}} *)
and GeoGridPositions
GeoGridRange /. absOps
(* {{5.5195, 15.4305}, {53.4218, 66.8345}} *)
The idea is to select <numCities> largest cities from each bin (Polygon) and sow them together with their distance from the bin center. For this we need to scale between the coordinates and the geo grid used in the plot.
nlist = (Values /@ Normal[dsCityRecords]) /. {"Germany", b_, c_, d_,
e_, f_} :> {"Germany", b, c, d, Lon2X[f], Lat2Y[e]}
xyRange = GeoGridRange /. absOps
lonlatRange = Reverse[GeoRange /. absOps]
lonRescale[lon_] := Rescale[lon, xyRange[[1]], lonlatRange[[1]]]
latRescale[lon_] := Rescale[lon, xyRange[[2]], lonlatRange[[2]]]
rescaleLonLat[{lon_, lat_}] := {lonRescale[lon], latRescale[lat]}
X2Lon[x_] := Rescale[x, xyRange[[1]], lonlatRange[[1]]]
Y2Lat[y_] := Rescale[y, xyRange[[2]], lonlatRange[[2]]]
Lon2X[x_] := Rescale[x, lonlatRange[[1]], xyRange[[1]]]
Lat2Y[y_] := Rescale[y, lonlatRange[[2]], xyRange[[2]]]
LatLon2XY[{x_, y_}] := {Lon2X[y], Lat2Y[x]}
Let's create the tooltips
tooltip = Table[
numCities = 5;
rmf = RegionMember[lsCells[[i]]["Cell"]];
sel = Select[nlist, rmf[#[[-2 ;; -1]]] &];
len = Min[{Length[sel], numCities}];
selTake = Take[sel, len];
dist =
Round@GeoDistance[XY2LatLon[lsCells[[i]]["Center"]],
XY2LatLon[#[[-2 ;; -1]]]] & /@ selTake;
If[sel != {},
Panel[
TableForm[
Flatten /@ Transpose[{selTake[[All, {2, 3, 4}]], dist}],
TableHeadings -> {None, {"Federal State", "City", "Population",
"Distance to ctr."}}]],
Panel[
TableForm[{{"", "", "", ""}},
TableHeadings -> {None, {"Federal State", "City", "Population",
"Distance to ctr."}}]]], {i, 1, Length[lsCells]}];
and put them in an Association for easier replacement later
ttasoc = Association@
Table[{lsCells[[i]]["Population"] ->
Panel[tooltip[[i]],
Style[lsCells[[i]]["Population"], Red, Bold], Top]}, {i, 1,
Length[lsCells]}];
Now we can jst replace the Tooltip from the original figure:
grHist /. Tooltip[p_Polygon, pop_?NumberQ] :> Tooltip[p, ttasoc[pop]]
This is not perfect. If you move over the hexagon belonging to the Berlin area we note, that Berlin is not within the Polygon.
The reason is most likely my simple-minded rescaling of the geo positions but I couldn't figure out a better transformation. Maybe some GeoGraphics experts can help here