@silen/leaflet-canvas
TypeScript icon, indicating that this package has built-in type declarations

6.1.1 • Public • Published

@silen/leaflet-canvas

Allows rendering to canvas using custom HtmlElement elements.

install

npm i @silen/leaflet-canvas

or

yarn add @silen/leaflet-canvas

or

pnpm add @silen/leaflet-canvas

usage

options

  • tolerance: Number The default value is 0. How much to extend the click tolerance around a path/object on the map.

for test

const features = [
  {
    type: 'Feature',
    properties: {},
    geometry: {
      type: 'Polygon',
      coordinates: [
        [
          [19.458847045898438, 51.75944673648409],
          [19.46846008300781, 51.760296746815754],
          [19.475669860839844, 51.745738110429116],
          [19.462108612060547, 51.742868336510526],
          [19.458847045898438, 51.75944673648409],
        ],
      ],
    },
  },
  {
    type: 'Feature',
    properties: {},
    geometry: {
      type: 'Polygon',
      coordinates: [
        [
          [19.475669860839844, 51.745738110429116],
          [19.489574432373047, 51.74765119176804],
          [19.489402770996094, 51.75604653513805],
          [19.485111236572266, 51.76157173231003],
          [19.46846008300781, 51.760296746815754],
          [19.475669860839844, 51.745738110429116],
        ],
      ],
    },
  },
]

This is an image for test.

const imgSrc =
  'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMsAAAAYCAYAAABUUQmyAAAAAXNSR0IArs4c6QAAHOdJREFUeF7tXHl4G9W1n9FIM5KlkbVZki3Zlh0viR0vsQ0hCYnjELMvAZq2QGgCtEBfoW1KW7ZX1tLtlbK8Aq+BUgdaUupQmhIITQg4gSSExAlxnIAdy5YcS5ZkraN9RsvzmU/jb6xIdszXfk2/j/tXbN+5c++553fO7ywTVKFQ3Oz3+19BEARZtGjRW4WFhdf19PQk4OdzfAg0Gk2VXC7/ZTKZvNRqtYphv+Xl5UgsFns7EolsCAaDOgRB9iMIIm9oaNiG4/iNvb29kXP8XF9u7xyVAKrVau9wuVz/B/tbvnz5HgzDVv8HgAVVKpUNKIru8nq92hyy9SEI0oQgiH7yWLsRBCHb2treTafT138JlnNUE/8DtoXq9fpvOxyO52Gvq1at2p9KpdrPdbBoNBoSQZBDbre7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ydvJZPJrPO8jUigUd/n9fkgd501D63S69+Px+A/8fj9wcwFJkj8JBoPPwGa590GdJZFIvM61u0A3aDgc/mWedpdpYAmFQtfn4O2gkFcIhcIut9utnO1s8+fPPxAKhS7KavkBbl872UC6y+/3G7LX0Ol0EyRJVn3BFhiRWq3+scfjYYuG+cZkMOpLJpNQwOMaKQmSJKHB9Ccz1cmUSuW2dDr9fb/fD93KBZk6CxSFWc9SVFR0C6cfcwVLbW3tfTKZ7Dd5vo/iCpDQr8V1kkPseHumNpOvko4plcr7Jps3Z5THZAz6hkAg+HEgEABqJ4dYTCgUPgR6AnGaVCr9+bFjxzbOdt/w98lm34e9Xu8T0xopswP87IXAgmq12uc0Gs2aU6dOKfhFRECoyWTyuFyuV4LB4IO5+sdkMtl8mUz2AkEQF/C+g4hjGNYfDocfczqd7xiNRlE6ne632WwGo9H4jFgsZg/I7SXT89PFZW+qqqoewnH8qRzUCTwLdB1Dpk9aV1f3N6FQuG6Gbxuw5ubmlzUazdW5zlZeXg6tHltDodDGPHEDBvRToVD8PBAILOd9F0GXlpYejEajl55FJibf3QlKS0tbjUbjJih48r8lggeMRqODpukXU6nU41mKyYKYJMkt6XS6if+txqSRPO3xeB4cGRn5s8lkwpLJ5AC0Ks2bN+8Zs9l8DxezFBcX3z4+Pv4CvKepqeltpVK5Jl/MAndTUFCwd3BwEIJquqKi4kGVSnVGgM+/S5qm+1wuF1vfkMlkXolEUn4WMTF8WlJDkuS2WCxWyz8XiqIfh0KhJ9xu906VSiXGcfyQw+EwLVy48BW/3w8ZNrbTI9Pmc41SqXySIIgyTqaclzOZTDGLxfI3iqIgHQ2GJP3/zVS1zL0h/HAAAAAASUVORK5CYII='

This is the interface for implementing custom rendering using canvas.

const onFillContent = (ctx, layer) => {
  const img = document.createElement('img')
  img.src = imgSrc

  const { _pxBounds } = layer
  const minX = _pxBounds.min.x
  const minY = _pxBounds.min.y
  const maxX = _pxBounds.max.x
  const maxY = _pxBounds.max.y

  const width = maxX - minX
  const height = maxY - minY

  img.onload = () => {
    ctx.drawImage(img, minX, minY, width, height)
  }
}

es

For example.

import L from 'leaflet'
import '@silen/leaflet-canvas'

const renderGroup = new L.FeatureGroup()
map.addLayer(renderGroup)

const geoJson = L.geoJson(
  {
    type: 'FeatureCollection',
    features,
  },
  {
    onFillContent,
    onEachFeature: (feature, layer) => {
      renderGroup.addLayer(layer)
    },
  },
)

browser

Introduce external dependencies

<link
  rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet.min.css"
/>
<script src="https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet-src.js"></script>

Introduce this plugin.

<script src="https://unpkg.com/@silen/leaflet-canvas@latest"></script>

You can also download this plugin locally and then import it.

<script src="/path/@silen/leaflet-canvas@latest"></script>

Create a dom container to load the map

<div id="map" style="height: 300px;"></div>

Use it.

let selectedLayer
const map = L.map('map', {
  renderer: L.customCanvas(),
})

map.setView(new L.LatLng(51.75, 19.46667), 12)
map.addLayer(
  new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    minZoom: 8,
    maxZoom: 20,
  }),
)

const renderGroup = new L.FeatureGroup()
map.addLayer(renderGroup)

const geoJson = L.geoJson(
  {
    type: 'FeatureCollection',
    features,
  },
  {
    onFillContent,
    onEachFeature: (feature, layer) => {
      layer.on('click', handleLayerClick)
      renderGroup.addLayer(layer)
    },
  },
)

function highlightFeature(layer) {
  if (selectedLayer) {
    geoJson.resetStyle(selectedLayer)
  }
  selectedLayer = layer

  layer.setStyle({
    weight: 5,
    color: '#666',
    dashArray: '',
    fillOpacity: 0.7,
  })

  layer.bringToFront()
}

function handleLayerClick(event) {
  const layer = event.target

  highlightFeature(layer)
}

Readme

Keywords

Package Sidebar

Install

npm i @silen/leaflet-canvas

Weekly Downloads

184

Version

6.1.1

License

MIT

Unpacked Size

86.8 kB

Total Files

11

Last publish

Collaborators

  • silentsun