All Projects → manubb → Leaflet.pixioverlay

manubb / Leaflet.pixioverlay

Licence: mit
Bring Pixi.js power to Leaflet maps

Projects that are alternatives of or similar to Leaflet.pixioverlay

Gown.js
UI system for pixi.js inspired by feathers-ui
Stars: ✭ 195 (-26.14%)
Mutual labels:  webgl, pixijs, pixi
Pixi Haxe
Externs of Pixi.js for Haxe
Stars: ✭ 175 (-33.71%)
Mutual labels:  webgl, pixijs, pixi
Pixi Seed
Pixi.js project seed with ES6 and webpack
Stars: ✭ 149 (-43.56%)
Mutual labels:  webgl, pixijs, pixi
Pixi.js
The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.
Stars: ✭ 34,982 (+13150.76%)
Mutual labels:  webgl, pixijs, pixi
Leaflet-active-area
A Leaflet plugin to center the map not in the center of the map but inside a DIV. Useful for responsive design.
Stars: ✭ 99 (-62.5%)
Mutual labels:  leaflet, leaflet-plugins
Tangram
WebGL map rendering engine for creative cartography
Stars: ✭ 1,964 (+643.94%)
Mutual labels:  webgl, leaflet
Expo Pixi
Tools for using pixi.js in Expo
Stars: ✭ 253 (-4.17%)
Mutual labels:  webgl, pixi
Leaflet.TileLayer.Fallback
Replaces missing Tiles by scaled lower zoom Tiles
Stars: ✭ 29 (-89.02%)
Mutual labels:  leaflet, leaflet-plugins
Phaser Kinetic Scrolling Plugin
Kinetic Scrolling plugin for Canvas using Phaser Framework
Stars: ✭ 117 (-55.68%)
Mutual labels:  webgl, pixijs
leaflet-defaulticon-compatibility
Retrieve all Leaflet Default Icon options from CSS, in particular all icon images URL's, to improve compatibility with bundlers and frameworks that modify URL's in CSS.
Stars: ✭ 71 (-73.11%)
Mutual labels:  leaflet, leaflet-plugins
esri-leaflet-vector
Display ArcGIS Online vector basemaps w/ Esri Leaflet
Stars: ✭ 39 (-85.23%)
Mutual labels:  leaflet, leaflet-plugins
harp-leaflet
Leaflet plugin for harp.gl
Stars: ✭ 16 (-93.94%)
Mutual labels:  leaflet, leaflet-plugins
leaflet-area-select
Control to just select an area and provide bbox for it
Stars: ✭ 27 (-89.77%)
Mutual labels:  leaflet, leaflet-plugins
Leaflet.MarkerCluster.LayerSupport
Sub-plugin for Leaflet.markercluster plugin; brings compatibility with Layers Control and other plugins
Stars: ✭ 53 (-79.92%)
Mutual labels:  leaflet, leaflet-plugins
Creature webgl
2D Skeletal Animation WebGL Runtimes for Creature ( PixiJS, PhaserJS, ThreeJS, BabylonJS, Cocos Creator )
Stars: ✭ 140 (-46.97%)
Mutual labels:  webgl, pixijs
pixi-shim
PIXI.js Back-End "shim". For mocking Canvas in Node.js with ❤️
Stars: ✭ 45 (-82.95%)
Mutual labels:  pixijs, pixi
pixi-omber-gltf2-vector
Pixi.js library for using vector art created in Omber that's saved in glTF 2.0 format
Stars: ✭ 13 (-95.08%)
Mutual labels:  pixijs, pixi
Morph
Morph is a free and open-source tool for creating designs, animations or interactive visualizations from data.
Stars: ✭ 107 (-59.47%)
Mutual labels:  webgl, pixijs
pixi-miniprogram
一个可运行于微信小程序的PIXI引擎,通过模拟window环境,有些功能小程序无法模拟,就直接修改了PIXI引擎代码,最终使得PIXI引擎正常运行在小程序上
Stars: ✭ 72 (-72.73%)
Mutual labels:  pixijs, pixi
pixijs-ts-boilerplate
Just another PixiJS Typescript Boilerplate with some basic functionalities
Stars: ✭ 54 (-79.55%)
Mutual labels:  pixijs, pixi

Leaflet.PixiOverlay

An overlay class for Leaflet, a JS library for interactive maps. Allows drawing overlay using Pixi.js, a JavaScript library for drawing using WebGL that seamlessly falls back to HTML5's canvas if needed. Thanks to Leaflet.D3SvgOverlay for inspiration.

screenshot

Features

  • No limitations to polylines, circles or geoJSON. Draw whatever you want with Pixi.js
  • No need to reproject your geometries on zoom, this is done using scaling
  • Zoom animation where Leaflet supports it

Compatible with Leaflet 0.7.x and 1.x

Demo

A very basic demo.

Largest US cities (1000 animated markers).

French cities (36700 animated markers).

One million markers

Rotating markers with constant size during zoom

French presidential 2017 election results: first round and second round (36000 polygons).

French legislative 2017 election results: first round and second round (36000 polygons).

(graph-draw is used to display boundaries in the election demos when rendered in WebGL)

Installation

Leaflet.PixiOverlay is available as a npm package:

npm install leaflet-pixi-overlay

or can be included in a page with jsDelivr CDN.

Usage

Include Pixi.js and the PixiOverlay libraries:

    <script src="pixi.min.js"></script>
    <script src="L.PixiOverlay.min.js"></script>

Create a map:

    var map = L.map(...);

Create an overlay:

    var pixiOverlay = L.pixiOverlay(function(utils) {
        // your drawing code here
    }, new PIXI.Container());

Add it to the map:

    pixiOverlay.addTo(map);

Examples

Draw a marker

var loader = new PIXI.loaders.Loader();
loader.add('marker', 'img/marker-icon.png');
loader.load(function(loader, resources) {
    var markerTexture = resources.marker.texture;
    var markerLatLng = [51.5, -0.09];
    var marker = new PIXI.Sprite(markerTexture);
    marker.anchor.set(0.5, 1);

    var pixiContainer = new PIXI.Container();
    pixiContainer.addChild(marker);

    var firstDraw = true;
    var prevZoom;

    var pixiOverlay = L.pixiOverlay(function(utils) {
        var zoom = utils.getMap().getZoom();
        var container = utils.getContainer();
        var renderer = utils.getRenderer();
        var project = utils.latLngToLayerPoint;
        var scale = utils.getScale();

        if (firstDraw) {
            var markerCoords = project(markerLatLng);
            marker.x = markerCoords.x;
            marker.y = markerCoords.y;
        }

        if (firstDraw || prevZoom !== zoom) {
            marker.scale.set(1 / scale);
        }

        firstDraw = false;
        prevZoom = zoom;
        renderer.render(container);
    }, pixiContainer);
    pixiOverlay.addTo(map);
});

Draw a triangle

var polygonLatLngs = [
    [51.509, -0.08],
    [51.503, -0.06],
    [51.51, -0.047],
    [51.509, -0.08]
];
var projectedPolygon;
var triangle = new PIXI.Graphics();

var pixiContainer = new PIXI.Container();
pixiContainer.addChild(triangle);

var firstDraw = true;
var prevZoom;

var pixiOverlay = L.pixiOverlay(function(utils) {
    var zoom = utils.getMap().getZoom();
    var container = utils.getContainer();
    var renderer = utils.getRenderer();
    var project = utils.latLngToLayerPoint;
    var scale = utils.getScale();

    if (firstDraw) {
        projectedPolygon = polygonLatLngs.map(function(coords) {return project(coords);});
    }
    if (firstDraw || prevZoom !== zoom) {
        triangle.clear();
        triangle.lineStyle(3 / scale, 0x3388ff, 1);
        triangle.beginFill(0x3388ff, 0.2);
        projectedPolygon.forEach(function(coords, index) {
            if (index == 0) triangle.moveTo(coords.x, coords.y);
            else triangle.lineTo(coords.x, coords.y);
        });
        triangle.endFill();
    }
    firstDraw = false;
    prevZoom = zoom;
    renderer.render(container);
}, pixiContainer);
pixiOverlay.addTo(map);

API

Factory method

L.pixiOverlay(<function> drawCallback, <PIXI.Container> container, <options> options?)
  • drawCallback - callback to draw/update overlay contents.
  • container - a Pixi container (a subclass of PIXI.Container).
  • options - overlay options object.

Drawing callback function

drawCallback(utils, eventOrCustomData)
  • utils - helper object. Contains methods to work with layers coordinate system and scaling.
  • eventOrCustomData - Contains either the Leaflet event that causes the redraw (moveend event) or a plain object {type: 'add'} when the pixi layer is added to the map or the argument of a redraw call.

Overlay options object

available fields:

  • padding - (number; defaults to 0.1) How much to extend the drawing area around the map view (relative to its size).
  • forceCanvas - (bool; defaults to false) Force use of a 2d-canvas for rendering.
  • doubleBuffering - (bool; default to false) Activate double buffering to prevent flickering when refreshing display on some devices (especially iOS devices). This field is ignored if rendering is done with 2d-canvas.
  • resolution - (number; defaults to 2 on retina devices and 1 elsewhere) Resolution of the renderer.
  • projectionZoom - (function(map): Number; defaults to function that returns the average of map.getMinZoom() and map.getMaxZoom()) returns the projection zoom level. Customizing this option can help if you experience visual artifacts.
  • pane - (string; defaults to 'overlayPane') The Leaflet pane where the overlay container is inserted.
  • destroyInteractionManager - (bool; defaults to false) Destroy PIXI Interaction Manager. This is useful when you do not need to use PIXI interaction.
  • autoPreventDefault - (bool; defaults to true) Customize PIXI Interaction Manager autoPreventDefault property. This option is ignored if destroyInteractionManager is true. This should be set to false in most situations to let all dom events flow from PIXI to leaflet but it is set by default for compatibility reason.
  • preserveDrawingBuffer - (bool; defaults to false) Enables drawing buffer preservation, enable this if you need to call toDataUrl on the webgl context.
  • clearBeforeRender - (bool; defaults to true) This sets if the renderer will clear the canvas or not before the new render pass.
  • shouldRedrawOnMove - (function(e: moveEvent): Boolean; defaults to function () {return false;}) Move events trigger a redraw when this function returns true. For example using function (e) {return e.flyTo || e.pinch;} will trigger redraws during flyTo animation and pinch zooms.

Utils object

available methods:

  • latLngToLayerPoint(latLng, zoom?) - (function) returns L.Point projected from L.LatLng in the coordinate system of the overlay.
  • layerPointToLatLng(point, zoom?) - (function) returns L.LatLng projected back from L.Point into the original CRS.
  • getScale(zoom?) - (function) return the current scale factor of the overlay or the scale factor associated to zoom value.
  • getRenderer() - (function) return the current PIXI renderer.
  • getContainer() - (function) return the PIXI container used in the overlay.
  • getMap() - (function) return the current map.

Instance methods

  • redraw(data) - (function) trigger a refresh of the layer. data is passed as second argument of drawCallback function. This is useful for example when you modify something in the container or if you want to animate using PIXI.ticker.Ticker.

Changelog

1.8.1 (May 2, 2019)

  • Fix a pinch zoom regression introduced in 1.8.0

1.8.0 (Apr 30, 2019)

  • Add support for redrawing the layer during flyTo animations and pinch zooms. (This is disabled by default. See shouldRedrawOnMove option to enable it,)
  • Both [email protected] and [email protected] should be supported now.

1.7.0 (Mar 20, 2019)

1.6.0 (Nov 26, 2018)

  • Add preserveDrawingBuffer and clearBeforeRender options

1.5.0 (Apr 13, 2018)

  • Bug fixes
  • Add options for PIXI Interaction Manager
  • Improved documentation

1.4.2 (Mar 27, 2018)

  • Improved behavior when doubleBuffering is enabled
  • Remove event listeners on layer remove wih Leaflet 0.7.x

1.4.0 (Mar 25, 2018)

  • Add second argument to drawCallback, improving control over redraw logic
  • No need to recompute container transform on redraw calls (performance improvement)

1.3.0 (Jan 22, 2018)

  • Add redraw method

1.2.0 (Jan 20, 2018)

  • Add doubleBuffering option to get rid of flickering on iOS devices

1.1.3 (Jan 20, 2018)

1.0.0 (Sep 2, 2017)

  • Initial release.

License

This code is provided under the MIT License (MIT).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].