[OSM-dev] Area center calculation

Jon Burgess jburgess777 at gmail.com
Tue Oct 5 18:52:16 BST 2010


On Tue, 2010-10-05 at 17:34 +0100, Tom Hughes wrote:
> On 05/10/10 17:26, Csongor Nemes wrote:
> 
> > Our product, OpenMaps (currently available on the iPhone and the iPod
> > touch), is the only one which lets you tap on POIs on the map. We use
> > the default OSM map as the default map type in our app, but the user can
> > change to OpenCycleMap and OpenPisteMap as well; also the user can add
> > custom map types (e.g. OSM Osmarender). We need to know the exact
> > location of the symbol inside an area (currently we use an algorithm
> > which doesn't always match the rendered symbol's location). The best
> > solution (from our perspective) would be to request the calculated
> > center from OSM, but I'm not sure that it's possible. Otherwise we will
> > implement the algorithm. If I'm not mistaken slightly different
> > algorithms are implemented in different renderers. We are interested in
> > the Mapnik version for now. Point me in the right direction, please;
> > where can I find a description of the algorithm and which source files
> > contain the implementation?
> 
> You'd be better off asking on the mapnik-dev list but I believe that the 
> calculation comes from geos and is a very simple centre-of-mass type 
> calculation.
> 
> Note that there was some discussion at the recent mapnik code sprint of 
> making this more intelligent, so I wouldn't count on it staying the 
> same. Equally it is quite likely that at some point mapnik may get the 
> ability to move the icon/label around a bit to try and find free space - 
> if that happens then there won't be the sort of algorithm that you're 
> looking for at all.

Another way you could approach this is to use the new MetaWriter[1]
feature in Mapnik2. This allows you to export information about the data
contained in the map tile in a machine-readable json format. This can
then be used by the front end to math the mouse position with the
underlying map features. This is shown off in the demo at [2].

1: http://trac.mapnik.org/wiki/MetaWriter
2: http://r2d2.stefanm.com/mapnik/demo.html 

Mapnik2 hasn't been released yet so you may need to be a bit careful
with it.

   Jon





More information about the dev mailing list