vue使用天地图、openlayers实现多个底图叠加显示效果

实现效果:

需求:根据返回的经纬度列表通过天地图、openlayers实现底图添加(航道图层、线图层、水深图层

tk:自己申请的密钥

安装opelayers

cnpm i -S ol
#或者
npm install ol
<script>
    // openlayers地图
import "ol/ol.css";
import {
  Icon,
  Style,
  Stroke
} from "ol/style";
import 'ol/ol.css'
import Map from "ol/Map";
import View from "ol/View";
import TileLayer from "ol/layer/Tile";
import XYZ from "ol/source/XYZ";
import { get as getProjection } from "ol/proj.js";
import { getBottomLeft, getTopRight } from 'ol/extent.js'
import { Vector as SourceVec } from 'ol/source';
import { Vector as LayerVec } from 'ol/layer';
import Overlay from "ol/Overlay";//弹窗
import {Point} from "ol/geom";
import {Feature} from "ol";
import { defaults as defaultControls } from "ol/control";//默认缩放
import {FullScreen,ScaleLine} from "ol/control";//全屏,比例尺控件
import TileGrid from 'ol/tilegrid/TileGrid';
import { LineString, Polygon } from 'ol/geom.js'
import { setTimeout } from 'timers';
import {Polyline} from "ol/format";
// import { vectorContext } from "ol/render";
import { getVectorContext } from "ol/render";
import {defaults as defaultInteractions} from 'ol/interaction';//旋转

export default {
        data(){
            tk:"密钥",
            center:{
                longitude:"",
                latitude:""
            },
            map:null,
        },
        methods:{
            initMap() {
              let defaultsMap = {
                tileUrl1:"图层地址1",
                tileUrl2:"图层地址2",
                tileUrl3:"图层地址3",
                origin: [-400, 400],
                zoom: 5,
                resolutions: [
                      //根据项目需要设置
                ],
                fullExtent: [
                          //根据项目需要设置
                ],
                inters: [1000, 100],
                center: [this.center.longitude, this.center.latitude],
                projection: getProjection("EPSG:4326")
              };
              // let projection = getProjection('EPSG:4326');

              // 底图天地图注记  cta——道路+中文注记
              let baseLayer = new TileLayer({
                title: "天地图",
                source: new XYZ({
                  url:"http://t4.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=" +this.tk
                 }),
                  zIndex: 2
          });
      //天地图路网
              let roadLayer = new TileLayer({
                    title: "天地图路网",
                    source: new XYZ({
                        projection: defaultsMap.projection,
                        url:"http://t4.tianditu.com/DataServer?T=vec_c&x={x}&y={y}&l={z}&tk=" +this.tk
                    }),
                    zIndex: 1
              });

              // 加载地图层mapservice

              let tileGrid = new TileGrid({
                tileSize: 256,
                origin: defaultsMap.origin,
                extent: defaultsMap.fullExtent,
                resolutions: defaultsMap.resolutions
              });

              // 航道图层
              let cjinobeaconMap = new TileLayer({
                  source: new XYZ({
                      tileGrid: tileGrid,
                      projection: defaultsMap.projection,
                      url: defaultsMap.tileUrl1
                    }),
                    zIndex: 9
              });
              // 线图层
              let framesMap = new TileLayer({
                    source: new XYZ({
                      tileGrid: tileGrid,
                      projection: defaultsMap.projection,
                      url: defaultsMap.tileUrl2
                    }),
                    zIndex: 10
              });

              // 水深图层
              let soundgMap = new TileLayer({
                    source: new XYZ({
                      tileGrid: tileGrid,
                      projection: defaultsMap.projection,
                      url: defaultsMap.tileUrl3
                    }),
                    zIndex: 11
              });

              // 加载地图
              this.map = new Map({
                    target: "trajecttoryMap",
                    controls: defaultControls().extend([
                      new FullScreen(),
                      new ScaleLine({
                        units: "metric"
                      })
                  // new ZoomSlider()
                ]),
                interactions: defaultInteractions({
                  pinchRotate: false // 移动端禁止地图旋转
                }),
                loadTilesWhileAnimating: true,
                layers: [baseLayer, roadLayer, cjinobeaconMap, framesMap, soundgMap],
                //overlays: [this.overlay], // 把弹窗加入地图
                view: new View({
                      projection: defaultsMap.projection,
                      center: defaultsMap.center,
                      extent: defaultsMap.fullExtent,
                      // resolutions: defaultsMap.resolutions,
                      zoom: 14,
                      minZoom: 7,
                      maxZoom:17
                })
              });

            },
        },
        mounted(){
            this.initMap();
        }
}
</script>

到此这篇关于vue使用天地图、openlayers实现多个底图叠加显示的文章就介绍到这了,更多相关vue天地图openlayers内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • vue调用高德地图实例代码

    一. vue-amap,一个基于 Vue 2.x 和高德地图的地图组件 https://elemefe.github.io/vue-amap/#/ 这个就不细说了,按照其文档,就能够安装下来. 二. 按照官方提供的方法引入 1.修改webpac.base.conf.js文件 externals: { 'AMap': 'AMap' } 2.引入sdk 引入有两种方式,一种是页面直接引入 复制代码 代码如下: <script type="text/javascript" src=&q

  • vue利用openlayers加载天地图和高德地图

    目录 一.天地图部分 1.在vue中安装openlayers 二.高德地图部分 一.天地图部分 1.在vue中安装openlayers npm i --save ol 这里说的vue是基于脚手架构建的. 新建个页面,也就是vue文件,配置好路由.接着就是可以直接放入我的代码运行显示了. <template> <div class="wrapper"> <div>天地图</div> <div class="map"

  • 在vue项目中引入高德地图及其UI组件的方法

    引入高德地图: 打开index.html,引用高德地图的JavaScript API: <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=你的API key"></script> 在"key="这里添加你申请的key,key不需要加引号. 引入高德地图UI组件,只需要在上面代码后面再加一串代码: <script

  • Vue Echarts实现可视化世界地图代码实例

    Echarts实现可视化世界地图模拟迁徙,以我自己开发过程. 下载Echarts依赖: npm install echarts 成功以后引入依赖: import echarts from 'echarts' peopleInsertCharts为生成echarts容器. let myChart = echarts.init(document.getElementById('peopleInsertCharts')) 容器一定要给宽高,否则echarts生成初始化页面不会显示.需要自适应的可以js

  • vue-openlayers实现地图坐标弹框效果

    本文实例为大家分享了vue-openlayers实现地图坐标弹框的具体代码,供大家参考,具体内容如下 openlayers 这个效果是点击地图,弹出坐标信息. 点击地图边缘时,底图会跟着移动,使弹窗能完整显示出来. <template> <div class="vm"> <h2 class="h-title">弹窗 popup</h2> <div id="map" class="ma

  • 解决Vue动态加载本地图片问题

    最近遇到了个问题,用v-bind动态绑定img的src,图片加载不出来.控制台显示src是有获取到图片地址的,可是就是加载不出来. 最后才发现原因原来是浏览器中直接显示'./img/img1.png',也就是没有经过编译的步骤,直接将获取到的数据当作字符串显示. 解决方法: 1.在当前界面全局import图片地址 //使用import引入 import img1 from './img/img1.png' import img2 from './img/img2.png' export defa

  • Vue-Cli 3.0 中配置高德地图的两种方式

    vue 中使用高德地图有两种方式 一.vue-amap 组件 官网: https://elemefe.github.io/vue-amap/#/ 开始的时候是打算用这个组件做地图功能的,但是尝试之后存在些问题,所以就放弃了,可能是我的使用方式不对.我所遇到的问题: 1. 安装之后使用,始终提示跨域问题. 2. 页面刷新之后地图出不来,第一次进入页面时没问题.因为这两个问题所以放弃了这个组件的使用.我想可能是我哪个地方代码有问题. 二.直接引用高德地图 SDK 因为第一种方式尝试失败了,所以我选择

  • vue百度地图 + 定位的详解

    vue 百度地图 + 定位 前提需要自己有百度的密钥,如没有可以去百度地图申请 一.在主目录下的index.html引入js,例如:   二.在webpack.base.conf.js配置文件中配置BMap,在module.exports 中与entry平级,例如: 三.在项目中引入BMap: 四.代码: <template> <div class="home"> <div id="allmap" class="allmap&

  • 详解vue项目中调用百度地图API使用方法

    步骤一:申请百度地图密钥: JavaScript API v1.4以及以前的版本无序申请秘钥(ak),自v1.5版本开始需要先申请秘钥(ak),才可以使用,如需获取更高的配额,需要申请  认证企业用户.百度地图API 链接地址:http://lbsyun.baidu.com/apiconsole/key 步骤二:在index.html中添加百度地图JavaScript API接口: <script src="http://api.map.baidu.com/api?v=1.4"

  • vue使用openlayers创建地图

    vue项目中使用openlayers创建地图,供大家参考,具体内容如下 前期准备 安装node环境 安装cnpm 安装vue-cli 以上步骤网上都有很多教程 搭建vue项目 vue create vue-ol 按照提示一步步搭建vue项目 cd vue-ol npm run serve 浏览器打开 http://localhost:8080/ 就可以看到初始化的vue项目页面 vue项目安装openlayers cnpm i ol --s main.js中引入ol.css import 'ol

随机推荐