Giter Club home page Giter Club logo

mapbox-animation's Introduction

Animate a GeoJSON source easily with Mapbox GL

Live Demo

Mapbox animation features demo

The code of the demo is in the "example" folder.

Installation

Like regular mapbox-gl, either include the source file

<script type="text/javascript" src="http://misterfresh.github.io/mapbox-animation/mapbox-gl.js" charset="utf-8"></script>

or install the npm package

npm install mapbox-animation

Usage

map.getSource('vehicles').animate(1000);  //To activate animation for this source with a delay of 1000ms
var vehiclesPositions = {
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [-76.93238901390978, 38.913188059745586]
        },
        "properties": {
            "title": "Bicycle",
            "marker-symbol": "bicycle",
            "nextPosition": [-76.83238901390978, 38.813188059745586]
        }
    }, {
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [-77.13238901390978, 38.813188059745586]
        },
        "properties": {
            "title": "Car",
            "marker-symbol": "car",
            "nextPosition": [-76.97238901390978, 38.973188059745586]
        }
    }]
};

map.getSource('vehicles').setData(vehiclesPositions);  //markers will animate

After running the animate method, set the "nextPosition" property, and the markers will smoothly transition to the specified coordinates.

Mapbox-gl extension

This module is mapbox-gl, extended with a new "animate" method for GeoJSON sources.

GeoJSONSource.animate(delay, transitionStyle);

The delay parameter is the duration of the transition. It is optional and defaults to false (no animation). The transition style parameter is optional, it defaults to "linear". Other available styles are "none", "bezier", "midpoints", and "circle". These other styles will only work if the "previousPosition" property is also set, because they require three points.

Performance

The following layer options seemed to give the best performance:

 map.addLayer({
    "id": "layerId",
    "type": "symbol",
    "source": "sourceId",
    "layout": {
        "icon-allow-overlap": true,
        "icon-ignore-placement": true,
        "text-allow-overlap": true,
        "text-optional": true,
    }
});

Animations were very smooth on iPhone 6S, average on 2 year-old macbook Air, and choppy on the retina macbook pro.

For more information, refer to the official mapbox-gl-js repository.

mapbox-animation's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.