[OSM-talk] Playing with Mapnik rendering

Cameron Patrick cameron at patrick.wattle.id.au
Thu Jul 26 21:36:35 BST 2007


Artem Pavlenko wrote:

> >>One thing I didn't manage to do was get Mapnik to render names either
> >>above or below the lines for the roads, though.  Anyone know if  
> >>this is possible easily?
> >
> >I couldn't manage to get that to work either, so if you figure it out,
> >let me know! I mentioned this previously in
> >http://lists.openstreetmap.org/pipermail/talk/2007-July/016036.html
> >with regards to cycle route numbers.
> 
> This is a good feature but it is not implemented at the moment. Could  
> you submit a ticker to trac.mapnik.org ?

I can do you one better than that.  Patch attached :-)

Cameron

-------------- next part --------------
Index: src/placement_finder.cpp
===================================================================
--- src/placement_finder.cpp	(revision 492)
+++ src/placement_finder.cpp	(working copy)
@@ -326,6 +326,7 @@
 
       double angle = 0.0;
       int orientation = 0;
+      double displacement = boost::tuples::get<1>(p->displacement_); // displace by dy
     
       p->current_placement.path.clear();
     
@@ -443,9 +444,17 @@
 
          x = new_x - (distance)*cos(angle);
          y = new_y + (distance)*sin(angle);
-         //Center the text on the line.
-         x -= (((double)string_height/2.0) - 1.0)*cos(render_angle+M_PI/2);
-         y += (((double)string_height/2.0) - 1.0)*sin(render_angle+M_PI/2);
+         //Center the text on the line, unless displacement != 0
+         if (displacement == 0.0) {
+           x -= (((double)string_height/2.0) - 1.0)*cos(render_angle+M_PI/2);
+           y += (((double)string_height/2.0) - 1.0)*sin(render_angle+M_PI/2);
+         } else if (displacement > 0.0) {
+           x -= ((displacement + (double)string_height) - 1.0)*cos(render_angle+M_PI/2);
+           y += ((displacement + (double)string_height) - 1.0)*sin(render_angle+M_PI/2);
+         } else { // displacement < 0
+           x -= ((displacement - (double)string_height) - 1.0)*cos(render_angle+M_PI/2);
+           y += ((displacement - (double)string_height) - 1.0)*sin(render_angle+M_PI/2);
+         }
          distance -= ci.width;
          next_char_x = ci.width*cos(render_angle);
          next_char_y = ci.width*sin(render_angle);


More information about the talk mailing list