GithubHelp home page GithubHelp logo

1sha1 / leaflet-fusesearch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from naomap/leaflet-fusesearch

0.0 3.0 0.0 176 KB

A plugin for Leaflet to search features in a GeoJSON layer using Fuse.js

License: MIT License

leaflet-fusesearch's Introduction

leaflet-fusesearch

Search features in a GeoJSON layer using the lightweight JavaScript fuzzy search Fuse.js

Usage

First download Fuse.js from this repo or from Kiro's site, and load it in your page before leaflet-fusesearch.js.

Create the control L.Control.FuseSearch and add it to the Map.

var searchCtrl = L.control.fuseSearch()
searchCtrl.addTo(map);

Then load your GeoJSON layer and index the features, choosing the properties you want to index, e.g.

searchCtrl.indexFeatures(features, ['name', 'company', 'details'];

This is it ! By default the search control will appear on the top right corner of the map. This opens the search pane on the same side where you can type in the search string. The matching features are listed, with the indexed properties displayed. Clicking a feature on the list opens up the matching pop-up on the map, provided one is associated with it.

Options

The FuseSearch control can be created with the following options :

  • position : position of the control, the search pane shows on the matching side. Default 'topright'.
  • title : used for the control tooltip, default 'Search'
  • placeholder : used for the input placeholder, default 'Search'
  • maxResultLength : number of features displayed in the result list, default is null and all features found by Fuse are displayed
  • showResultFct : function to display a feature returned by the search, parameters are the feature and an HTML container. Here is an example :
    showResultFct: function(feature, container) {
        props = feature.properties;
        var name = L.DomUtil.create('b', null, container);
        name.innerHTML = props.name;
        container.appendChild(L.DomUtil.create('br', null, container));
        container.appendChild(document.createTextNode(props.details));
    }

In addition these options are directly passed to Fuse - more details on Fuse.js :

  • caseSensitive : whether comparisons should be case sensitive, default is false
  • threshold : a decimal value indicating at which point the match algorithm gives up. A threshold of 0.0 requires a perfect match, a threshold of 1.0 would match anything, default 0.5

Example

I'm currently working on providing a simple example, for now have a look at my NaoMap site.

leaflet-fusesearch's People

Watchers

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