• Stars
    star
    706
  • Rank 64,138 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 12 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Search stuff in a Leaflet map

Leaflet Control Search

npm version

A Leaflet control that search markers/features location by custom property.
Support ajax/jsonp autocompletion and JSON data filter/remapping.

Licensed under the MIT license.

Copyright Stefano Cudini

If this project helped your work help me to keep this alive by Paypal DONATION ❀

Tested in Leaflet 0.7.x and 1.3.x

Image

Where

Demo: opengeo.tech/maps/leaflet-search

Source code: Github NPM

Install

npm install --save leaflet-search

Options

Option Default Description
url '' url for search by ajax request, ex: "search.php?q={s}". Can be function to returns string for dynamic parameter setting
layer null layer where search markers(is a L.LayerGroup)
sourceData null function to fill _recordsCache, passed searching text by first param and callback in second
jsonpParam null jsonp param name for search by jsonp service, ex: "callback"
propertyLoc 'loc' field for remapping location, using array: ['latname','lonname'] for select double fields(ex. ['lat','lon'] ) support dotted format: 'prop.subprop.title'
propertyName 'title' property in marker.options(or feature.properties for vector layer) trough filter elements in layer,
formatData null callback for reformat all data from source to indexed data object
filterData null callback for filtering data from text searched, params: textSearch, allRecords
moveToLocation null callback run on location found, params: latlng, title, map
buildTip null function to return row tip html node(or html string), receive text tooltip in first param
container '' container id to insert Search Control
zoom null default zoom level for move to location
minLength 1 minimal text length for autocomplete
initial true search elements only by initial text
casesensitive false search elements in case sensitive text
autoType true complete input with first suggested result and select this filled-in text.
delayType 400 delay while typing for show tooltip
tooltipLimit -1 limit max results to show in tooltip. -1 for no limit, 0 for no results
tipAutoSubmit true auto map panTo when click on tooltip
firstTipSubmit false auto select first result con enter click
autoResize true autoresize on input change
collapsed true collapse search control at startup
autoCollapse false collapse search control after submit(on button or on tips if enabled tipAutoSubmit)
autoCollapseTime 1200 delay for autoclosing alert and collapse after blur
textErr 'Location not found' error message
textCancel 'Cancel title in cancel button
textPlaceholder 'Search' placeholder value
hideMarkerOnCollapse false remove circle and marker on search control collapsed
position 'topleft' position in the map
marker {} custom L.Marker or false for hide
marker.icon false custom L.Icon for maker location or false for hide
marker.animate true animate a circle over location found
marker.circle L.CircleMarker options draw a circle in location found

Events

Event Data Description
'search:locationfound' {latlng, title, layer} fired after moved and show markerLocation
'search:expanded' {} fired after control was expanded
'search:collapsed' {} fired after control was collapsed

Methods

Method Arguments Description
setLayer() L.LayerGroup() set layer search at runtime
showAlert() 'Text message' show alert message
searchText() 'Text searched' search text by external code

Examples

(require src/leaflet-search.css)

Adding the search control to the map:

var searchLayer = L.layerGroup().addTo(map);
//... adding data in searchLayer ...
map.addControl( new L.Control.Search({layer: searchLayer}) );
//searchLayer is a L.LayerGroup contains searched markers

Short way:

var searchLayer = L.geoJson().addTo(map);
//... adding data in searchLayer ...
L.map('map', { searchControl: {layer: searchLayer} });

AMD module:

require(["leaflet", "leafletSearch"],function(L, LeafletSearch) {

	//... initialize leaflet map and dataLayer ...

	map.addControl( new LeafletSearch({
		layer: dataLayer
	}) );
});

Build

Therefore the deployment require npm installed in your system.

npm install
npx grunt

Use Cases

This list is intended to be of utility for all developers who are looking web mapping sample code to solve complex problems of integration with other systems using Leaflet Control Search.

Anyone can add the link of your website

(spamming urls will be automatically deleted)

More Repositories

1

leaflet-panel-layers

Leaflet Control Layers extended with support groups and icons
JavaScript
267
star
2

leaflet-gps

Simple leaflet control plugin for tracking gps position
JavaScript
112
star
3

bootstrap-list-filter

Search widget to filter Bootstrap lists
HTML
99
star
4

leaflet-geojson-selector

Show GeoJSON Layer like as Interactive Menu List
JavaScript
99
star
5

gpx-simplify-optimizer

Free Tracks Optimizer Online Service
JavaScript
92
star
6

leaflet-layerJSON

Build dynamic JSON Layer via Ajax/JSONP with caching
JavaScript
90
star
7

leaflet-compass

Leaflet plugin to show a rotating Compass!
JavaScript
85
star
8

leaflet-list-markers

A Leaflet Control for listing visible markers/features in a interactive box
JavaScript
61
star
9

leaflet-locationpicker

Simple location picker on Leaflet map
JavaScript
46
star
10

bootstrap-confirm-button

A simple button to confirm tasks, inline and unobtrusive confirm system
HTML
24
star
11

leaflet-loader

Simple control to show a gif loader to the center of the map
HTML
16
star
12

share-tracks

Simple way to Share/Embed GPX Tracks in Leaflet
JavaScript
15
star
13

node-fetch-dom

Magic utility that extract javascript global variables from a remote html page.
HTML
13
star
14

labshub

Static web site generator for create an Hub to organizing a set of NPM packages by keywords
HTML
9
star
15

orthogonalize-js

JavaScript polyline, linestring, path spatial orthogonalize library
Java
8
star
16

dns-320-command-line

COMMAND-LINE INTERFACE for D-LINK SHARECENTER DNS-320
PHP
8
star
17

osm-contributors-by-area

List of contributors who have participated in a given OSM area.
JavaScript
8
star
18

PeliasLite

Minimal Single Service Interface of Pelias Geocoder in Nodejs
JavaScript
7
star
19

GeoSFX

Self Extracting GeoJSON build compressed GeoJSON distributed over JSONP in a compact, no dependencies Javascript file
JavaScript
6
star
20

docker-ors-vroom

Docker service to test VRP(Vehicle Routing Problem) with OpenRouteService and VROOM
Jupyter Notebook
5
star
21

leaflet-webpack-example

Simple example to use Leaflet with webpack
JavaScript
5
star
22

geotiff-picker

Raster GeoTiff file data picker with API Restful/CLI interface
HTML
5
star
23

download-limiter-php

Download Bandwidth Limit by PHP/BASH
PHP
5
star
24

overpass-query-cache

Bounding boxes caching system for Overpass API requests
JavaScript
5
star
25

meteor-googlemaps-server

NPM wrapper for node-googlemaps to be used in Meteor projects, google maps api for server side
JavaScript
5
star
26

leaflet-tilelayer-blend

Apply CSS Blend Modes filters to a stack of tile layers
HTML
4
star
27

youtubecaster

Stream any youtube video as audio podcast
JavaScript
3
star
28

realtime-access-map

Map for realtime monitoring geo-referenced accesses
PHP
3
star
29

osm-tile-cacher

another tiles cacher using leaflet and little bit of php
HTML
2
star
30

Mega-Python-CommandLine-Tools

Mega Python CommandLine Tools
Python
2
star
31

gps-network-tracking-system

System for realtime tracking and archive of a mobile devices network
2
star
32

mWm

Mobile Web Monitor, *nix web interface monitoring for mobile
PHP
2
star
33

geojson-resources

static GeoJSON resources distributed via public cdn
2
star
34

dotfiles

my .files
Shell
1
star
35

share-location

publish gps position to remote gpx file
JavaScript
1
star
36

crop-avatar

Interactive interface for cropping and rotation of photos for creating an avatar's profile
PHP
1
star
37

leaflet-animation

Make a GIF animation from a Leaflet map
JavaScript
1
star
38

stefanocudini

Stefano Cudini - Curriculum Vitae
HTML
1
star
39

websocket-chess

Chess game multiplayer online via websocket
PHP
1
star
40

json-indent-beautifier

Simple and interactive JSON beatifier online
HTML
1
star
41

ubuntu-window-border-updater

set window border width in ubuntu themes
JavaScript
1
star