Skip to content

Commit 138b690

Browse files
committed
【fix】修复当style里有indexbounds又同时传入tilegrid时,应该优先tilegrid
1 parent 7f9c01a commit 138b690

File tree

5 files changed

+103
-7
lines changed

5 files changed

+103
-7
lines changed

build/webpack.config.openlayers.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
var configBase = require('./webpack.config.base');
22
var fs = require('fs');
33
const chalk = require('chalk');
4+
const minimist = require('minimist');
45
//端名
56
var libName = 'openlayers';
67
//产品包名
78
var productName = 'iclient-openlayers';
89

9-
var argv = JSON.parse(process.env['npm_config_argv']);
10-
var origin = argv.original;
11-
12-
if (origin && origin.includes('deploy-ol')) {
10+
const args = minimist(process.argv.slice(2));
11+
if (
12+
args._.includes('deploy-ol') ||
13+
(process.env.npm_lifecycle_event?.includes('deploy-ol'))
14+
) {
1315
libName = 'ol';
1416
productName = 'iclient-ol';
1517
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
"karma-sonarqube-unit-reporter": "0.0.23",
116116
"karma-teamcity-reporter": "^1.1.0",
117117
"mini-css-extract-plugin": "^2.6.1",
118+
"minimist": "^1.2.8",
118119
"mock-socket": "^9.0.3",
119120
"nightwatch": "^2.3.0",
120121
"open": "^8.4.0",

src/leaflet/overlay/dataflow/NormalRenderer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export var NormalRenderer = L.GeoJSON.extend({
2323
options = options || {};
2424
if (options.style && !options.pointToLayer) {
2525
options.pointToLayer = function (geojson, latlng) {
26-
return L.circleMarker(latlng, options.style());
26+
return L.circleMarker(latlng, options.style(geojson));
2727
}
2828
}
2929
L.Util.setOptions(this, options);

src/openlayers/overlay/VectorTileSuperMapRest.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ export class VectorTileSuperMapRest extends VectorTile {
8282
me.headers = options.headers || {};
8383
me._tileType = options.tileType || 'ScaleXY';
8484
me.baseUrl = options.baseUrl;
85+
if(options.tileGrid){
86+
this.hasTileGrid = true;
87+
}
8588
this.vectorTileStyles = new VectorTileStyles();
8689
this._initialized(options);
8790

@@ -366,7 +369,7 @@ export class VectorTileSuperMapRest extends VectorTile {
366369
}
367370
this._tileUrl = SecurityManager.appendCredential(newUrl);
368371
}
369-
if (style.metadata && style.metadata.indexbounds) {
372+
if (!this.hasTileGrid && style.metadata && style.metadata.indexbounds) {
370373
const indexbounds = style.metadata.indexbounds;
371374
var max = Math.max(indexbounds[2] - indexbounds[0], indexbounds[3] - indexbounds[1]);
372375
const defaultResolutions = [];

test/openlayers/overlay/VectorTileSuperMapRestSpec.js

+91-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import View from 'ol/View';
77
import MVT from 'ol/format/MVT';
88
import Feature from 'ol/Feature';
99
import VectorTileLayer from 'ol/layer/VectorTile';
10+
import TileGrid from 'ol/tilegrid/TileGrid';
1011

1112
var url = GlobeParameter.ChinaURL;
1213
const mapObject = {
@@ -105,7 +106,7 @@ describe('openlayers_VectorTileSuperMapRest', () => {
105106
map.removeLayer(vectorLayer);
106107
}
107108
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
108-
spyGet.calls.reset();
109+
spyGet && spyGet.calls.reset();
109110
spyPost.calls.reset();
110111
spyCommit.calls.reset();
111112
});
@@ -294,4 +295,93 @@ describe('openlayers_VectorTileSuperMapRest', () => {
294295
});
295296
});
296297
});
298+
const style = {
299+
"version": 8,
300+
"name": "",
301+
"center": [0, 0],
302+
"zoom": 2,
303+
"metadata": {
304+
"indexbounds": [-400000, -400000, 400000,400000]
305+
},
306+
"sources": {
307+
"aaa": {
308+
"tiles": ["http://127.0.0.1:5566/tiles/{z}/{x}/{y}.mvt"],
309+
"type": "vector"
310+
}
311+
},
312+
"layers": [{
313+
"id": "区级政面0_24",
314+
"source": "矢量切片",
315+
"source-layer": "区级政面@矢量",
316+
"minzoom": 0.0,
317+
"maxzoom": 24.0,
318+
"type": "fill",
319+
"layout": {
320+
"visibility": "visible"
321+
}
322+
}]
323+
};
324+
it('initialize_with_tilegrid_and_metadata_indexbounds', (done) => {
325+
map = new Map({
326+
target: 'map',
327+
view: new View({
328+
center: [0, 0],
329+
zoom: 2
330+
})
331+
});
332+
vectorTileOptions = {
333+
style: style,
334+
tileGrid: new TileGrid({
335+
resolutions: [100000,50000],
336+
origin: [-4823200, 6183000],
337+
tileSize: 512,
338+
}),
339+
format: new ol.format.MVT(),
340+
}
341+
vectorTileOptions.tileLoadFunction = (tile) => {
342+
tile.setLoader(() => {
343+
tile.setFeatures([]);
344+
});
345+
};
346+
vectorTileSource = new VectorTileSuperMapRest(vectorTileOptions);
347+
vectorTileSource.once('tileloadstart', () => {
348+
expect(vectorTileSource).not.toBeNull();
349+
expect(vectorTileSource.getTileGrid().getResolutions()[0]).toBe(100000)
350+
done();
351+
});
352+
vectorLayer = new VectorTileLayer({
353+
source: vectorTileSource
354+
});
355+
map.addLayer(vectorLayer);
356+
});
357+
358+
359+
it('initialize_without_tilegrid_but_metadata_indexbounds', (done) => {
360+
map = new Map({
361+
target: 'map',
362+
view: new View({
363+
center: [0, 0],
364+
zoom: 2
365+
})
366+
});
367+
vectorTileOptions = {
368+
style: style,
369+
format: new ol.format.MVT(),
370+
}
371+
vectorTileOptions.tileLoadFunction = (tile) => {
372+
tile.setLoader(() => {
373+
tile.setFeatures([]);
374+
});
375+
};
376+
vectorTileSource = new VectorTileSuperMapRest(vectorTileOptions);
377+
vectorTileSource.once('tileloadstart', () => {
378+
expect(vectorTileSource).not.toBeNull();
379+
expect(vectorTileSource.getTileGrid().getResolutions()[0]).toBe((400000-(-400000))/512)
380+
done();
381+
});
382+
vectorLayer = new VectorTileLayer({
383+
source: vectorTileSource
384+
});
385+
map.addLayer(vectorLayer);
386+
});
297387
});

0 commit comments

Comments
 (0)