获取基于百分比或基于像素的x&y坐标来自latlng

Getting percentage-based or pixel based x & y coordinates from latlng

本文关键字:amp 坐标 latlng 于像素 百分比 像素 获取      更新时间:2023-09-26

我目前正在尝试从传单中的latlng获取百分比或像素坐标。

以下是创建地图并定义瓦片的脚本(取自名为"maptiler"的应用程序)

    var mapMinZoom = 0;
    var mapMaxZoom = 3;
    var map = L.map('main-map', {
        maxZoom: mapMaxZoom,
        minZoom: mapMinZoom,
        crs: L.CRS.Simple
    }).setView([0 0], mapMaxZoom);
    var mapBounds = new L.LatLngBounds(
        map.unproject([0, 1792], mapMaxZoom),
        map.unproject([2048, 0], mapMaxZoom));
    map.fitBounds(mapBounds);
    L.tileLayer('/_Content/leafletmap/{z}/{x}/{y}.png', {
        minZoom: mapMinZoom, maxZoom: mapMaxZoom,
        bounds: mapBounds,
        noWrap: true,
        tms: false
    }).addTo(map);

这里的主要要求是在cordova应用程序中提供离线功能,这就是我们不使用谷歌地图API的原因。

您可能正在寻找传单地图转换方法:

  • latLngToLayerPoint(latlng)以获得相对于整个贴图的层点
  • latLngToContainerPoint(latlng)以获得相对于映射容器的点(在您的情况下为'main-map'