Code Monkey home page Code Monkey logo

flowmap.gl's Introduction

flowmap.gl

Flow map drawing layer for deck.gl. Can be used for visualizing movement of people (e.g. migration) or objects between geographic locations. The layer is rendered in WebGL and can handle large numbers of flows with a good rendering performance.

Check out the live examples.

Features

Given an array of locations and an array of flows between these locations the layer will do the following:

  • Represent the flows as lines of varying thickness depending on the flow magnitudes
  • The flow lines are sorted so that the larger flows are drawn above
  • GeoJSON geometries of the location areas are rendered as polygons
  • Total incoming and outgoing flows for the locations are calculated and represented as circles of varying sizes.

Location totals

Both the incoming and outgoing totals for the locations are represented. A darker outline means that there are more incoming flows, a lighter outline means that there are more outgoing flows.

For instance, below we compare between the evening and the morning commuting behaviors of a large city:

Difference mode

The layer can be used to show the difference between two moments in time.

Usage

Here's a usage example:

import DeckGL from 'deck.gl';
import MapGL from 'react-map-gl';
import FlowMapLayer from 'flowmap.gl';

const colors = {
  flows: {
    max: '#137CBD',
  },
  locationAreas: {
    outline: 'rgba(92,112,128,0.5)',
    normal: 'rgba(187,187,187,0.5)',
    selected: 'rgba(217,130,43,0.5)',
  },
};

class MyFlowMap extends Component {
  render() {
    const flowMapLayer = new FlowMapLayer({
      id: 'flow-map-layer',
      colors,
      locations: [...],   // array of GeoJSON features of location areas
      flows: [...],       // array of Flow objects
      getLocationId: l => l.id,
      getLocationCentroid: l => l.properties.centroid,
      getFlowOriginId: f => f.origin,
      getFlowDestId: f => f.dest,
      getFlowMagnitude: f => f.magnitude,
      showTotals: true,
      showLocationAreas: true,
      locationCircleSize: 3,
      showLocationAreas: true,
      getFlowMagnitude: f => f.count,
      varyFlowColorByMagnitude: true,
      showTotals: true,
    });
  
    return (
      <MapGL {...viewport} width={width} height={height} mapboxApiAccessToken={mapboxAccessToken}>
        <DeckGL {...viewport} width={width} height={height} layers={[flowMapLayer]} />
      </MapGL>
    );
  }    
}    

The full list of supported props:

interface Props {
  id: string;
  colors: Colors | DiffColors;
  locations: Locations;
  flows: Flow[];
  fp64?: boolean;
  onClick?: PickingHandler<FlowLayerPickingInfo>;
  onHover?: PickingHandler<FlowLayerPickingInfo>;
  getLocationId?: LocationAccessor<string>;
  getLocationCentroid?: LocationAccessor<[number, number]>;
  getLocationTotalIn?: LocationAccessor<number>;
  getLocationTotalOut?: LocationAccessor<number>;
  getFlowOriginId?: FlowAccessor<string>;
  getFlowDestId?: FlowAccessor<string>;
  getFlowMagnitude?: FlowAccessor<number>;
  showTotals?: boolean;
  locationCircleSize?: number;
  showLocationAreas?: boolean;
  varyFlowColorByMagnitude?: boolean;
  selectedLocationIds?: string[];
  highlightedLocationId?: string;
  highlightedFlow?: Flow;
  visible?: boolean;
  opacity?: number;
  pickable?: boolean;
  fp64?: boolean;
  updateTriggers?: UpdateTriggers;
}

Here's the code for the complete static example and a more complex interactive example.

Developing

Create an .env file in the project root containing one line:

MapboxAccessToken=<your-mapbox-access-token>

Then, run:

npm install
npm start
open http://localhost:6006 to open storybook

Acknowledgements

Many thanks to Philippe Voinov for his help with the first version of the FlowLinesLayer.

flowmap.gl's People

Contributors

fnberta avatar ilya-vassilenko avatar ilyabo 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.