Giter Site home page Giter Site logo

vrdev / leaflet.layerindex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from makinacorpus/leaflet.layerindex

0.0 0.0 0.0 29 KB

Spatial index of layer objects using RTree.js

Home Page: https://makinacorpus.github.io/Leaflet.LayerIndex/

License: MIT License

JavaScript 88.88% HTML 11.12%

leaflet.layerindex's Introduction

Leaflet.LayerIndex

Efficient spatial index for Leaflet layers. It works recursively for L.FeatureGroup objects.

Requires the Magnificient RTree.js

Check out the live demo

Usage

On L.Map objects


    L.Map.include(L.LayerIndexMixin);

    var map = L.map(...);
    ...
    var layer = L.GeoJSON(data).addTo(map);
    map.indexLayer(layer);

    // Search visible features for example
    map.on('moveend', function () {
        var shown = map.search(map.getBounds());
        console.log(shown.length + ' objects shown.');
    });

    // remove the spatial index when the layer is unused
    map.unindexLayer(layer);

map.unindexLayer() function accepts an options object as an optional second parameter to define the bounds to be removed from the index. It should have one of the following attributes:

  • options.bounds - a leaflet latLngBounds object
  • options.latlng - a leaflet latLng object
  • options.latlngs - an array of leaflet latLng objects

If no option is provided, the function will use the bounds of the layer's geometry.

Using inherited class


    L.IndexedGeoJSON = L.GeoJSON.extend({
        includes: L.LayerIndexMixin,

        initialize: function (geojson, options) {
            // Decorate onEachFeature to index layers
            var onEachFeature = function (geojson, layer) {
                this.indexLayer(layer);
                if (this._onEachFeature) this._onEachFeature(geojson, layer);
            };
            this._onEachFeature = options.onEachFeature;
            options.onEachFeature = L.Util.bind(onFeatureParse, this);

            // Parent initialization
            L.GeoJSON.prototype.initialize.call(this, geojson, options);
        },

        removeLayer: function (layer) {
          if (this.hasLayer(layer)) {
            this.unindexLayer(layer)
          }
          return window.L.GeoJSON.prototype.removeLayer.call(this, layer)
        }
    });


    var layer = L.IndexedGeoJSON(data).addTo(map);

    var aroundToulouse = layer.searchBuffer(L.latLng([43.60, 1.44]), 0.1);

Changelog

0.0.2

  • Add bower.json

0.0.1

  • Initial version

Authors

Makina Corpus

leaflet.layerindex's People

Contributors

leplatrem avatar fredericbonifas avatar matt-in-a-hat avatar bo-duke 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.