VUE项目 openlayers简单使用

1 篇文章 0 订阅

在项目中安装依赖

npm i ol --save

调用相关API

选取一个DOM元素,并进行相关的配置,完整代码:

<template>
  <div id="wrapper">
    <div id="map"></div>
  </div>
</template>

<script>
import Map from "ol/Map";
import View from "ol/View";
// 添加图层
import TileLayer from "ol/layer/Tile";
import OSM from "ol/source/OSM";
//引入样式文件
import "ol/ol.css"

export default {
    name: 'map',
    data() {
        return {
          map: null  
        }
    },
    mounted() {
      this.init()
    },
    methods: {
      init() {
        this.map = new Map({
          layers:[
            new TileLayer({   //数据源
              source: new OSM()  //openlayers内置的数据源
            })
          ],
          target: 'map',  //绑定页面中DOM元素的id
          view: new View({  //视图配置
            center: [0,0],  //地图中心点坐标,经度0、纬度0
            zoom: 2  //定义地图显示层级为2
          }),
        })
      }
    }
}
</script>

<style scoped lang="stylus">
  #map
    width 500px
    height 500px
</style>

此时,一个简易版的地图就出现了

学习资源:
官方文档:https://openlayers.org/
中文文档: http://linwei.xyz/ol3-primer/ch01/index.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值