8
$\begingroup$

My goal here is to be able to display the coordinates of the center of a DynamicGeoGraphic which updates as the map is dragged (without right clicking on the map to get coordinates).

One method I came up with to do this was to read the GeoRange of the map, then take the average of the latitudes and longitudes in the GeoRange, but the GeoRange doesn't update dynamically as the map is dragged:

Column[
{map = DynamicGeoGraphics[GeoPosition[{40.097191, -88.245990}]],
Dynamic[Options[map, GeoRange]]}]

I've provided a specific GeoPosition here just for the sake of clarity. I have two questions:

  1. Is there a better way to access information about the map directly than what I've done here?

  2. Why won't the GeoRange change as the map is moved?

Any other ideas for how to accomplish this are also welcome.

$\endgroup$
6
$\begingroup$

Final code depends of your exact needs but here is something to start with:

Insert[
  ToBoxes@DynamicGeoGraphics[],
  Initialization :> (CreatePalette[
     DynamicModule[{}, 
      Panel@Column[{EvaluationCell[], 
         Dynamic[Column@{Typeset`geoRange$$, Typeset`geoZoom$$, 
            Typeset`geoProjection$$}]}], InheritScope -> True]]),
  {1, 1, -1}
  ] // RawBoxes

enter image description here

$\endgroup$
  • 1
    $\begingroup$ I think this is closest to what I was hoping to find, but I'm having trouble understanding what's actually going on with your code. I've not seen a context used in this way before. Could you expand a bit on why/how this works? $\endgroup$ – Texas Red Sep 12 '16 at 23:56
  • $\begingroup$ @TexasRed I will later :) $\endgroup$ – Kuba Sep 13 '16 at 5:35
4
$\begingroup$

This is a comment.

The following gives dynamically the XYZ coordinates asked to the tiles server OpenStreetMap (not Wolfram Tile Server). It updates when you release the mouse button in the map.

A particularly interesting thing is that the option GeoServer of GeoGraphics works also with DynamicGeoGraphics.

Dynamic[{x, y, z}]
DynamicGeoGraphics[
 Entity["City", {"Paris", "IleDeFrance", "France"}], 
 GeoServer -> 
  StringTemplate[
   "http://a.tile.openstreetmap.org/<*z=#1*>/<*x=#2*>/<*y=#3*>.png"]]

Edit
This gives the coordinate of the last tile asked to the server, which is probably not the center of the map.
End Edit

$\endgroup$
  • $\begingroup$ Very interesting. I was hoping to be able to update the value while the map was dragged, not just when it was released, but this is quite clever. I take it that the reason this works has more to do with OpenStreetMap than Mathematica? $\endgroup$ – Texas Red Sep 12 '16 at 23:58

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.