Closed helotrix closed 9 years ago
Hi. Did you try to put the line "feature.layer = layer;" in the function onEachFeature() for instance ? That should do the trick. Antoine.
I assume you solved your problem. Please reopen with more details if that is not the case.
Hello, I have the same problem like helotrix. When I search the feature, it appears in the container but it doesn't connect whith the popup of the feature...
I put "feature.layer = layer;" before the "searchCtrl.indexFeatures" like in the example and I have the error "ReferenceError: feature is not defined". If I put the reference in the onEachFeature() function, I don't have any error, but the plugin doesn't run.
Excuse me for my English.
Thank you,
Mikel
This is the code:
function pop_lorazaintzaguneak(feature, layer) {
var popupContent = '<table><tr><th scope="row">IZENA</th><td>' + Autolinker.link(String(feature.properties['IZENA']))
+ '</td></tr><tr><th scope="row">AZALERA</th><td>' + Autolinker.link(String(feature.properties['Azalera'])) </tr></table>';
layer.bindPopup(popupContent);
}
function doStylelorazaintzaguneak(feature) {
return {
weight: 1.04,
color: '#5fb404',
fillColor: '#a5df00',
dashArray: '',
opacity: 1.0,
fillOpacity: 0.6
};
}
var json_lorazaintzaguneakJSON = new L.geoJson(json_lorazaintzaguneak, {
onEachFeature: pop_lorazaintzaguneak,
style: doStylelorazaintzaguneak
});
layerOrder[layerOrder.length] = json_lorazaintzaguneakJSON;
layerOrder[layerOrder.length] = json_lorazaintzaguneakJSON;
for (index = 0; index < layerOrder.length; index++) {
feature_group.removeLayer(layerOrder[index]); feature_group.addLayer(layerOrder[index]);
}
bounds_group.addLayer(json_lorazaintzaguneakJSON);
feature_group.addLayer(json_lorazaintzaguneakJSON);
var searchCtrl = L.control.fuseSearch({
position: 'topleft',
panelTitle: 'Bilaketa emaitza',
showResultFct: function(feature, container) {
props = feature.properties;
var name = L.DomUtil.create('b', null, container);
name.innerHTML = props.IZENA;
container.appendChild(L.DomUtil.create('br', null, container));
container.appendChild(document.createTextNode(props.Azalera));
}
});
searchCtrl.addTo(map);
searchCtrl.indexFeatures(json_lorazaintzaguneak, ['IZENA', 'Azalera']);
feature.layer = json_lorazaintzaguneakJSON;
You need to bind the layer to the feature for each individual feature, for instance in your function pop_lorazaintzaguneak() :
function pop_lorazaintzaguneak(feature, layer) {
../..
layer.bindPopup(popupContent);
feature.layer = layer;
}
Hello!
I'm really struggling here, not helped by my sorry lack of Javascript knowledge. I wonder if you can help?
I have created the map, added markers with pop-ups, added the search control and that is all working. I am getting search results in the RHS pane.
But I can not find a way to bind the layer to each marker.
Here's the script:
I've read the ReadMe and I see that I have to use:
But try as I might I just can not get it to work. What am I missing?
Thank you.