私はリーフレットのライブラリとJavaScriptにはまったく新しく、ズームレベルに基づいてリーフレットの表示/非表示の仕方を理解しようとしています(マーカは「クラスタ」にあります)層)。リーフレットで特定のズームレベルを超えてラベルを表示するにはどうすればよいですか?
マーカーはすべてAJAXコールバック経由でロードされてから、onEachFeature
を使用してポップアップとラベルをバインドしてから、geoJsonマーカーのレイヤーをマップに追加します。
あるレベルまで拡大したときにラベルを表示したいのですが、私は運がありませんでした。私もleaflet.zoomcss.js
を追加しようとしましたが、正しく使用していないと思います。
サンプルは、私もそれが、このようにそれを追加しようとしました
var officesLayerGroup = L.markerClusterGroup();
var currentMakers;
function DiaplyLocalOffices(jqOffices) {
currentMakers = new L.geoJson(jqOffices, {
style: function (feature) {
var c = feature.properties.markercolor;
if (feature.properties.OfficeID == 0) {
c = 'yellow';
}
return { color: c };
},
pointToLayer: function (feature, latlng) {
return new L.CircleMarker(latlng, { radius: 7, fillOpacity: 0.5 });
},
onEachFeature: bindOfficePopup
});
officesLayerGroup.addLayer(currentMakers);
map.addLayer(officesLayerGroup);
}
function bindOfficePopup(feature, layer) {
// This function adds the popup based on the information in the 'layer' or marker
// Keep track of the layer(marker)
feature.layer = layer;
var props = feature.properties;
if (props) {
var desc = '<span id="feature-popup">';
//.. a bunch of other html added here!
var warn = props.Warning ? props.Warning : null;
if (warn !== null) {
desc += '<font size="4" color="red"><strong><em>' + warn + '</em></strong></font></br>';
}
desc += '</span>';
layer.bindPopup(desc);
layer.bindLabel('Hi Label!', { noHide: true, className: 'my-css-styled-labels'});
}
}
どちらか動作しませんでした。その後、
layer.on({
zoomend: showLabel(e)
});
と急ごしらえ機能:
function showLabel(e) {
z = map.getZoom();
if (z > 6) {
layer.bindLabel("HIYA", { noHide: true, className: 'my-css-styled-labels' });
}
}
しかし、ライブラリとCSSスタイルを追加する場合でも、運がないleaflet.zoomcss.js
申し訳ありませんが長いですが、どんな助けでも本当に感謝しています!
私の場合は、特定のgeoJsonレイヤーでのみ動作し、任意の種類と数のレイヤーでマップで動作する点を除いて、上記の追加値はわかりません。 –