mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 09:12:52 +00:00
18 lines
564 B
JavaScript
18 lines
564 B
JavaScript
import * as d3 from 'd3';
|
|
|
|
export function svgPath(projection, graph, polygon) {
|
|
var cache = {},
|
|
clip = d3.geoIdentity().clipExtent(projection.clipExtent()).stream,
|
|
project = projection.stream,
|
|
path = d3.geoPath()
|
|
.projection({stream: function(output) { return polygon ? project(output) : project(clip(output)); }});
|
|
|
|
return function(entity) {
|
|
if (entity.id in cache) {
|
|
return cache[entity.id];
|
|
} else {
|
|
return cache[entity.id] = path(entity.asGeoJSON(graph));
|
|
}
|
|
};
|
|
}
|