【问题标题】:Changing the coordinate system on my leaflet map to custom (scale and 0,0 position)将我的传单地图上的坐标系更改为自定义(比例和 0,0 位置)
【发布时间】:2019-09-11 17:34:53
【问题描述】:

我正在为游戏构建自定义切片图层地图。游戏中有一个当前内置的坐标系统,我正在寻找复制它,以便用户在查找坐标和连接到位置数据库时访问。

我正在尝试将 CRS 的 0,0 移动到地图的中心位置,但是我尝试过的所有内容始终位于左上角。

有没有办法在将切片图层添加到地图后移动它?

另外,我将如何更改坐标的比例?

我一直在尝试寻找解决方案,但没有找到适合我正在寻找的东西。我已经尝试过https://leafletjs.com/examples/crs-simple/crs-simple.html,但除非我遗漏了什么,否则它对我没有帮助。

这是一个例子:蓝线是当前坐标系,红色是我想要的一个例子。 example of my problem

这里是我初始化地图和瓦片层的地方。

    var map = new L.Map('map', {
        crs: L.CRS.Simple, 
        zoom: 3, 
        center:(hash), 
        minZoom: 2, 
        zoomControl: false, 
        noWrap: true, });
    var TopoLayer = L.tileLayer('map-tiles/{z}/{x}/{y}.jpg').addTo(map);  

谢谢,我觉得解决方案很简单,我只是跳过它。

【问题讨论】:

标签: javascript leaflet


【解决方案1】:
    var factorx = 8
    var factory = 8

    L.CRS.pr = L.extend({}, L.CRS.Simple, {
      projection: L.Projection.LonLat,
      transformation: new L.Transformation(factorx, 160, -factory, 52.9),

      scale: function(zoom) {
        return Math.pow(2, zoom);
      },

      zoom: function(scale) {
        return Math.log(scale) / Math.LN2;
      },

      distance: function(latlng1, latlng2) {
        var dx = latlng2.lng - latlng1.lng,
          dy = latlng2.lat - latlng1.lat;

        return Math.sqrt(dx * dx + dy * dy);
      },
      infinite: true
    });

这似乎成功了 :) 创建了一个自定义 crs。

【讨论】:

    猜你喜欢
    • 2013-02-09
    • 2016-04-10
    • 1970-01-01
    • 2017-04-05
    • 2016-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多