kopia lustrzana https://github.com/hholzgra/ocitysmap
				
				
				
			finally made the compass rose an optional overlay feature
							rodzic
							
								
									95ca3e6f61
								
							
						
					
					
						commit
						52e66553cf
					
				|  | @ -10,6 +10,7 @@ dbname=maposmatic | ||||||
| # List of available stylesheets, each needs to be described by an eponymous | # List of available stylesheets, each needs to be described by an eponymous | ||||||
| # configuration section in this file. | # configuration section in this file. | ||||||
| available_stylesheets: stylesheet_osm1, stylesheet_osm2 | available_stylesheets: stylesheet_osm1, stylesheet_osm2 | ||||||
|  | available_overlays: scalebar, compass_rose, surveillance, | ||||||
| 
 | 
 | ||||||
| # The default Mapnik stylesheet. | # The default Mapnik stylesheet. | ||||||
| [stylesheet_osm1] | [stylesheet_osm1] | ||||||
|  | @ -22,3 +23,21 @@ path: /path/to/mapnik-osm/osm.xml | ||||||
| name: AnotherOne | name: AnotherOne | ||||||
| description: Another OSM Stylesheet | description: Another OSM Stylesheet | ||||||
| path: /path/to/another/osm.xml | path: /path/to/another/osm.xml | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | # Bundled overlay effect stylesheets | ||||||
|  | [scalebar] | ||||||
|  | name: Scale_Bar_overlay | ||||||
|  | description: Scale bar | ||||||
|  | path: internal:scalebar | ||||||
|  | 
 | ||||||
|  | [compass_rose] | ||||||
|  | name: Compass_Rose_overlay | ||||||
|  | description: Compass Rose | ||||||
|  | path: internal:compass_rose | ||||||
|  | 
 | ||||||
|  | [surveillance] | ||||||
|  | name: Surveillance_Overlay | ||||||
|  | description: Surveillance Cameras | ||||||
|  | path: internal:surveillance | ||||||
|  | 
 | ||||||
|  |  | ||||||
|  | @ -175,28 +175,6 @@ class Renderer: | ||||||
|         return Renderer._get_svg(ctx, logo_path, height) |         return Renderer._get_svg(ctx, logo_path, height) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     @staticmethod |  | ||||||
|     def _get_compass_rose(ctx, height): |  | ||||||
|         """ |  | ||||||
|         Read the compass rose image and rescale it to fit within height. |  | ||||||
| 
 |  | ||||||
|         Args: |  | ||||||
|            ctx (cairo.Context): The cairo context to use to draw. |  | ||||||
|            height (number): final height of the image (cairo units). |  | ||||||
| 
 |  | ||||||
|         Return a tuple (cairo group object for the image, image width in |  | ||||||
|                         cairo units). |  | ||||||
|         """ |  | ||||||
|         logo_path = os.path.abspath(os.path.join( |  | ||||||
|             os.path.dirname(__file__), '..', '..', 'images', 'compass-rose.svg')) |  | ||||||
|         if not os.path.exists(logo_path): |  | ||||||
|             logo_path = os.path.join( |  | ||||||
|                 sys.exec_prefix, 'share', 'images', 'ocitysmap', |  | ||||||
|                 'compass-rose.svg') |  | ||||||
| 
 |  | ||||||
|         return Renderer._get_svg(ctx, logo_path, height) |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def _draw_labels(ctx, map_grid, |     def _draw_labels(ctx, map_grid, | ||||||
|                      map_area_width_dots, map_area_height_dots, |                      map_area_width_dots, map_area_height_dots, | ||||||
|  |  | ||||||
|  | @ -0,0 +1,33 @@ | ||||||
|  | import cairo | ||||||
|  | import os | ||||||
|  | import sys | ||||||
|  | import logging | ||||||
|  | from ocitysmap.layoutlib.commons import convert_pt_to_dots | ||||||
|  | from ocitysmap.layoutlib.abstract_renderer import Renderer | ||||||
|  | 
 | ||||||
|  | LOG = logging.getLogger('ocitysmap') | ||||||
|  | 
 | ||||||
|  | def render(renderer, ctx): | ||||||
|  |     svg_path = os.path.abspath(os.path.join( | ||||||
|  |         os.path.dirname(__file__), '..', '..', '..', '..', 'images', 'compass-rose.svg')) | ||||||
|  | 
 | ||||||
|  |     if not os.path.exists(svg_path): | ||||||
|  |         logo_path = os.path.join( | ||||||
|  |             sys.exec_prefix, 'share', 'images', 'ocitysmap', 'compass-rose.svg') | ||||||
|  | 
 | ||||||
|  |     if not os.path.exists(svg_path): | ||||||
|  |         LOG.warning("No compass rose image found") | ||||||
|  |         return | ||||||
|  |          | ||||||
|  |     h = convert_pt_to_dots(renderer._title_margin_pt, renderer.dpi) | ||||||
|  |     x = convert_pt_to_dots(renderer._map_coords[0], renderer.dpi) | ||||||
|  |     y = convert_pt_to_dots(renderer._map_coords[1], renderer.dpi) | ||||||
|  |          | ||||||
|  |     ctx.save()    | ||||||
|  |     ctx.translate(x + h/2, y + h/2) | ||||||
|  |     rose_grp, rose_width = Renderer._get_svg(ctx, svg_path, h) | ||||||
|  |     ctx.set_source(rose_grp) | ||||||
|  |     ctx.paint_with_alpha(0.75) | ||||||
|  |     ctx.stroke() | ||||||
|  |     ctx.restore() | ||||||
|  | 
 | ||||||
|  | @ -646,17 +646,6 @@ class SinglePageRenderer(Renderer): | ||||||
|             ctx.restore() |             ctx.restore() | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|         # Draw compass rose |  | ||||||
|         # TODO: proper positioning/scaling, move to abstract renderer |  | ||||||
|         ctx.save() |  | ||||||
|         ctx.translate(map_coords_dots[0] + title_margin_dots/2, |  | ||||||
|                       map_coords_dots[1] + title_margin_dots/2) |  | ||||||
|         rose_grp, rose_width = self._get_compass_rose(ctx, title_margin_dots) |  | ||||||
|         ctx.set_source(rose_grp) |  | ||||||
|         ctx.paint_with_alpha(0.75) |  | ||||||
|         ctx.stroke() |  | ||||||
|         ctx.restore() |  | ||||||
| 
 |  | ||||||
|         # Draw QR code |         # Draw QR code | ||||||
|         if self.qrcode_text: |         if self.qrcode_text: | ||||||
|           ctx.save() |           ctx.save() | ||||||
|  |  | ||||||
		Ładowanie…
	
		Reference in New Issue
	
	 Hartmut Holzgraefe
						Hartmut Holzgraefe