vue全局引入openlayers_vue+openlayers加载矢量切片显示不完整(图片支零破碎)

您需要贴一下下,您那边对接的代码的,我这边贴我的import Map from 'ol/Map';

import View from 'ol/View';

import proj4 from 'proj4';

import {get} from 'ol/proj';

import VectorTileLayer from 'ol/layer/VectorTile';

import { Logo, TileSuperMapRest } from '@supermap/iclient-ol';

import {VectorTileSuperMapRest} from '@supermap/iclient-ol/overlay/VectorTileSuperMapRest';

import TileGrid from 'ol/tilegrid/TileGrid';

import {MapboxStyles} from '@supermap/iclient-ol/overlay/vectortile/MapboxStyles';

import MVT from 'ol/format/MVT';

import Feature from 'ol/Feature';

import olms from 'ol-mapbox-style';

export default {

mounted(){

var url = (window.isLocal ? window.server : "https://iserver.supermap.io") +

"/iserver/services/map-mvt-California/rest/maps/California";

let  scaleToResolution = function (scale) {

var inchPerMeter = 1 / 0.0254;

var meterPerMapUnitValue = Math.PI * 2 * 6378137 / 360;

return 1 / (scale * 96 * inchPerMeter * meterPerMapUnitValue);

};

let  getResolutions = function (zoom, scale, targetMinZoom, targetMaxZoom) {

var res = scaleToResolution(scale);

var minRes = res * Math.pow(2, zoom - targetMinZoom);

var resolutions = [];

for (var index = 0; index < targetMaxZoom - targetMinZoom + 1; index++) {

resolutions.push(minRes / Math.pow(2, index));

}

return resolutions;

};

var vectorLayer;

//通过缓存sci文件已知第10级的比例尺是0.000003461454994642,计算0到16级的分辨率

var resolutions = getResolutions(10, 0.000003461454994642, 0, 16);

var map = new Map({

target: 'map',

view: new View({

center: [-122.228687503369, 38.1364932162598],

zoom: 10,

minZoom: 10,

maxZoom: 14,

projection: 'EPSG:4326',

resolutions: resolutions

})

});

// var key = 'pk.eyJ1IjoieWFuZ2p1bmxpbiIsImEiOiJjazhpazFsdjQwNnlvM2RwNjl1dngyYmdsIn0.kuycGa4pcXob5ja5aVtgfQ';

// olms('map', 'https://api.mapbox.com/styles/v1/mapbox/bright-v9?access_token=' + key);

var format = new MVT({

featureClass: Feature

});

// format.defaultDataProjection = new ol.proj.Projection({

//     code: 'EPSG:4326',

//     units: ol.proj.Units.TILE_PIXELS

// });

var style = new MapboxStyles({

url: url,

source: 'California',

resolutions: resolutions

});

// console.log(style,'style')

style.on('styleloaded', function () {

vectorLayer = new VectorTileLayer({

//设置避让参数

declutter: true,

source: new VectorTileSuperMapRest({

url: url,

projection: 'EPSG:4326',

tileGrid: new TileGrid({

resolutions: resolutions,

origin: [-180, 90],

tileSize: 512

}),

tileType: 'ScaleXY',

format: format

}),

style: style.getStyleFunction()

});

map.addLayer(vectorLayer);

})

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Vue3中使用OpenLayers初次加载叠加图片图层,可以借助OpenLayersVue3的生命周期函数来完成。以下是一个简单的示例代码: ```vue <template> <div class="map"> <div id="map" class="map-container"></div> </div> </template> <script> import { onMounted } from 'vue'; import Map from 'ol/Map'; import View from 'ol/View'; import TileLayer from 'ol/layer/Tile'; import OSM from 'ol/source/OSM'; import ImageLayer from 'ol/layer/Image'; import ImageStatic from 'ol/source/ImageStatic'; import { fromLonLat } from 'ol/proj'; export default { name: 'MapView', setup() { let map; onMounted(() => { // 创建地图 map = new Map({ target: 'map', layers: [ new TileLayer({ source: new OSM() }) ], view: new View({ center: fromLonLat([116.39, 39.9]), zoom: 10 }) }); // 创建Image图层 const imageLayer = new ImageLayer({ source: new ImageStatic({ url: 'path/to/image.png', // 图片路径 imageSize: [width, height], // 图片大小 projection: map.getView().getProjection(), // 投影 imageExtent: [left, bottom, right, top] // 图片范围 }) }); map.addLayer(imageLayer); }); return { map }; } } </script> <style scoped> .map { width: 100%; height: 100%; } .map-container { width: 100%; height: 100%; } </style> ``` 在上面的示例中,我们使用了Vue3的`onMounted`生命周期函数来创建地图和图层。我们首先导入需要使用的OpenLayers模块,然后在`onMounted`函数中创建地图,并将OSM图层添加到地图中。接下来,我们创建了一个Image图层,并将其添加到地图中。我们使用ImageStatic源来指定要叠加的图片,需要提供图片的路径、大小、投影和范围。最后,我们将Image图层添加到地图中,这样图片就会显示在地图上了。 希望这个示例能对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值