美文网首页openlayers学习笔记
三章-23-限制图层的最大/最小分辨率

三章-23-限制图层的最大/最小分辨率

作者: 彩云飘过 | 来源:发表于2020-04-20 17:51 被阅读0次

本文基于腾讯课堂老胡的课《跟我学Openlayers--基础实例详解》做的学习笔记,使用的openlayers 5.3.x api。

源码 见 1023.html ,对应的 官网示例 https://openlayers.org/en/latest/examples/min-max-resolution.html?q=ZIndex

在限制的范围之内时显示图层,在限制的范围之外时不显示图层

image.png
<!DOCTYPE html>
<html>

<head>
  <title>限制图层的最大/最小分辨率
  </title>
  <link rel="stylesheet" href="../include/ol.css" type="text/css">
  <script src="../include/ol.js"></script>
  <script src="../include/jquery-3.1.1.min.js"></script>

</head>
<style>

</style>

<body>
  <div>
   
  <div id="map" class="map"></div>

  <script>
  //当分辨率2000~20000时,TileJSON图层显示;
  //当分辨率大于20000时,TileJSON图层就显示不出来了,OSM图层就显示出来了  
       var map = new ol.Map({
        layers: [
          new ol.layer.Tile({
            source: new ol.source.OSM(),
            //  minResolution: 200,
            //  maxResolution: 2000
          }),
          new ol.layer.Tile({
            source: new ol.source.TileJSON({
              url: 'https://api.tiles.mapbox.com/v4/mapbox.natural-earth-hypso-bathy.json?secure&access_token=pk.eyJ1IjoiYWhvY2V2YXIiLCJhIjoiY2pzbmg0Nmk5MGF5NzQzbzRnbDNoeHJrbiJ9.7_-_gL8ur7ZtEiNwRfCy7Q',
              crossOrigin: 'anonymous'
            }),
            minResolution: 2000,
            maxResolution: 20000
          })
        ],
        target: 'map',
        view: new ol.View({
          center: [653600, 5723680],
          zoom: 5
        })
      });
  </script>
</body>

</html>

相关文章

网友评论

    本文标题:三章-23-限制图层的最大/最小分辨率

    本文链接:https://www.haomeiwen.com/subject/jdnquhtx.html