Giter Site home page Giter Site logo

leaflet-geojson-stream's Introduction

leaflet-geojson-stream

Stream GeoJSON features into a Leaflet layer.

usage

With browserify

npm install --save leaflet-geojson-stream

Otherwise

curl https://raw.github.com/tmcw/leaflet-geojson-stream/master/leafletgeojsonstream.js > leafletgeojsonstream.js

api

lgs.ajax(url: string, layer: L.geoJson instance)

Request all features from a given url with hyperquest and add them incrementally to layer. Returns a stream of feature objects that also emits end on completion.

lgs.layerPipe(layer: L.geoJson instance)

Given a L.geoJson instance, return a writable stream that accepts GeoJSON Feature objects.

example

var leafletStream = require('leaflet-geojson-stream'),
    map = L.map('map').setView([0, 0], 2),
    gj = L.geoJson().addTo(map);

leafletStream.ajax('/points.geojson', gj)
    .on('end', function() {
        alert('all done!');
    });

To run the prepackaged example:

npm install
cd example
node server.js

And open http://localhost:3000/

build

npm install
npm run-script build

How

A simple abstraction on top of geojson-stream, which is in turn just a bit of sugar on JSONStream. Regular old XMLHttpRequest allows for partial replies under the magical 'status code 3'. This doesn't use WebSockets or anything else fancy.

Caveats

  • Some servers will send huge chunks in their responses. This depends on a keep-alive connection with reasonable bites.
  • The GeoJSON object returned by the server currently must be a FeatureCollection at its root.

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.