]> git.openstreetmap.org Git - chef.git/commitdiff
Fix issues with the export script
authorTom Hughes <tom@compton.nu>
Tue, 25 Jun 2013 20:32:50 +0000 (21:32 +0100)
committerTom Hughes <tom@compton.nu>
Tue, 25 Jun 2013 20:41:40 +0000 (21:41 +0100)
cookbooks/tile/recipes/default.rb
cookbooks/tile/templates/default/export.erb

index 261c0e9ede2f5be4129240d4d9b5457578bd9194..67aeeaa11af151e8a82dc5999c3e706e3bb4e801 100644 (file)
@@ -96,6 +96,9 @@ remote_directory "/srv/tile.openstreetmap.org/html" do
   files_mode 0644
 end
 
+package "python-cairo"
+package "python-mapnik"
+
 directory "/srv/tile.openstreetmap.org/cgi-bin" do
   owner "tile"
   group "tile"
index 8dd209ba6892b9f835da36a272c666a3b376f5f9..ae37fee3a23e18d96d41739ac3506a7fb72d085c 100755 (executable)
@@ -3,7 +3,7 @@
 
 import cairo
 import cgi
-import mapnik2
+import mapnik
 import os
 import shutil
 import sys
@@ -81,7 +81,7 @@ elif not form.has_key("format"):
   output_error("No format specified")
 else:
   # Create projection object
-  prj = mapnik2.Projection("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over");
+  prj = mapnik.Projection("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over");
 
   # Get the bounds of the area to render
   bbox = [float(x) for x in form.getvalue("bbox").split(",")]
@@ -91,7 +91,10 @@ else:
     output_error("Invalid bounding box")
   else:
     # Project the bounds to the map projection
-    bbox = mapnik2.forward_(mapnik2.Box2d(*bbox), prj)
+    bbox = mapnik.forward_(mapnik.Box2d(*bbox), prj)
+
+    # Get the style to use
+    style = form.getvalue("style", "default")
 
     # Calculate the size of the final rendered image
     scale = float(form.getvalue("scale"))
@@ -104,45 +107,45 @@ else:
       output_error("Map too large")
     else:
       # Create map
-      map = mapnik2.Map(width, height)
+      map = mapnik.Map(width, height)
 
       # Load map configuration
-      mapnik2.load_map(map, "/home/jburgess/live/osm2.xml")
+      mapnik.load_map(map, "/srv/tile.openstreetmap.org/styles/%s/project.xml" % style)
 
       # Zoom the map to the bounding box
       map.zoom_to_box(bbox)
 
       # Render the map
       if form.getvalue("format") == "png":
-        image = mapnik2.Image(map.width, map.height)
-        mapnik2.render(map, image)
+        image = mapnik.Image(map.width, map.height)
+        mapnik.render(map, image)
         png = image.tostring("png")
         output_headers("image/png", "map.png", len(png))
         sys.stdout.write(png)
       elif form.getvalue("format") == "jpeg":
-        image = mapnik2.Image(map.width, map.height)
-        mapnik2.render(map, image)
+        image = mapnik.Image(map.width, map.height)
+        mapnik.render(map, image)
         jpeg = image.tostring("jpeg")
         output_headers("image/jpeg", "map.jpg", len(jpeg))
         sys.stdout.write(jpeg)
       elif form.getvalue("format") == "svg":
         file = tempfile.NamedTemporaryFile()
         surface = cairo.SVGSurface(file.name, map.width, map.height)
-        mapnik2.render(map, surface)
+        mapnik.render(map, surface)
         surface.finish()
         output_headers("image/svg+xml", "map.svg", file_size(file))
         output_file(file)
       elif form.getvalue("format") == "pdf":
         file = tempfile.NamedTemporaryFile()
         surface = cairo.PDFSurface(file.name, map.width, map.height)
-        mapnik2.render(map, surface)
+        mapnik.render(map, surface)
         surface.finish()
         output_headers("application/pdf", "map.pdf", file_size(file))
         output_file(file)
       elif form.getvalue("format") == "ps":
         file = tempfile.NamedTemporaryFile()
         surface = cairo.PSSurface(file.name, map.width, map.height)
-        mapnik2.render(map, surface)
+        mapnik.render(map, surface)
         surface.finish()
         output_headers("application/postscript", "map.ps", file_size(file))
         output_file(file)