Public
Edited
Aug 30, 2023
Fork of Leaflet POC
Insert cell
Insert cell
L.SVG.prototype
Insert cell
leafletGeoJson = L.geoJSON(testFeature, {
style: function (feature) {
return {color: "#ff00ff"};
}
});
Insert cell
leafletGeoJson._path
Insert cell
map = {
const height = width * mapSize.height / mapSize.width;
const container = html`<div style="height:${height}px;">`;
yield container;

const bounds = L.latLngBounds(L.latLng(0, 0), L.latLng(mapSize.height, mapSize.width));
const map = L.map(container, {
crs: wrappingCrs,
minZoom: -30,
zoomSnap: 0,
renderer: clippedSVG
});
L.geoJSON(geoJson, {
style: function (feature) {
return {color: "#ff00ff"};
}
}).addTo(map)
// leafletGeoJson.addTo(map);
map.fitBounds(bounds);
}
Insert cell
L.Util.stamp
Insert cell
clippedSVG._layers
Insert cell
clippedSVG = new ClippedSVG()
Insert cell
L.Util.splitWords
Insert cell
ClippedSVG = {
const { stamp, splitWords } = L.Util;
const { create } = L.SVG;
const parent = L.SVG.prototype;
return L.SVG.extend({
options: {
padding: 0.1,
continuous: true,
},
_initContainer() {
parent._initContainer.call(this);
this._defs = create("defs");
this._container.prepend(this._defs);
},
_destroyContainer() {
parent._destroyContainer.call(this);
delete this._defs;
},
_initPath(layer) {
const layerStamp = stamp(layer);

const clipPath = layer._clipPath = create('clipPath');
clipPath.setAttribute("id", `clip_${layerStamp}`);
const path = layer._path = create('path');
path.setAttribute("id", `path_${layerStamp}`);
clipPath.append(path);
const use = layer._use = create('use');
use.setAttribute("href", "#" + layer._path.id);

if (layer.options.className) {
path.classList.add(...splitWords(layer.options.className));
}
if (layer.options.interactive) {
path.classList.add('leaflet-interactive');
}
this._updateStyle(layer);
this._layers[layerStamp] = layer;
},
_addPath(layer) {
if (!this._rootGroup || !this._defs) { this._initContainer(); }
this._defs.appendChild(layer._clipPath);
this._rootGroup.appendChild(layer._use);
layer.addInteractiveTarget(layer._use);
},
_removePath(layer) {
layer._clipPath.remove();
layer._path.remove();
layer.removeInteractiveTarget(layer._use);
delete this._layers[stamp(layer)];
},

_updateStyle(layer) {
parent._updateStyle.call(this, layer);
const use = layer._use,
options = layer.options;

if (options.clip || options.clip === undefined) {
use.setAttribute('clip-path', `url(#${layer._clipPath.id})`);
}
else {
use.removeAttribute('clip-path');
}
},

_bringToFront(layer) {
L.DomUtil.toFront(layer._use);
},
_bringToBack(layer) {
L.DomUtil.toBack(layer._use);
}
});
}
Insert cell
new L.Bounds()
Insert cell
Insert cell
geoJson
Insert cell
L.geoJSON({ type: "FeatureCollection", features: [testFeature] })
Insert cell
L.CRS.Simple.projection.bounds
Insert cell
wrappingCrs.infinite
Insert cell
mapSize = ({ width: 2048, height: 904 });
Insert cell
wrappingCrs = {
const simple = L.CRS.Simple;
const wrappingCrs = L.extend({}, simple, {
wrapLng: [0, mapSize.width],
infinite: true,
projection: {
project: function(latLng) {
const latLng2 = L.latLng(mapSize.height - latLng.lat, latLng.lng);
return simple.projection.project.call(this, latLng2);
},
unproject: function(point) {
const latLng = simple.projection.unproject.call(this, point);
return L.latLng(mapSize.height - latLng.lat, latLng.lng);
},
bounds: {
min: { x: 0, y: 0 },
max: { x: mapSize.width, y: mapSize.height }
}
}
})
return wrappingCrs;
}
Insert cell
svg`<svg viewBox="0 0 100 100">
<defs>
<clipPath id="myClip">
<circle id="circle" cx="40" cy="35" r="35" />
</clipPath>
</defs>
<g transform="scale(1 0.5)">>
<use clip-path="url(#myClip)" href="#circle" fill="red" stroke="blue" stroke-width="10" />
</g>
</svg>`
Insert cell
Insert cell
import { sampleGeoJson as geoJson } from "053fea843f886be5"
Insert cell
L = require('leaflet@1.2.0')
Insert cell
html`<link href='${resolve('leaflet@1.2.0/dist/leaflet.css')}' rel='stylesheet' />`
Insert cell
turf = await require('@turf/turf@6.5.0/turf.min.js')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more