uniapp中使用openlayers
相关链接 https://codeleading.com/article/25216143964/#google_vignette
例子
<template> <view id="map-id" class="map-class"></view> </template> <script> export default { data() { return { mapIsLoad: false, mapBase: {}, mapInit: '', mapPoints: [], mapLines: [] }; }, created() {}, methods: {} } </script> <script module="olMap" lang="renderjs"> export default { data() { return { tiles: [], placeId: '', mapObj: null, viewObj: null, pointLayer: null, // 点位图层 pointSelect: null, // 点位图层 点击 SELayer: null // 起始、终点 } }, mounted() { if (typeof window.ol === 'function') { this.initOlMap(); console.log(1) } else { const script = document.createElement('script'); script.src = 'https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.13.0/build/ol.js'; // 可以通过此方式导入jquery,echart库 script.onload = this.initOlMap.bind(this); document.head.appendChild(script); console.log(12) } }, methods: { initOlMap() { // 地图 var map = new ol.Map({ // 绑定 DIV 元素 target: 'map-id', // 添加图层 layers: [ new ol.layer.Tile({ // 设置图层的数据源 // source: new ol.source.OSM() source: new ol.source.XYZ({ // url: 'https://tile.openstreetmap.bzh/br/{z}/{x}/{y}.png' url: 'http://192.168.22.43/mapGis/mapImage/base/{z}/{x}/{y}.png' }) }) ], // 设置视图窗口 view: new ol.View({ center: ol.proj.transform([104, 30], 'EPSG:4326', 'EPSG:3857'), zoom: 5 }) }); }, } }; </script> <style lang="less"> .map-class { width: 100%; height: 100%; } </style>
前端大牛的路上
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了