Reputation: 4359
I am trying to build a cartographic quil visualization derivative of this bicycle station map animation. I am trying to use the new default functional mode in quil, because it looks like this handles a lot of the work of dealing with mouse events and updating the display. However, I am running into an issue where one part of the drawing (the background map) is taking far too long to render completely, even with a very low framerate.
Following the recommendation of this visualization, I am installing the UnfoldingMaps dependency by downloading it, and installing it into a leiningen localrepo as follows:
$ lein localrepo install /path/to/library/Unfolding.jar unfolding 0.9.6
$ lein localrepo install /path/to/library/json4processing.jar json4proc 0.9.6
My project.clj file looks like this:
(defproject transit-map "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:plugins [[lein-localrepo "0.5.3"]]
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[org.clojure/data.json "0.2.5"]
[quil "2.2.5"]
[unfolding "0.9.6"] ; Installed in local repo
[json4proc "0.9.6"] ; Ditto; shipped with unfolding
[log4j "1.2.15"]])
And, my simple core.clj looks like so:
(ns transit-map.core
(:import (de.fhpotsdam.unfolding UnfoldingMap)
(de.fhpotsdam.unfolding.geo Location)
(de.fhpotsdam.unfolding.providers StamenMapProvider)
(de.fhpotsdam.unfolding.marker SimplePointMarker))
(:require [quil.core :as q]
[quil.middleware :as m]))
(defn setup []
;; Only has close to enough time to plot if the framerate is very
;; low, and even then doesn't quite get the job done.
(q/frame-rate 1)
;; setup function returns initial state.
;; State is one big happy hashmap
{:bg-map (doto (UnfoldingMap.
(quil.applet/current-applet)
(de.fhpotsdam.unfolding.providers.StamenMapProvider$TonerBackground.))
(.setZoomRange 10 12)
(.zoomToLevel 11)
(.panTo (Location. 47.625 -122.332071))
(.draw))})
(defn update-state [state])
(defn draw-state [state]
(.draw (state :bg-map)))
(q/defsketch transit-map
:title "Transit map"
:size [250 500]
;; setup function called only once, during sketch initialization.
:setup setup
;; update-state is called on each iteration before draw-state.
:update update-state
:draw draw-state
;; This sketch uses functional-mode middleware.
:middleware [m/fun-mode])
Remarkably, for very little effort, this works... sort of. Even with the frame rate dialed back to 1fps, the background image isn't quite able to render:
Any suggestions on how to give this particular element the time it needs to render fully? Ultimately, I'm looking to do some animations on top of this at more than 1fps. I'm beginning to suspect that my best bet will be to grab a static image and throw that in the background. But, is there anything else that people can recommend here?
Upvotes: 2
Views: 319
Reputation: 4359
Well, it looks like storing the map context in the state hashmap is the problem. Defining the background map in setup
as:
(def bgmap
(doto (UnfoldingMap.
(quil.applet/current-applet)
(de.fhpotsdam.unfolding.providers.StamenMapProvider$TonerBackground.))
(.setZoomRange 10 13)
(.zoomToLevel 12)
(.draw)))
Works if I then call the draw method in draw-state
as such:
(.draw bgmap)
I can set the framerate to reasonable levels, and the relatively slow drawing of the background map simply takes a few frames to fully fill in--exactly what I was looking for.
Upvotes: 1