lwu (owner)

Revisions

gist: 7382 Download_button fork
public
Description:
Shoes + Mapnik = http://flickr.com/photos/wu_135/2801694916/sizes/l/
Public Clone URL: git://gist.github.com/7382.git
Embed All Files: show embed
README #
1
2
3
4
5
6
7
8
9
10
11
12
13
My first Shoes app! Shoes is a "Tiny Toolkit" for informal graphics and windowing:
  http://code.whytheluckystiff.net/shoes/
 
I wanted to be able to easily edit Mapnik stylesheets, hit render, and see the result
right away. While this isn't a great solution -- the prototype shells out to a C++ binary to
re-render the map -- it works for the time being.
 
A screenshot of the resulting application can be seen here:
  http://farm4.static.flickr.com/3095/2801694916_1a051349b4_b.jpg
  (http://flickr.com/photos/wu_135/2801694916/sizes/l/)
 
This code doesn't come with the C++ binary nor does it come with the original dataset, but please do
provide your own!
shoes_mappin.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
## This is a prototype Shoes app to make Mapnik stylesheet editing a little bit easier.
## More of a proof of concept -- manysuchthings are hardcoded (image sizes, file names)
#
class DebugShoes < Shoes # Shoes got you down? DebugShoes won't fail silently on ya...
  def self.app(*args, &blk)
    super(*args) do
      begin
        self.instance_eval(&blk)
      rescue => e
        error(e) # log the error and inform the user!
        @err_bar = flow :width => 1.0, :height => 32, :top => self.height-32, :left => 0 do
          background lightgrey
          stack :width => self.width-100
          stack :width => 20, :margin => 4 do image "#{DIR}/static/icon-error.png" end;
          stack :width => 80 do para(link("#{Shoes.log.length} Errors!", :stroke => red) { Shoes.show_log }) end;
        end
      end
    end
  end
end
 
class Image
  def reload
    self.path = "./" + path # reload hack, cache begone!
    self.hide.show
  end
end
 
DebugShoes.app :width => 1360, :height => 720, :title => 'MappinPrototype' do
  STYLE_XML = 'style.xml'
  IMAGE_PNG = 'cali.png'
  MAP_APP = './cali ~/src/mapnik'
 
  animate(2) do
    if @render then
      @render = false
      `#{MAP_APP}` # shell out to run Map app
      @bg.reload
    end
  end
 
  background black
  flow do
    stack :width=>820, :margin=>15 do
      @bg = image IMAGE_PNG, :width=>800, :height=>680
    end
    stack :width => 530, :margin=>15 do
      background lightgrey, :curve => 12
      para "Layers"
      @e = edit_box "Would that I...", :width => 500, :height => 620
      @e.text = IO.read(STYLE_XML)
      button "Render!", :margin=>5 do
        warn "Rendering..."
        open(STYLE_XML, 'w') { |f| f.puts @e.text }
        @bg.blur 10
        @bg.hide.show # reload
        @render = true # defer rendering so that blur effect becomes visible
      end
    end
  end
end