Closed HarryStevens closed 6 years ago
var map = swiftmap.map()
.projection("mercator")
.polygons(JSON, key)
.draw()
.drawScheme(scheme)
.polygons(JSON)
.drawBoundary()
.points(JSON)
.drawLabels(d => d.name);
This is fine, but what if you want to update the first polygons? Either give them a name as the third argument passed to polygons(), or assign them to a variable.
A:
var map = swiftmap.map()
.projection("mercator")
.polygons(JSON, d => d.state, "states")
.draw()
.drawScheme(scheme)
.points(newJSON, d => d.city, "cities")
.drawLabels(d => d.city);
map.subunits.states.style("fill", "red");
map.places.cities.attr("r", 10);
B:
var map = swiftmap.map()
.projection("mercator");
var states = map
.polygons(JSON, d => d.state)
.draw()
.drawScheme(scheme);
map
.points(newJSON, d => d.city)
.drawLabels(d => d.city);
states.subunits.style("fill", "red"); // refers to the states polygons
map.places.attr("r", 10); // refers to the most recently draw newJSON
I think option B will be easier to reason about.
Finally went with more of an option A approach.
Ideally, you could simply invoke map.geometry() again and again. But maybe there need to be some methods like map.addLayer() or map.subGeometry().