Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

leaflet-canvas-layer

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leaflet-canvas-layer

Leaflet plugin for showing a canvas overlay in a leaflet map. This project is a fork and a typescript translation from https://github.com/Sumbera/gLayers.Leaflet

  • 1.0.8
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
410
decreased by-40.58%
Maintainers
1
Weekly downloads
 
Created
Source

gLayers.Leaflet

generic map layers for leaflet 0.7 and 1.0-rc, moving from original GIST here https://gist.github.com/Sumbera/11114288 to this repo.

L.CanvasLayer - full screen generic canvas layer for leaflet

##API

methodsdescription
needRedrawwill schedule next frame call for drawLayer
delegate(object)optionaly set receiver of the events if not 'inheriting' from L.CanvasLayer
eventsdescription
onLayerDidMountafter layer is attached/added to the map
onLayerWillUnmountbefore layer is removed from the map
onDrawLayer(info)when layer is drawn , info contains view parameters like bounds, size, canvas etc.
note : events will be called only if presented on the 'subclass' or if delegate(receiver) is set

Examples

Basic usage

        L.canvasLayer()
            .delegate(this) // -- if we do not inherit from L.CanvasLayer  we can setup a delegate to receive events from L.CanvasLayer
            .addTo(leafletMap);
      
        function onDrawLayer(info) {
            var ctx = info.canvas.getContext('2d');
            ctx.clearRect(0, 0, info.canvas.width, info.canvas.height);
            ctx.fillStyle = "rgba(255,116,0, 0.2)";
            for (var i = 0; i < data.length; i++) {
                var d = data[i];
                if (info.bounds.contains([d[0], d[1]])) {
                    dot = info.layer._map.latLngToContainerPoint([d[0], d[1]]);
                    ctx.beginPath();
                    ctx.arc(dot.x, dot.y, 3, 0, Math.PI * 2);
                    ctx.fill();
                    ctx.closePath();
                }
            }
        };

Custom layer

  
          myCustomCanvasDraw= function(){
              this.onLayerDidMount = function (){      
                 // -- prepare custom drawing    
              };
              this.onLayerWillUnmount  = function(){
                 // -- custom cleanup    
              };
              this.setData = function (data){
                // -- custom data set
                this.needRedraw(); // -- call to drawLayer
              };
              this.onDrawLayer = function (viewInfo){
              // -- custom  draw
              }
              
          }
          
          myCustomCanvasDraw.prototype = new L.CanvasLayer(); // -- setup prototype 
          
          var myLayer = new myCustomCanvasDraw();
          myLayer.addTo(leafletMap);

Other useful full view Leaflet Canvas sources here:

FAQs

Package last updated on 03 Oct 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc