MCPcopy Create free account
hub / github.com/StephanGeorg/staticmaps / multiPolygonToSVG

Method multiPolygonToSVG

src/staticmaps.js:376–400  ·  view source on GitHub ↗

* Render MultiPolygon to SVG

(multipolygon)

Source from the content-addressed store, hash-verified

374 * Render MultiPolygon to SVG
375 */
376 multiPolygonToSVG(multipolygon) {
377 const shapeArrays = multipolygon.coords.map((shape) => shape.map((coord) => [
378 this.xToPx(geoutils.lonToX(coord[0], this.zoom)),
379 this.yToPx(geoutils.latToY(coord[1], this.zoom)),
380 ]));
381
382 const pathArrays = shapeArrays.map((points) => {
383 const startPoint = points.shift();
384
385 const pathParts = [
386 `M ${startPoint[0]} ${startPoint[1]}`,
387 ...points.map((p) => `L ${p[0]} ${p[1]}`),
388 'Z',
389 ];
390
391 return pathParts.join(' ');
392 });
393
394 return `<path
395 d="${pathArrays.join(' ')}"
396 style="fill-rule: inherit;"
397 stroke="${multipolygon.color}"
398 fill="${multipolygon.fill ? multipolygon.fill : 'none'}"
399 stroke-width="${multipolygon.width}"/>`;
400 }
401
402 /**
403 * Render Polyline to SVG

Callers 1

drawFeaturesMethod · 0.95

Calls 2

xToPxMethod · 0.95
yToPxMethod · 0.95

Tested by

no test coverage detected