Socket
Book a DemoInstallSign in
Socket

@concord-consortium/react-leaflet-canvas-layer

Package Overview
Dependencies
Maintainers
9
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@concord-consortium/react-leaflet-canvas-layer

A canvas layer for react-leaflet

latest
npmnpm
Version
1.1.0
Version published
Maintainers
9
Created
Source

react-leaflet-canvas-layer

a canvas layer for react-leaflet.

install

yarn add react-leaflet-canvas-layer # yarn 
npm install react-leaflet-canvas-layer # npm 

Usage

import React from 'react';
import { render } from 'react-dom';
import { Map, TileLayer } from 'react-leaflet';
import CanvasLayer from 'react-leaflet-canvas-layer';

class App extends React.Component {
  drawMethod(info) {
    const ctx = info.canvas.getContext('2d');
    ctx.clearRect(0, 0, info.canvas.width, info.canvas.height);
    ctx.fillStyle = 'rgba(255,116,0, 0.2)';
    var point = info.map.latLngToContainerPoint([-37, 175]);
    ctx.beginPath();
    ctx.arc(point.x, point.y, 200, 0, Math.PI * 2.0, true, true);
    ctx.closePath();
    ctx.fill();
    ctx.stroke();
  }
  render() {
    return (
      <div>
        <Map center={[-37, 175]} zoom={13}>
          <CanvasLayer
            drawMethod={this.drawMethod}
          />
          <TileLayer
            url="https://cartodb-basemaps-{s}.global.ssl.fastly.net/dark_all/{z}/{x}/{y}{r}.png"
          />
        </Map>
      </div>
    );
  }
}

render(<App />, document.getElementById('app'));

API

CanvasLayer component props:

  • data: a custom dataset
  • drawMethod: required a custom render function e.g. (view) => { /*draw something*/} view contains parameters :map, canvas, bounds, size, zoom, center, corner, data.

License

MIT.

Keywords

react

FAQs

Package last updated on 21 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts