Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
// "eslint.enable": false,
"editor.formatOnSave": false,
// "editor.autoIndent": "none",
"editor.codeActionsOnSave": {

},
"liveServer.settings.port": 5501
}
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ grunt.registerTask('default', [
'concat',
'cssmin',
'removelogging',
'jshint',
// 'jshint',
'uglify'
]);

Expand Down
2 changes: 1 addition & 1 deletion dist/leaflet-search.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/leaflet-search.mobile.src.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Leaflet Control Search v3.0.10 - 2023-08-08
* Leaflet Control Search v4.0.0 - 2025-04-14
*
* Copyright 2023 Stefano Cudini
* Copyright 2025 Stefano Cudini
* [email protected]
* https://opengeo.tech/
*
Expand Down
4 changes: 2 additions & 2 deletions dist/leaflet-search.src.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Leaflet Control Search v3.0.10 - 2023-08-08
* Leaflet Control Search v4.0.0 - 2025-04-14
*
* Copyright 2023 Stefano Cudini
* Copyright 2025 Stefano Cudini
* [email protected]
* https://opengeo.tech/
*
Expand Down
121 changes: 84 additions & 37 deletions dist/leaflet-search.src.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Leaflet Control Search v3.0.10 - 2023-08-08
* Leaflet Control Search v4.0.0 - 2025-04-14
*
* Copyright 2023 Stefano Cudini
* Copyright 2025 Stefano Cudini
* [email protected]
* https://opengeo.tech/
*
Expand Down Expand Up @@ -80,6 +80,7 @@
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
filtersearch: null, // Optional comma-separated string to prepend to the search text
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
Expand Down Expand Up @@ -553,54 +554,66 @@
},

_searchInLayer: function (layer, retRecords, propName, baseProp = 'options') {
const self = this; let loc
const self = this;
let loc;

if (layer instanceof L.Control.Search.Marker) return
if (layer instanceof L.Control.Search.Marker) return;

if (layer instanceof L.Marker || layer instanceof L.CircleMarker) {
if (self._getPath(layer.options, propName)) {
loc = layer.getLatLng()
loc.layer = layer
retRecords[self._getPath(layer.options, propName)] = loc
} else if (self._getPath(layer.feature.properties, propName)) {
loc = layer.getLatLng()
loc.layer = layer
retRecords[self._getPath(layer.feature.properties, propName)] = loc
// Handle markers
const key = self._getPath(layer.options, propName) || self._getPath(layer.feature.properties, propName);
if (key) {
loc = layer.getLatLng();
loc.layer = layer;
if (!retRecords[key]) {
retRecords[key] = [];
}
retRecords[key].push(loc);
} else {

}
} else if (layer instanceof L.Path || layer instanceof L.Polyline || layer instanceof L.Polygon) {
if (self._getPath(layer.options, propName)) {
loc = layer.getBounds().getCenter()
loc.layer = layer
retRecords[self._getPath(layer.options, propName)] = loc
} else if (self._getPath(layer.feature.properties, propName)) {
loc = layer.getBounds().getCenter()
loc.layer = layer
retRecords[self._getPath(layer.feature.properties, propName)] = loc
// Handle paths
const key = self._getPath(layer.options, propName) || self._getPath(layer.feature.properties, propName);
if (key) {
loc = layer.getBounds().getCenter();
loc.layer = layer;
if (!retRecords[key]) {
retRecords[key] = [];
}
retRecords[key].push(loc);
} else {

}
} else if (Object.prototype.hasOwnProperty.call(layer, 'feature')) { // GeoJSON
if (Object.prototype.hasOwnProperty.call(layer.feature.properties, propName)) {
if (layer.getLatLng && typeof layer.getLatLng === 'function') {
loc = layer.getLatLng()
loc.layer = layer
retRecords[layer.feature.properties[propName]] = loc
loc = layer.getLatLng();
loc.layer = layer;
const key = layer.feature.properties[propName];
if (!retRecords[key]) {
retRecords[key] = [];
}
retRecords[key].push(loc);
} else if (layer.getBounds && typeof layer.getBounds === 'function') {
loc = layer.getBounds().getCenter()
loc.layer = layer
retRecords[layer.feature.properties[propName]] = loc
loc = layer.getBounds().getCenter();
loc.layer = layer;
const key = layer.feature.properties[propName];
if (!retRecords[key]) {
retRecords[key] = [];
}
retRecords[key].push(loc);
} else {

}
} else {

}
} else if (layer instanceof L.LayerGroup) {
// Recursively search in layer groups
layer.eachLayer(function (layer) {
self._searchInLayer(layer, retRecords, propName)
})
self._searchInLayer(layer, retRecords, propName);
});
}
},

Expand Down Expand Up @@ -748,7 +761,12 @@
this._retrieveData = this.options.jsonpParam ? this._recordsFromJsonp : this._recordsFromAjax
}

this._curReq = this._retrieveData.call(this, inputText, function (data) {
filterText =
(this.options.filtersearch
? this.options.filtersearch.replace(/,+$/, "") + ","
: "") + inputText;

this._curReq = this._retrieveData.call(this, filterText, function (data) {
self._recordsCache = self._formatData(self, data)

// TODO refact!
Expand Down Expand Up @@ -820,17 +838,34 @@
this.collapse()
} else {
const loc = this._getLocation(this._input.value)

if (!loc) {
this.showAlert()
this.showAlert();
} else {
this.showLocation(loc, this._input.value)
this.fire('search:locationfound', {
this.showLocation(loc, this._input.value);

// Create a feature group to combine multiple layers
let combinedLayer = null;

if (Array.isArray(loc)) {
combinedLayer = L.featureGroup();
loc.forEach((location) => {
if (location.layer) {
combinedLayer.addLayer(location.layer);
}
});
} else if (loc.layer) {
combinedLayer = loc.layer;
}

this.fire("search:locationfound", {
latlng: loc,
text: this._input.value,
layer: loc.layer ? loc.layer : null
})
layer: combinedLayer,
});
}


}
}
},
Expand Down Expand Up @@ -908,8 +943,19 @@
},

setLatLng: function (latlng) {
L.Marker.prototype.setLatLng.call(this, latlng)
if (this._circleLoc) { this._circleLoc.setLatLng(latlng) }
if (Array.isArray(latlng)) {
latlng.forEach((point, i) => {
L.Marker.prototype.setLatLng.call(this, point);
if (this._circleLoc) {
this._circleLoc.setLatLng(point);
}
});
} else {
L.Marker.prototype.setLatLng.call(this, latlng);
if (this._circleLoc) {
this._circleLoc.setLatLng(latlng);
}
}
return this
},

Expand All @@ -925,6 +971,7 @@
// TODO refact animate() more smooth! like this: http://goo.gl/DDlRs
if (this._circleLoc) {
const circle = this._circleLoc

const tInt = 200 // time interval
const ss = 5 // frames
let mr = parseInt(circle._radius / ss)
Expand Down
Loading