自定义CRS:如何使小叶刻度控件显示毫米(毫米)和微米(微米)

问题描述 投票:1回答:1

反正是否要让传单显示小于一米的值?例如,刻度控制上的毫米(毫米)或微米(微米)?

或者如果有插件可以做到这一点?

我有一个自定义地图,其中包含使用虚拟显微镜图像的自定义CRS。

我使用以下代码创建一个小于一米的值的地图,但是比例控制非常宽并且不会低于一米:

L.CRS.Meters = L.extend(L.CRS, {
    projection: L.extend( L.Projection.LonLat, {
      bounds: L.bounds([0, 0], [2160, 4096])
    }),
    transformation: new L.Transformation(1, 0, -1, 0),
    scale: function (zoom) {
        return Math.pow(2, zoom);
    },
    infinite: false
});

var customCRS = L.extend(L.CRS.Simple, {
  projection: L.extend( L.Projection.LonLat, {
     bounds: L.bounds([0, 0], [2160, 4096])
  }),
  transformation: new L.Transformation(1, 0, 1, 0),
  scale: function (zoom) {
    return Math.pow(2, zoom +7);
  },
  infinite: false
});

var map = L.map('vm', { zoomSnap: 0.2, crs: customCRS}).setView([3, 3], 3);
leaflet
1个回答
1
投票

处理比例尺测量和(公制)单位舍入的特定代码是_updateMetric method

_updateMetric: function (maxMeters) {
    var meters = this._getRoundNum(maxMeters),
        label = meters < 1000 ? meters + ' m' : (meters / 1000) + ' km';

    this._updateScale(this._mScale, label, meters / maxMeters);
},

请注意,implementation of this._getRoundNum()将返回一个整数,即1最小值。

您可能希望替换_updateMetric()的实现,以舍入该数字的因子,并相应地应用单位后缀,例如:

L.Control.Scale.include({
  _updateMetric: function(maxMeters) {
    var maxMilliMeters = maxMeters * 1000,
        milliMeters = this._getRoundNum(maxMilliMeters),
        label = milliMeters < 1000 ? milliMeters + " mm" : milliMeters / 1000 + " m";

    console.log(this._mScale, label, milliMeters / maxMilliMeters);

    this._updateScale(this._mScale, label, milliMeters / maxMilliMeters);
  }
});

看到working example here

© www.soinside.com 2019 - 2024. All rights reserved.