mapnik icon indicating copy to clipboard operation
mapnik copied to clipboard

Working out how to position an overlay

Open rheh opened this issue 9 years ago • 2 comments

I have successfully used mapnik to produce the following map:

image

The area at the bottom containing the labels is added post mapnik with graphics magic. The position is fixed. However, as you can see the overlay splats over the route I've printed. Is it possible to use something within mapnik to help me position the overlay which automatically moves the overlay to an edge of the map that does not collide with the route. Or, is there a way to convert the pixel x, y values to a latitude and longitude so I can use a tool like mapnik to do the collision detection.

rheh avatar Aug 22 '16 16:08 rheh

I see two options. First the simpler one.

You can place the overlay box by ShieldSymbolizer with placement="point to the center of the map and use placement-type="list" to define positions for all four edges of the map by dx and dy from the center of the map.

Something like:

<ShieldSymbolizer
    file="file path of the overlay image"
    placement="point"
    dx="value for left position"
    dy="value for down position"
    placement-type="list"
    face-name="DejaVu Sans Book">
    <Placement dx="value for right position" dy="value for down position" />
    <Placement dx="value for right position" dy="value for top position" />
    <Placement dx="value for left position" dy="value for top position" />
<ShieldSymbolizer>

Because LineSymbolizer doesn't interact with the collision detector, some text or markers with opacity="0" need to be rendered along the line and their bboxes added to the collision detector.

The more complicated way contains some actual programming. It is possible to do additional collision detection after a map is rendered. The collision detector can be passed to the rendering and then queried as this python test case partly shows. But such functionality is fully supported only by C++ interface. Python interface doesn't support querying and the Node one doesn't implement the interface to the collision detector at all, as far as I know.

talaj avatar Aug 23 '16 08:08 talaj

I compromised and moved the labels to the bottom and also reduced the height of the image to compensate. It would be great to have a way to ask for the lat / long of a given pixel on the final render

rheh avatar Sep 05 '16 10:09 rheh