欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 幼教 > uniapp (vue3)整合 OpenLayer3

uniapp (vue3)整合 OpenLayer3

2024/10/25 3:22:38 来源:https://blog.csdn.net/qq_19688207/article/details/142356959  浏览:    关键词:uniapp (vue3)整合 OpenLayer3
  1. 安装openLayer插件

命令行:npm install ol

  1. 安装sass插件

命令行:npm install -D sass

使用方法:

***

***

<style scoped lang="scss">

</style>

  1. 安装ElementPlus

命令行:npm install element-plus --save

引用方法:

实际代码:

// #ifndef VUE3

import Vue from 'vue'

import App from './App'

Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({

...App

})

app.$mount()

// #endif

// #ifdef VUE3

import {

createSSRApp

} from 'vue'

import App from './App.vue'

import ElementPlus from 'element-plus'

import 'element-plus/dist/index.css'

export function createApp() {

const app = createSSRApp(App)

app.use(ElementPlus)

return {

app

}

}

// #endif

4、代码

<template><view class="map" id="mapView"><button @click="goTo()" class="btn" type="primary">测试</button></view>
</template><script setup>
import "ol/ol.css";
import {ref,onMounted} from 'vue';
import {ScaleLine, defaults as defaultControls} from 'ol/control';
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import TileLayer from "ol/layer/Tile.js";
import XYZ from "ol/source/XYZ.js";
import { fromLonLat } from "ol/proj.js";
import  ZoomToExtent  from 'ol/control/ZoomToExtent.js';
import  ZoomSlider  from 'ol/control/ZoomSlider.js';
import FullScreen from 'ol/control/FullScreen.js';
import Feature from "ol/Feature.js";
import {LineString,Point } from 'ol/geom.js';
import { Icon, Style,Stroke,Circle,Fill } from "ol/style.js";onMounted(()=>{initMap();
})const initMap = () =>{map.setTarget("mapView")
}const sourceXYZ = new XYZ({url:"http://webst0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}",wrapX:false
});const gaodeLayer = new TileLayer({title:"高德地图",source:sourceXYZ
});const map = new Map({//target:"mapView",layers:[gaodeLayer],view:new View({center:fromLonLat([125.33,43.90]),projection:'EPSG:3857',minZoom: 4,zoom:10}),controls:defaultControls({zoom:false,//不显示放大放小按钮rotate:false,// 不显示指北针控件attribution:false//不显示右下角的地图信息控件}).extend([// 比例尺new ScaleLine({//设置比例尺单位,degrees、imperial、us、nautical、metric(度量单位)units: "metric"})])
});/*// 定位范围控件
const zoomToExtent = new ZoomToExtent({// 吉林市范围extent:[14065372.073666595, 5371093.384611047, 14121465.137798928, 5492671.839893217]
})
map.addControl(zoomToExtent);// 放大缩小滑动控件
const zoomSlider = new ZoomSlider();
map.addControl(zoomSlider);// 全屏控件
const fullScreen = new FullScreen();
map.addControl(fullScreen);
*/
// 测试按钮
const goTo = () =>{// 获取当前可见视图范围console.log(map.getView().calculateExtent())
}</script><style scoped lang="scss">/*去除顶部导航栏*/*{margin:0;padding:0}.map{width:100vw;height: 95vh;position: relative;z-index: 1;.btn {margin-top: 80px;margin-left: 85%;width:80rpx;height:60rpx;position: absolute;z-index: 10;}}</style>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com