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

本文介绍了在Vue项目中全局引入OpenLayers和SuperMap iClient for OL,处理加载矢量切片地图时出现图片破碎的问题。通过计算不同级别的分辨率并设置合适的投影和避让参数,确保地图正确显示。同时展示了如何使用Mapbox风格来定制地图样式。
摘要由CSDN通过智能技术生成

您需要贴一下下,您那边对接的代码的,我这边贴我的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);

})

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值