简体   繁体   English

强制传单地图仅使用整数缩放级别(无分数级别)

[英]Force leaflet map to use only integer zoom levels (no fractional levels)

I'm unable to force my leaflet map to use only integer zoom levels. 我无法强制我的传单地图仅使用整数缩放级别。 As long as I use only the -/+ control buttons it's fine, but as soon as I use the mouse wheel or a function like map.fitBounds(some polygon) I always end up with a fractional zoom level. 只要我只使用-/ +控制按钮,就可以了,但是只要我使用鼠标滚轮或诸如map.fitBounds(some polygon)之类的函数,我总会得到分数缩放级别。

This is bad for me because I use tiles for levels 0 to 17 and when I end up with a fractional zoom level in between two levels, like 10.5, the tiles are scaled and blurry. 这对我来说是不利的,因为我将图块的级别设置为0到17,当最终得到介于两个级别之间的小数缩放级别(如10.5)时,图块会缩放且模糊。

The documentation says the default for zoomSnap and zoomDelta is 1. So I don't get why I end up with a fractional zoom level anyway. 该文档说zoomSnap和zoomDelta的默认值为1。所以我不明白为什么我最终只能得到分数缩放级别。 How can I prevent this? 我该如何预防?

I'm using these 我正在使用这些

<!-- Leaflet -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.1/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.0.1/dist/leaflet.js"></script>

<!-- L.esri for Leaflet -->
<script src="https://unpkg.com/esri-leaflet@2.0.4"></script>

<!-- Elevation plugin for Leaflet -->
<link rel="stylesheet" href="/app/libs/leaflet-elevation/dist/leaflet.elevation-0.0.4.css" />
<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<!--<script src="app/libs/leaflet-elevation/dist/leaflet.elevation-0.0.4.min.js"></script>-->
<script src="/app/libs/leaflet-elevation/dist/leaflet.elevation-0.0.4.src.js"></script>

<!-- Marker Cluster plugin for Leaflet -->
<link rel="stylesheet" type="text/css" href="https://unpkg.com/leaflet.markercluster@1.0.0/dist/MarkerCluster.Default.css">
<link rel="stylesheet" type="text/css" href="https://unpkg.com/leaflet.markercluster@1.0.0/dist/MarkerCluster.css">
<script src="https://unpkg.com/leaflet.markercluster@1.0.0/dist/leaflet.markercluster.js"></script>

<!-- zoomhome plugin for Leaflet -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"/>
<link rel="stylesheet" href="/app/libs/leaflet-zoomhome/leaflet.zoomhome.css"/>
<script src="/app/libs/leaflet-zoomhome/leaflet.zoomhome.js"></script>

and here's how I init my map: 这是我初始化地图的方式:

    this.map = L.map(this.config.domNode, {
        center: [50.13466432216696, -72.72949218750001],
        zoom: 6,
        zoomSnap: 1,
        zoomDelta: 1,
        zoomControl: false,
        minZoom: 3,
        maxZoom: 17,
        scrollWheelZoom: this.config.scrollWheelZoom,
        wheelDebounceTime: 20,
        wheelPxPerZoomLevel: 50
    });

    L.Control.zoomHome({ position: 'topright' }).addTo(this.map);

The tangram library was setting the zoomSnap to 0 after adding our basemap to the map. 在将底图添加到地图后,七巧板库将zoomSnap设置为0。 Which basically enables fractional zoom levels for the map. 基本上可以为地图启用分数缩放级别。

After digging through the tangram documentation, I found this little nugget of information: 在浏览了七巧板文档之后,我发现了这一小块信息:

modifyScrollWheel modifyScrollWheel

By default, Tangram modifies Leaflet's scrollwheel behavior, for better synchronization with its own render loop while zooming. 默认情况下,七巧板修改Leaflet的滚轮行为,以便在缩放时与其自身的渲染循环更好地同步。 If this interferes with your application, you can disable this behavior with the optional modifyScrollWheel option: 如果这干扰了您的应用程序,则可以使用可选的ModifyScrollWheel选项禁用此行为:

var layer = Tangram.leafletLayer({
    modifyScrollWheel: false,
    ...
});

I tried it, and indeed it fixed my issue. 我尝试过,确实解决了我的问题。

添加了部分缩放作为增强功能 ,可以使用zoomStep= 1禁用它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM