Update street width depending on zoom level
This commit is contained in:
parent
26972c366e
commit
cfeafc11d9
@ -130,7 +130,7 @@ L.StreetLabels = L.LabelTextCollision
|
|||||||
if (layer._parts) {
|
if (layer._parts) {
|
||||||
ctx.textAlign = "center";
|
ctx.textAlign = "center";
|
||||||
ctx.textBaseline = "middle";
|
ctx.textBaseline = "middle";
|
||||||
ctx.lineWidth = 3;
|
//ctx.lineWidth = 3;
|
||||||
layer._parts.forEach(function (part) {
|
layer._parts.forEach(function (part) {
|
||||||
//Build the points list for the first part
|
//Build the points list for the first part
|
||||||
var pathPoints = [];
|
var pathPoints = [];
|
||||||
|
@ -4,13 +4,17 @@ var streetLabelsRenderer = new L.StreetLabels({
|
|||||||
collisionFlg: true,
|
collisionFlg: true,
|
||||||
propertyName: 'name',
|
propertyName: 'name',
|
||||||
showLabelIf: function (layer) {
|
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: {
|
fontStyle: {
|
||||||
dynamicFontSize: true,
|
dynamicFontSize: true,
|
||||||
fontSize: 11,
|
fontSize: 10,
|
||||||
fontSizeUnit: "px",
|
fontSizeUnit: "px",
|
||||||
lineWidth: 4.0,
|
lineWidth: 3.0,
|
||||||
fillStyle: "black",
|
fillStyle: "black",
|
||||||
strokeStyle: "white",
|
strokeStyle: "white",
|
||||||
},
|
},
|
||||||
@ -18,10 +22,10 @@ var streetLabelsRenderer = new L.StreetLabels({
|
|||||||
|
|
||||||
streetLabelsRenderer._getDynamicFontSize = function () {
|
streetLabelsRenderer._getDynamicFontSize = function () {
|
||||||
zoom = mymap.getZoom();
|
zoom = mymap.getZoom();
|
||||||
if (zoom <= 7)
|
if (zoom <= 8)
|
||||||
return 11;
|
return 11;
|
||||||
else
|
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");
|
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', function () {is_user_drag = 1; update_hash_from_position();});
|
||||||
mymap.on('zoomend', update_aa_status);
|
mymap.on('zoomend', update_aa_status);
|
||||||
|
mymap.on('zoomend', update_street_width);
|
||||||
mymap.on('moveend', update_hash_from_position);
|
mymap.on('moveend', update_hash_from_position);
|
||||||
mymap.on('dragstart', function () { is_user_drag = 1;});
|
mymap.on('dragstart', function () { is_user_drag = 1;});
|
||||||
mymap.on('keydown', function (e) { if (e.originalEvent.code.match(/Arrow.*/)) 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);
|
window.addEventListener("hashchange", onHashChange, false);
|
||||||
onHashChange(null);
|
onHashChange(null);
|
||||||
|
update_street_width();
|
||||||
|
Loading…
Reference in New Issue
Block a user