Update street width depending on zoom level

This commit is contained in:
Markus Koch 2020-04-20 18:39:48 +02:00
parent 26972c366e
commit cfeafc11d9
2 changed files with 28 additions and 6 deletions

View File

@ -130,7 +130,7 @@ L.StreetLabels = L.LabelTextCollision
if (layer._parts) {
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.lineWidth = 3;
//ctx.lineWidth = 3;
layer._parts.forEach(function (part) {
//Build the points list for the first part
var pathPoints = [];

View File

@ -4,13 +4,17 @@ var streetLabelsRenderer = new L.StreetLabels({
collisionFlg: true,
propertyName: 'name',
showLabelIf: function (layer) {
return (layer.geometry.type == "LineString"|| layer.geometry.type == "Polygon");
if (!(layer.geometry.type == "LineString"|| layer.geometry.type == "Polygon"))
return false;
if (mymap.getZoom() <= 5)
return false;
return true;
},
fontStyle: {
dynamicFontSize: true,
fontSize: 11,
fontSize: 10,
fontSizeUnit: "px",
lineWidth: 4.0,
lineWidth: 3.0,
fillStyle: "black",
strokeStyle: "white",
},
@ -18,10 +22,10 @@ var streetLabelsRenderer = new L.StreetLabels({
streetLabelsRenderer._getDynamicFontSize = function () {
zoom = mymap.getZoom();
if (zoom <= 7)
if (zoom <= 8)
return 11;
else
return 2**(zoom - 8) * 11;
return 2**(zoom - 9) * 11;
}
@ -375,8 +379,25 @@ function update_aa_status() {
document.getElementById('mapid').classList.remove("no-aa");
}
function update_street_width() {
zoom = mymap.getZoom();
var w;
if (zoom <= 6) {
w = 2;
} else {
w = 2**zoom * 0.016 * 2;
}
var myStyle = {weight: w, opacity: 0.7};
for (var i = 0; i < layers._layers.length; i++) {
if (!layers._layers[i].layer._layers)
continue;
layers._layers[i].layer.setStyle(myStyle);
}
}
mymap.on('zoomend', function () {is_user_drag = 1; update_hash_from_position();});
mymap.on('zoomend', update_aa_status);
mymap.on('zoomend', update_street_width);
mymap.on('moveend', update_hash_from_position);
mymap.on('dragstart', function () { is_user_drag = 1;});
mymap.on('keydown', function (e) { if (e.originalEvent.code.match(/Arrow.*/)) is_user_drag = 1;});
@ -397,3 +418,4 @@ function onHashChange(e, hash=null) {
window.addEventListener("hashchange", onHashChange, false);
onHashChange(null);
update_street_width();