项目需要引入超图,再次将引入方式记录如下:
首先使用命令安装超图依赖插件:
npm install @supermap/vue-iclient --save
安装成功后进行全局引入,也可以局部页面引入,如下:
main.js引入
import VueiClient from '@supermap/vue-iclient';
Vue.use(VueiClient);
引入成功后进行加载超图,如下
<template>
<div id="iGisMap">
</div>
</template>
<script>
import { XYZ as XYZSource, Vector as VectorSource } from 'ol/source';
import Vector from 'ol/source/Vector.js';
import GeoJSON from 'ol/format/GeoJSON.js';
import {bbox} from 'ol/loadingstrategy.js';
import 'ol/ol.css'
import { Map, View } from 'ol'
import Point from 'ol/geom/Point'
import TileLayer from 'ol/layer/Tile'
import { TileSuperMapRest } from '@supermap/iclient-ol'
import Feature from 'ol/Feature'
import { Style, Icon } from 'ol/style'
import Draw from 'ol/interaction/Draw'
import VectorLayer from 'ol/layer/Vector'
import Overlay from 'ol/Overlay'
export default {
data() {
return {
map:null,
pointSource:null,
pointLayer:null,
feature:null,
featureStyle:null,
popupLayer: null,
},
created() {},
watch: {},
computed: {},
mounted() {
this.initMap()
},
methods: {
initMap(){
let url = "https://iserver.supermap.io/iserver/services/map-world/rest/maps/World";
// 初始化地图信息
this.mapObj = new window.iGis.GisMap()
this.map = new Map({
target: 'iGisMap',//对应div容器的id
view: new View({
center: [0, 0],//地图中心
zoom: 18,//缩放层级
projection: 'EPSG:4326'//坐标系
})
});
// 添加图层
let layer = new TileLayer({
source: new TileSuperMapRest({
url: url,//地图服务地址
wrapX: true//是否在地图水平坐标轴上重复
}),
projection: 'EPSG:4326'//坐标系
});
this.map.addLayer(layer);//添加图层到地图
setTimeout(()=>{
this.map.updateSize(); //地图适配div容器
},100)
}
</script>
<style>
</style>