I want to add tooltip which will show magnitude for each earthquake epicenter and was able to make it but I have a problem that with many epicenters in one area tooltips are overlapped.
My question is can I first hide tooltips (magnitudes) and then on control when clicked to show them?
This is my code that shows epicenters, and at the end you will see that I have added .bindTooltip.
var earthquakes = L.geoJson([], {
onEachFeature: function (feature, layer) {
var props = feature.properties;
},
pointToLayer: function (feature, latlng) {
var color,
mag,
radius,
weight;
mag = feature.properties.mag;
label = String(mag);
if (mag === null) {
color = '#FF0000';
radius = 2;
weight = 1;
} else {
color = '#FF0000';
radius = 2 * Math.max(mag, 1);
weight = 1;
}
if (feature.properties.type === 'quarry blast') {
color = '#FF00FF';
}
return L.circleMarker(latlng, {
color: color,
radius: radius,
weight: weight
}).bindTooltip(label, {
permanent: true,
direction: 'center',
opacity: 0.65,
className: 'pointlabel'
}).openTooltip();
}
}).addTo(map);
At the beginning of code I have below code for controls where I can switch map and also show lines (earth faults), so can I somehow by using overlays control be able to bintooltip when checked and unbindtooltip when unchecked?
var Faults = new L.LayerGroup();
var Tooltip = new L.LayerGroup();
var Base = {
"Arcgis map": Arcmap,
"Google terrain": googlemap
};
var overlays = {
"Faults": Faults,
"Tooltip": Tooltip
};
L.control.layers(Base, overlays, {collapsed:false}).addTo(map);
In layer control I would like to have checkbox called tooltip so when checked it show tooltip and when unchecked hide it, see image below:
Here is complete code: https://jsfiddle.net/Tkalac/f5mqo6Lj/1/#&togetherjs=9KtCAh7Unw
earthquakes
with circle markers, then there is layerFaults
with no contents, and on the picture there are circle markers (probablay layerearthquakes
, which I don't see added to the layer control) and some lines, which are probably coming from layerFaults
. Please edit your question, add more code if necessary and try to explain what is what and step by step what should happen.