GithubHelp home page GithubHelp logo

diversoft / leaflet.canvaslayer.field Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ihcantabria/leaflet.canvaslayer.field

0.0 1.0 0.0 20.18 MB

Load and style Raster files in Leaflet (geotiff & asciigrid)

Home Page: https://ihcantabria.github.io/Leaflet.CanvasLayer.Field/

License: Other

JavaScript 99.38% HTML 0.62%

leaflet.canvaslayer.field's Introduction

Leaflet.CanvasLayer.Field

A plugin for LeafletJS that adds layers to visualize fields (aka Rasters) from ASCIIGrid or GeoTIFF files (EPSG:4326).

Leaflet.CanvasLayer.Field EXAMPLES

It includes:

  • L.CanvasLayer.ScalarField - a "typical" raster layer (from scalars such as DTM, temperature...) that can be rendered with different color scales and arrows.
  • L.CanvasLayer.VectorFieldAnim - an animated layer representing a vector field (wind, currents...), based on the excellent earth by Cameron Becarrio

This plugin extends L.CanvasLayer Leaflet Plugin by Stanislav Sumbera and uses geotiff.js by Fabian Schindler. For the 'arrow' renderer, it includes a modified portion of leaflet-geotiff by Stuart Matthews.

Demo

The figures below show the results for three basic layers, showing Currents in the Bay of Santander (Spain)

Example

Example

If you want to have a quick testing environment, have a look at these snippets at codepen.io:

Instructions

Basic Usage

  1. Get the JavaScript file. You can grab a copy from ongoing work at leaflet.canvaslayer.field.js. If you prefer to work locally with npm, then go with npm install leaflet-canvaslayer-field --save. Every version is automatically published to unpkg CDN (last version at: https://unpkg.com/leaflet-canvaslayer-field/dist/leaflet.canvaslayer.field.js)

  2. Include the JavaScript dependencies in your page:

    <!-- CDN references -->
    <script src="//npmcdn.com/[email protected]/dist/leaflet.js"></script>

    <script src="//cdnjs.cloudflare.com/ajax/libs/chroma-js/1.3.4/chroma.min.js"></script>
    <script src="//d3js.org/d3.v4.min.js"></script>
    <script src="//npmcdn.com/[email protected]/dist/geotiff.js"></script> <!-- optional -->

    <!-- Plugin -->
    <script src="https://ihcantabria.github.io/Leaflet.CanvasLayer.Field/dist/leaflet.canvaslayer.field.js"></script>
  1. Prepare a Raster File with your favourite GIS tool, using EPSG:4326 (ASCII Grid or GeoTIFF format)

  2. Create a ScalarField layer and add it to the map, using your raster files as source (e.g. this .asc)

d3.text("https://ihcantabria.github.io/Leaflet.CanvasLayer.Field/data/Bay_Speed.asc", function (asc) {
    var s = L.ScalarField.fromASCIIGrid(asc);
    var layer = L.canvasLayer.scalarField(s).addTo(map);

    map.fitBounds(layer.getBounds());
});
  1. Or try the VectorFieldAnim layer, adding also a popup (previously you have to prepare 2 raster files, with 'u' and 'v' components in 'm/s'):
d3.text('https://ihcantabria.github.io/Leaflet.CanvasLayer.Field/data/Bay_U.asc', function(u) {
    d3.text('https://ihcantabria.github.io/Leaflet.CanvasLayer.Field/data/Bay_V.asc', function(v) {
        let vf = L.VectorField.fromASCIIGrids(u, v);
        let layer = L.canvasLayer.vectorFieldAnim(vf).addTo(map);
        map.fitBounds(layer.getBounds());

        layer.on('click', function(e) {
            if (e.value !== null) {
                let vector = e.value;
                let v = vector.magnitude().toFixed(2);
                let d = vector.directionTo().toFixed(0);
                let html = (`<span>${v} m/s to ${d}&deg</span>`);
                let popup = L.popup()
                    .setLatLng(e.latlng)
                    .setContent(html)
                    .openOn(map);
            }
        });
    });
});

Developers

  • This plugin works with Leaflet >=v1.0.0
  • node & npm are needed to build and test the plugin, and it uses webpack 2 as module bundler. To use it just:
npm install
npm run start
  • Navigate to docs/index.html for some examples.

License

Licensed under the GNU General Public License v3.0

This software currently includes a copy of:

At runtime it requires:

leaflet.canvaslayer.field's People

Contributors

claustres avatar victorvelarde 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.