OpenLayers3-3-Tiled ArcGIS MapServer

本文展示了如何使用ArcGISRESTMapService作为切片,并提供了相关API文档,包括ol.Map, ol.View, ol.layer.Tile, ol.source.MapQuest, ol.source.TileArcGISRest等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文地址:http://openlayers.org/en/v3.12.1/examples/arcgis-tiled.html

This example shows how to use an ArcGIS REST MapService as tiles. This source type supports Map and Image Services. For cached ArcGIS services, better performance is available by using ol.source.XYZ instead.

Related API documentation:
ol.Map,ol.View,ol.layer.Tile,ol.source.MapQuest,ol.source.TileArcGISRest

翻译:
这个例子演示了如何使用ArcGIS REST MapService作为切片。这个来源类型支持地图和图片服务。对于缓存的ArcGIS服务,更好的展现方式是使用ol.source.XYZ

相关的api文档包括:
ol.Map,ol.View,ol.layer.Tile,ol.source.MapQuest,ol.source.TileArcGISRest

<!DOCTYPE html>
<html>
  <head>
    <title>Tiled ArcGIS MapServer</title>
    <link rel="stylesheet" href="http://openlayers.org/en/v3.12.1/css/ol.css" type="text/css">
    <script src="http://openlayers.org/en/v3.12.1/build/ol.js"></script>
  </head>
  <body>
    <div id="map" class="map"></div>
    <script>
      var url = 'http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/' +
          'Specialty/ESRI_StateCityHighway_USA/MapServer';

      var layers = [
        //底图 osm, sat, hyb.
        new ol.layer.Tile({
          source: new ol.source.MapQuest({layer: 'sat'})
        }),
        //ArcGIS的切片
        new ol.layer.Tile({
          //ArcGIS的切图范围,主要坐标系
          extent: [-13884991, 2870341, -7455066, 6338219],
          source: new ol.source.TileArcGISRest({
            url: url
          })
        })
      ];
      var map = new ol.Map({
        layers: layers,
        target: 'map',
        view: new ol.View({
          center: [-10997148, 4569099],
          zoom: 4
        })
      });
    </script>
  </body>
</html>
### uni-app 中集成 OpenLayers 和 Vue3 #### 文件准备与配置 为了在uni-app中成功使用OpenLayers,需先下载OpenLayers并将`ol.css`和`ol.js`放置于项目的`static`文件夹下[^1]。 ```javascript // main.js 或者 app.vue 的 <script setup> 部分 import.meta.glob(&#39;@/static/openlayers/*.css&#39;); ``` 由于直接通过`import`引入可能会造成打包失败的问题,在Vue组件内利用`<script>`标签动态创建脚本节点来加载`ol.js`是一个可行方案。这一步骤应在`mounted()`生命周期钩子函数里完成,以确保DOM已经就绪。 #### 组件内部实现 考虑到renderjs模块内的`this`指向问题——即该上下文中访问不到外部定义的数据或方法的情况,建议采用事件驱动的方式来进行跨层通信。对于H5平台而言,可以直接操作全局对象;但对于APP环境,则可能需要借助vuex或其他状态管理工具共享数据[^2]。 下面展示了一个简单的例子,说明怎样初始化OpenLayers的地图实例: ```html <!-- AppMap.vue --> <script> export default { name: &#39;AppMap&#39;, data() { return {}; }, methods: {}, }; </script> <script module="openlayers" lang="renderjs"> let map; const initMap = () => { map = new ol.Map({ target: &#39;map-container&#39;, // HTML容器ID layers: [ new ol.layer.Tile({ source: new ol.source.XYZ({ url: &#39;http://t0.tianditu.gov.cn/DataServer?T=vec_w&x={x}&y={y}&l={z}&#39;, // 天地图瓦片服务URL模板 attributions: &#39;<a href="https://www.tianditu.gov.cn">天地图</a>&#39;, }), }), ], view: new ol.View({ center: ol.proj.fromLonLat([116.4074, 39.9042]), // 设置中心点坐标(北京) zoom: 10, }), }); }; export default { mounted() { const script = document.createElement(&#39;script&#39;); script.src = &#39;/static/openlayers/ol.js&#39;; script.onload = initMap; document.head.appendChild(script); } } </script> <style scoped> @import &#39;../static/openlayers/ol.css&#39;; #map-container { width: 100%; height: calc(100vh - var(--header-height)); } </style> <template> <div id="map-container"></div> </template> ``` 这段代码展示了如何在一个名为`AppMap.vue`的单文件组件中设置并启动一个基于OpenLayers的地图应用,其中包含了来自天地图的服务作为底图[^1][^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值