gpt4 book ai didi

javascript - 在 d3/js 中通过 Stamen 或 CartoDB 使用视网膜 map 图 block

转载 作者:行者123 更新时间:2023-12-03 06:58:23 24 4
gpt4 key购买 nike

我想知道如何修改我的代码以检测视网膜显示并向用户提供增强的图 block 。我通常使用此代码来调用图 block :

雄蕊图 block :

.attr("xlink:href", function(d) { return "http://tile.stamen.com/toner-lite/" + d[2] + "/" + d[0] + "/" + d[1] + ".png"; })

CartoDB 磁贴:

.attr("xlink:href", function(d) { return "http://" + ["a", "b", "c", "d"][Math.random() * 4 | 0] + ".basemaps.cartocdn.com/light_all/" + d[2] + "/" + d[0] + "/" + d[1] + ".png"; })

谢谢!

最佳答案

好的,通过使用它来工作:

function isRetina() {
return ((window.matchMedia && (window.matchMedia('only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx), only screen and (min-resolution: 75.6dpcm)').matches || window.matchMedia('only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2/1), only screen and (min--moz-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2)').matches)) || (window.devicePixelRatio && window.devicePixelRatio > 2)) && /(iPad|iPhone|iPod)/g.test(navigator.userAgent);}

function isRetinaDisplay() {
if (window.matchMedia) {
var mq = window.matchMedia("only screen and (min--moz-device-pixel-ratio: 1.3), only screen and (-o-min-device-pixel-ratio: 2.6/2), only screen and (-webkit-min-device-pixel-ratio: 1.3), only screen and (min-device-pixel-ratio: 1.3), only screen and (min-resolution: 1.3dppx)");
if (mq && mq.matches || (window.devicePixelRatio > 1)) {
return true;
} else {
return false;}
}
}

image.enter().append("image")
.attr("xlink:href", function(d) {
if (isRetinaDisplay) {
return "http://tile.stamen.com/toner-lite/" + d[2] + "/" + d[0] + "/" + d[1] + "@2x.png";
} else {
return "http://tile.stamen.com/toner-lite/" + d[2] + "/" + d[0] + "/" + d[1] + ".png";
}
})

这是用于雄蕊图 block 的。基本上只需在文件名末尾添加“@2x”即可。

关于javascript - 在 d3/js 中通过 Stamen 或 CartoDB 使用视网膜 map 图 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37168207/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com