Openlayers示例6 | ArcGIS REST with 512x512 Tiles

ArcGIS REST with 512x512 Tiles

ol/source/XYZ支持的ArcGIS REST tile服务具有定制的tile大小(这里:512x512像素)和投影(这里:EPSG:4326)。

<!DOCTYPE html>
<html lang="zn">

<head>
  <meta charset="UTF-8">
  <!-- 引入OpenLayers CSS样式 -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.13.0/css/ol.css"
    type="text/css">
  <!-- 引入OpenLayers JS库 -->
  <script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.13.0/build/ol.js"></script>
  <!-- css代码 -->
  <style type="text/css">
    .map {
      width: 100%;
      height: 600px;
    }
  </style>
  </style>
  <title>ArcGIS REST with 512x512 Tiles</title>
</head>
<body>
  <div id="map" class="map"></div>
</body>
<script>
  // 初始化地图
 const map = new ol.Map({
  //  绑定doc元素
  target: 'map',
  layers: [
    // 添加图层
    new ol.layer.Tile({
      // https://openlayers.org/en/latest/apidoc/module-ol_source_XYZ-XYZ.html
      source: new ol.source.XYZ({
        attributions: 'Copyright:© 2013 ESRI, i-cubed, GeoEye',
        url:
          'https://services.arcgisonline.com/arcgis/rest/services/' +
          'ESRI_Imagery_World_2D/MapServer/tile/{z}/{y}/{x}',
        maxZoom: 15,  // 最大级别
        projection: 'EPSG:4326',  // 投影坐标
        tileSize: 512, // 瓦片大小
        maxResolution: 180 / 512, // 最大分辨率
        wrapX: true,  // 是否水平包裹世界
      }),
    }),
  ],
  // 视图范围
  view: new ol.View({
    center: [0, 0],  // 视图的初始中心。projection如果未设置用户投影,则使用该选项指定中心的坐标系。如果未设置,则不会获取层源,但稍后可以使用 设置中心#setCenter。
    projection: 'EPSG:4326',  // 投影。默认值为球形墨卡托'EPSG:3857'
    zoom: 2,  // 仅在resolution未定义时使用。用于计算视图初始分辨率的缩放级别。
    minZoom: 2,  // 默认0。用于确定分辨率约束的最小缩放级别。它与maxZoom(or minResolution) 和一起使用zoomFactor。请注意,如果maxResolution还提供了,它的优先级高于minZoom.
  }),
});
</script>
</html>
posted @ 2022-03-20 15:03  槑孒  阅读(225)  评论(0编辑  收藏  举报