Skip to content

Commit

Permalink
fix: 下载zoom限制,切换瓦片grid显示问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Hxy1992 committed Jun 8, 2022
1 parent 083108f commit c355e42
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 25 deletions.
6 changes: 6 additions & 0 deletions packages/renderer/src/components/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
:visible="saveVisible"
:download-extent="downloadExtent"
:base-layer="saveLayers"
:limit-max-zoom="limitMaxZoom"
:limit-min-zoom="limitMinZoom"
@ok="save"
@cancel="cancelSave"
/>
Expand Down Expand Up @@ -112,6 +114,8 @@ export default defineComponent({
helpVisible: false,
setVisible: false,
saveLayers: [],
limitMinZoom: 1,
limitMaxZoom: 18,
};
},
computed: {
Expand Down Expand Up @@ -167,6 +171,8 @@ export default defineComponent({
}
const {titleLayer} = map.getBaseMapConfig();
this.saveLayers = titleLayer;
this.limitMaxZoom = titleLayer.getMaxZoom();
this.limitMinZoom = titleLayer.getMinZoom();
this.saveVisible = true;
map.fitExtent();
return true;
Expand Down
10 changes: 9 additions & 1 deletion packages/renderer/src/components/Save.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ export default defineComponent({
required: true,
type: [Object, Array],
},
limitMinZoom: {
required: true,
type: Number,
},
limitMaxZoom: {
required: true,
type: Number,
},
},
setup() {
Expand Down Expand Up @@ -175,7 +183,7 @@ export default defineComponent({
if (isNaN(minZoom) || isNaN(maxZoom)) {
return window.$message.warning('层级格式错误,请输入非负整数');
}
if (minZoom >= maxZoom || minZoom < 0 || maxZoom > 18) {
if (minZoom >= maxZoom || minZoom < this.limitMinZoom || maxZoom > this.limitMaxZoom) {
return window.$message.warning('层级格式错误');
}
const param = {
Expand Down
55 changes: 35 additions & 20 deletions packages/renderer/src/utils/baseMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,17 @@ export default class baseMap{
// attribution: param.layer.attribution,
...param.layer.exteral,
});
this.map.removeBaseLayer(this.map.getBaseLayer());
const oldBaseLayer = this.map.getBaseLayer();
if (oldBaseLayer && oldBaseLayer.config()?.debug) {
baseLayer.config({debug: true});
}
this.map.removeBaseLayer(oldBaseLayer);
this.map.setBaseLayer(baseLayer);
this.map.setSpatialReference({
projection : param.layer.prejection,
});

// testDraw(this.map.getBaseLayer(), {x:24,y:12,z:5}); // 测试-绘制瓦片外框
}
// 绘制矩形、编辑矩形位置
startDraw() {
Expand Down Expand Up @@ -178,7 +184,6 @@ export default class baseMap{
}

let _testDraw;
let _testPrj;
/**
* 根据行列号绘制瓦片外框
* @param {*} tileLayer
Expand All @@ -188,18 +193,16 @@ export function testDraw(tileLayer, tileConfig) {
if (!_testDraw) {
const map = tileLayer.getMap();
_testDraw = new maptalks.VectorLayer('test-vector').addTo(map);
_testPrj = _testDraw.getProjection();
}
_testDraw.clear();
const extent = calcExtentByTile(tileLayer, tileConfig);
const left = _testPrj.unproject({x:extent.xmin, y:extent.ymin});
const right = _testPrj.unproject({x:extent.xmax, y:extent.ymax});
const polygon = new maptalks.Polygon([
[
[left.x, -right.y],
[right.x, -right.y],
[right.x, -left.y],
[left.x, -left.y],
[left.x, -right.y],
[extent.xmin, extent.ymax],
[extent.xmax, extent.ymax],
[extent.xmax, extent.ymin],
[extent.xmin, extent.ymin],
[extent.xmin, extent.ymax],
],
], {
visible : true,
Expand All @@ -215,6 +218,10 @@ export function testDraw(tileLayer, tileConfig) {
'lineWidth' : 1,
'polygonFill' : 'rgb(135,196,240)',
'polygonOpacity' : 0.3,
'textName' : `X: ${tileConfig.x}, Y: ${tileConfig.y}, Z: ${tileConfig.z}`,
'textFill' : '#34495e',
'textPlacement' : 'polygon',
'textSize' : 16,
},
});
_testDraw.addGeometry(polygon);
Expand All @@ -231,16 +238,24 @@ export function calcExtentByTile(tileLayer, tileConfig) {
const { x, y, z } = tileConfig;
const { width, height } = tileLayer.getTileSize();
const spatialReference = tileLayer.getSpatialReference();
const prj = spatialReference.getProjection();
const resolution = spatialReference.getResolution(z);
const fullExtent = spatialReference.getFullExtent();
const xmin = resolution * x * width + fullExtent.xmin;
const xmax = xmin + width * resolution;
const ymin = resolution * y * height + fullExtent.ymin;
const ymax = ymin + height * resolution;
return {
xmin,
xmax,
ymin,
ymax,
};

if (spatialReference.getProjection().code === 'BAIDU') {
throw new Error('暂不支持百度');
} else {
const xmin = resolution * x * width + fullExtent.xmin;
const xmax = xmin + width * resolution;
const ymin = resolution * y * height + fullExtent.ymin;
const ymax = ymin + height * resolution;
const leftBottom = prj.unproject({x:xmin, y:ymin});
const rightTop = prj.unproject({x:xmax, y:ymax});
return {
xmin: leftBottom.x,
xmax: rightTop.x,
ymin: -leftBottom.y,
ymax: -rightTop.y,
};
}
}
4 changes: 0 additions & 4 deletions packages/renderer/src/utils/fileSaveTms.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import { setState } from './progress';
import { downloadLoop } from './download';

// import {testDraw} from './baseMap';

/**
* 下载TMS瓦片
*/
Expand Down Expand Up @@ -39,8 +37,6 @@ export class TileTMS {
this.apiEnsureDirSync(temppath);
const savePath = temppath + '\\' + tile.y + pictureType;
list.push({zoom: tile.z, url:tile.url, savePath});

// testDraw(this.titleLayer, tile); // 测试-绘制瓦片外框
}
}
return list;
Expand Down

0 comments on commit c355e42

Please sign in to comment.