Skip to content

warudin/leaflet-tag-filter-button

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Leaflet Tag Filter Button

Adds tag filter control for marker to LeafLet.

Required Leaflet.EasyButton

Check out the demo

Usage

Simple usage :

If your markers contains tags option the plugin filters them by selected tags when popup is closed For example:


var map = L.map('map');

var fastMarker = L.marker([50.5, 30.5], { tags: ['fast'] }).addTo(map); 
var slowMarker = L.marker([50.5, 30.5], { tags: ['slow'] }).addTo(map);
var bothMarker = L.marker([50.5, 30.5], { tags: ['fast', 'slow'] }).addTo(map);

L.control.tagFilterButton({
	data: ['fast', 'slow']
}).addTo( map );

Set data from external url/ajax :

note: this option not implemented yet!


var map = L.map('map');
L.tagFilterButton({
	ajaxData: function(callback) {
		$.get('https://leaflet-tag-filter-button.herokuapp.com/data', function(data)) {
			callback(data);
		}
	}
}).addTo( map );


Selection complete callback


var map = L.map('map');
L.tagFilterButton({
	data: function(callback) {
		$.get('https://leaflet-tag-filter-button.herokuapp.com/data', function(data)) {
			callback(data);
		}
	},
	onSelectionComplete: function(tags) {
		console.log('selected tags are', tags);
	}
}).addTo( map );



API Docs

Options

Option Type Default Description
icon `String HTML` fa-filter
onSelectionComplete Function null The callback function for selected tags. It fires when popup is closed and sends selected tags to the callback function as a parameter.
data `Array Function` null
clearText String clear The text of the clear button
filterOnEveryClick Boolean false if set as true the plugin do filtering operation on every click event on the checkboxes.

Methods

Method Returns Description
update() void Updates markers with last selected tags.
hasFiltered() Boolean returns true if any tag(s) selected otherwise false.
registerCustomSource(<Object> source) throws an exception if sourcehas no name orsource.hide function is not implemented Registers source object for filtering markers by tags. If you want to to use this function you must implement hide function
enablePruneCluster(<PruneCluster> pruneClusterInstance) void Searches markers for filtering on given pruneClusterInstance object
resetCaches(<Boolean> update?) void Resets internal caches. if the update parameter sent as true, the update() function will be call after cleaning the cache.

Change Log

v0.0.2 (30.06.2016)

  • Added multi layer source support.

You can add a new marker container layer source to plugin and the plugin searches on added source.

Added PruneCluster layer source to the plugin as default. You can enable it by enablePruneCluster function.

v0.0.3 (18.08.2016)

  • Moved css of filter info box from code-side to css-side
  • Added resetCaches function for cleaning the internal caches

Authors

  • Mehmet Aydemir

About

Adds tag filter control for marker to LeafLet.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 72.6%
  • CSS 17.5%
  • API Blueprint 9.9%