npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

leaflet-canvas-geojson

v0.0.8

Published

leaflet layer for rendering vectors on single canvas layer

Downloads

96

Readme

leaflet-canvas-geojson

A HTML canvas layer to render large amounts of geojson data.

Basic Usage

/**
 * note unlike most DOM based map event handling which return only
 * the top feature, the L.CanvasGeojsonLayer returns all features
 * the are moused over or clicked.
 */
var canvasLayer = new L.CanvasGeojsonLayer({
    onMouseOver : function(features) {
        // handle mouseover events
    },
    onMouseOut : function(features) {
        // handle mouseout events
    },
    onClick : function(features) {
        // handle mouse click events
    }
});

// add to map
canvasLayer.addTo(map);

/**
 * This is just shorthand for creating a bunch of L.CanvasFeature 
 * or L.CanvasFeatureCollection objects from your geojson
 */
canvasLayer.addCanvasFeatures(L.CanvasFeatureFactory(geojsonData));

// first render
canvasLayer.render();

Rendering

There are two ways two the geojson:

  1. Assign a renderer to the layer
canvasLayer.renderer = function() {}
  1. Assign a renderer to the L.CanvasFeature
canvasFeature.renderer = function() {}

If a CanvasFeature render is provided, it will be used instead of the layer render.

The renderer function should look like:

/**
 * ctx - The canvas elements 2d context
 * xyPoints - either object or array
 *  for Point: {x: number, y: number}
 *  for Linestring: array of points
 *  for Polygon: array of points
 *  for Multipolygon: array of Polygons
 * map - canvas layers map
 * geojson - actual geojson object passed to L.CanvasFeature
 *
 * The function will be called in scope of the CanvasFeature.  So
 * [this] will access the CanvasFeature
 */
function render(ctx, xyPoints, map, geojson) {
    // to stuff here
}

See /src/defaultRenderer/index.js for full example. This is also the layer default if no renderer is assigned.

Layer Methods

addCanvasFeatures(features: [L.CanvasFeature | L.CanvasFeatureCollection])

Add array of CanvasFeatures to layer

addCanvasFeature(feature: L.CanvasFeature | L.CanvasFeatureCollection)

Add single L.CanvasFeature or L.CanvasFeatureCollection

removeCanvasFeature(feature: L.CanvasFeature | L.CanvasFeatureCollection)

remove single L.CanvasFeature or L.CanvasFeatureCollection

removeAll()

Remove all canvas layer features

getCanvasFeatureForGeojson(geojson: Object)

Returns a L.CanvasFeature or L.CanvasFeatureCollection. Useful for when you need to lookup a Feature to remove or update the visibility

render()

Render to GeoJSON

CanvasFeature Visibility

If you want to hide/show a feature, the recommended method is to use the visible flag with the associated L.CanvasFeature. Not only will the Feature not be drawn, but this flag will save the layer from reprojecting the feature.