Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to draw and animate polylines with polymaps? #91

Closed
codecowboy opened this issue Aug 8, 2011 · 7 comments
Closed

Is it possible to draw and animate polylines with polymaps? #91

codecowboy opened this issue Aug 8, 2011 · 7 comments

Comments

@codecowboy
Copy link

I would like to create a map which displays a route passing through several points. I would then like to clone this route (a series of polylines) and animate it by filling the polyline with another colour. The fill would extend as far as a user has travelled along the route.

Would something like this be possible using polymaps?

@shawnbot
Copy link
Contributor

shawnbot commented Aug 8, 2011

You'd have to interpolate the feature's geometry coordinates (perhaps with d3.js?) and force a redraw of the geoJson layer:

var map = po.map();
var layer = po.geoJson();
var coords = [...]; // your coordinates here
var feature = {type: "Feature", geometry: {type: "LineString", coordinates: coords}, ...};
layer.features([feature]);
map.add(layer);
// force a redraw
map.dispatch({type: "move"}); 

@codecowboy
Copy link
Author

Thanks for your reply. Can you explain what you mean by interpolate the feature's geometry coordinates? Is the polyline 'the feature'? From a quick look at d3 it looks like I could use that to select the individual svg paths. I don't want to move the map layer, just the line. I mocked up a quick example when I started looking at the problem - http://jsfiddle.net/codecowboy/XkShV/. This is the effect I would like:

@mbostock
Copy link
Contributor

mbostock commented Aug 9, 2011

You can call layer.reload to redraw the layer.

@shawnbot
Copy link
Contributor

shawnbot commented Aug 9, 2011

So yeah, I guess the answer to your original question is no: Polymaps can't animate polylines out of the box. The idea I was getting at in my previous comment was that you would keep references to the GeoJSON feature (feature) and its geometry coordinates (coords) around and, on a timer (or in response to a slider, etc.), interpolate the points along a path defined by those coordinates, update feature.geometry.coordinates accordingly, then redraw the layer (as Mike noted, using layer.redraw()). d3 does SVG, but it also just does interpolation and transitions really well. I can't recommend any particular strategy because I'm pretty new to it personally, but I'm sure you could find an example in the docs and build from that.

@codecowboy
Copy link
Author

ok, thanks for your replies guys ;-)

@jensfinnas
Copy link

This might be a stupid question, but how does layer.redraw() work in practice?

layer = map.add(po.geoJson().url("hki.json"))
layer.reload()

...does not seem to work.

@mikeplis
Copy link

Just in case anyone happens to come across this looking for an answer to jensfinnas's question, it's layer.reload not layer.reload()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants