Vue+OpenLayers学习系列(二)OpenLayers 读取 ArcGIS Server 发布的地图服务

一、首先用 ArcGIS Server 发布地图服务

在 ArcMap 中文件-共享为-服务,然后选择发布服务。

二、Vue + OpenLayers 读取发布的 ArcGIS Server 地图服务

<template>
  <div id="map" ref="rootmap">

  </div>
</template>
<script>
  import 'ol/ol.css';
  import Map from 'ol/Map';
  import View from 'ol/View';
  import {Tile as TileLayer, Image as ImageLayer} from 'ol/layer';
  import {OSM, ImageArcGISRest} from 'ol/source';
  export default{
    name: 'OlImage',
    data(){
      return{
          map: null
      };
    },
    mounted(){

        var url = 'http://localhost:6080/arcgis/rest/services/Test/hzzg/MapServer';   //结果可以出来
        this.map = new Map({
          target: "map",
          layers: [
              new TileLayer({
                source: new OSM()
              }),
              new ImageLayer({
                source: new ImageArcGISRest({   //可以得出结果
                  ratio: 1,
                  url: url
                })
              })
          ],
          view: new View({
            center: [-10997148, 4569099],
            zoom: 4
          })
        });
    }
  };

</script>

<style>
  #map{
    height:800px;
    width: 1400px;
  }
  /*隐藏ol的一些自带元素*/
  .ol-attribution,.ol-zoom { display: none;}

</style>

 

 

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要在Vue中使用高德地图实现导航,首先需要引入高德地图的JavaScript API。可以通过在Vue项目中的index.html文件中添加以下script标签来引入API: ``` <script src="https://webapi.amap.com/maps?v=1.4.15&key=your_api_key"></script> ``` 其中,"your_api_key"需要替换为你在高德地图开放平台申请的API密钥。 接下来,在Vue组件中,可以使用AMap对象来创建地图实例以及实现导航功能。 首先,在vue组件的mounted钩子函数中,实例化地图对象: ```javascript mounted() { const map = new AMap.Map("mapContainer", { zoom: 15, center: [经度, 纬度] }); } ``` 这里,“mapContainer”是一个div元素的id,用来承载地图。 然后,可以使用AMap对象的Driving类来实现导航功能: ```javascript mounted() { const map = new AMap.Map("mapContainer", { zoom: 15, center: [经度, 纬度] }); const driving = new AMap.Driving({ map: map, panel: "naviPanel" }); const startPoint = new AMap.LngLat(起点经度, 起点纬度); const endPoint = new AMap.LngLat(终点经度, 终点纬度); driving.search(startPoint, endPoint, function(status, result) { if (status === 'complete') { console.log('导航搜索成功!'); } else { console.log('导航搜索失败!'); } }); } ``` 在上述代码中,通过实例化Driving类并传入地图对象map和导航结果显示的panel容器的id,然后可以使用search方法进行导航搜索。 需要注意的是,经度和纬度需要根据实际情况进行替换。 最后,在Vue组件的template中,添加地图容器和导航结果容器的代码: ```html <template> <div> <div id="mapContainer"></div> <div id="naviPanel"></div> </div> </template> ``` 通过上述步骤,就可以在Vue中调用高德地图实现导航功能了。当然,还可以根据具体需求,调整地图的样式和导航的方式等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值