【问题标题】:Leaflet base layer control with non-geographic image?带有非地理图像的传单基础层控制?
【发布时间】:2014-04-02 15:39:22
【问题描述】:

我已经对这个主题进行了多次搜索,但没有运气,所以这是我的问题...

我创建了带有地理地图图块的传单地图,这些地图块对基础图层和覆盖图层都有图层控件,并且我已经创建了带有非地理图像图块的传单地图,但是我在创建带有非地理图像的传单地图时遇到了问题还具有平铺层控件的图像——因此用户可以通过 Leaflet 层控制开关在图像之间切换以查看和放大。

所有设置在没有瓦片图层控制的单图版本中都可以正常工作,但在以下代码中不起作用。我在 Dreamweaver 和 Firebug 上运行了代码检查器,他们没有发现任何问题,但我得到的是一个空白屏幕,没有图像,没有可见的图层控件,右下角没有图层属性。

<!DOCTYPE html>
<html>
  <head>
    <title>Horsehead Nebulae</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.ie.css" />
    <![endif]-->
    <script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
    <script>
      function init() {
        var mapMinZoom = 0;
        var mapMaxZoom = 5;
        var map = L.map('map', {
          maxZoom: mapMaxZoom,
          minZoom: mapMinZoom,
          crs: L.CRS.Simple
        }).setView([0, 0], mapMaxZoom);

        var mapBounds = new L.LatLngBounds(
            map.unproject([0, 5376], mapMaxZoom),
            map.unproject([5120, 0], mapMaxZoom));

        map.fitBounds(mapBounds);

        var hhAttr = 'Ipsulem lorem',

            hhUrl = 'http://www.astonisher.com/maps/nebulae/horsehead/{z}/{x}/{y}.png';

        var horsehead   = L.tileLayer(hhUrl, {attribution: hhAttr});

        var heAttr = 'Ipsumel lorem',

             heUrl = 'http://www.astonisher.com/maps/nebulae/helix/{z}/{x}/{y}.png';

         var helix = L.tileLayer(heUrl, {attribution: heAttr});


         var map = L.map('map', {
          minZoom: mapMinZoom, 
          maxZoom: mapMaxZoom,
          bounds: mapBounds,
          noWrap: true,          
          layers: [horsehead]
        });

        var baseLayers = {
            "Horsehead": horsehead,
            "Helix": helix

        };

        L.control.layers(baseLayers).addTo(map);
      }
    </script>
    <style>
      html, body, #map { width:100%; height:100%; margin:0; padding:0; }
    </style>
  </head>
  <body onLoad="init()">
    <div id="map"></div>
  </body>
</html>

这几天一直在咀嚼这个。真的很感激你能引导我朝着正确的方向前进。谢谢...

【问题讨论】:

    标签: javascript layer leaflet


    【解决方案1】:

    知道了。原来我混合了几个 L.tileLayer 和 L.map 属性。当我把它理顺后,它工作得很好......

    【讨论】:

    • 您能否详细说明您是如何解决这个问题的?谢谢!
    猜你喜欢
    • 1970-01-01
    • 2019-07-11
    • 2016-12-18
    • 1970-01-01
    • 2018-02-16
    • 1970-01-01
    • 2012-07-26
    • 2023-03-17
    相关资源
    最近更新 更多