I am trying to use L.Control.Search and L.markercluster to make a searchable cluster of ~4400 address points. I have tried two separate ways (based on examples I have found) but not yet been successful:
Attempt 1 loaded the address points twice, so the map is uselessly slow and illegible (full link)
// load address points for address search
$.getJSON("data/address_pts.geojson", function(data){
var addressIcon = L.icon({
iconUrl: "images/home.svg",
iconSize: [60,50]
});
var addresses = L.geoJson(data,{
pointToLayer: function(feature,latlng){
var marker = L.marker(latlng,{icon:addressIcon});
marker.bindPopup(feature.properties.FULL_ADDRE);
return marker;
}
});
var clusters = L.markerClusterGroup();
clusters.addLayer(addresses);
map.addLayer(clusters);
// add search
map.addControl(new L.Control.Search({
layer: addresses,
textPlaceholder: 'Address...',
propertyName: 'FULL_ADDRE'
})
);
// end getJSON
});
I wondered if this was some problem with $.getjson, so I tried L.geoJson.ajax extenstion as well:
var addresses = new L.GeoJSON.AJAX('data/address_pts.geoJson', {
pointToLayer: function(feature, latlng) {
return new L.CircleMarker(latlng, {radius: 6, fillOpactiy: 0.9});
},
});
var addressCluster = new L.markerClusterGroup({
disableClusteringAtZoom: 12
}).addTo(map);
address.on('data:loaded', function() {
addressCluster.addLayer(addresses);
});
// feature search
var search = new L.Control.Search({
layer: addresses,
initial: false,
propertyName: 'FULL_ADDRE',
circleLocation:false,
collapsed:false,
textPlaceholder:'Search Addresses',
zoom:'12'});
map.addControl(search);
This loads no data or points at all. I assume I was closer to the right track on Attempt #1, but I don't understand how to prevent duplicate loading of the address points.
var addresses = new L.GeoJSON.AJAX(...
orvar addresses = L.geoJson.ajax(...