Skip to content

Commit 25cdea3

Browse files
committed
openlayers mbglstyle增加getStylesBySourceLayer方法
1 parent 93a428f commit 25cdea3

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

dist/iclient9-openlayers.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62377,6 +62377,7 @@ var MapboxStyles = exports.MapboxStyles = function (_ol$Observable) {
6237762377
_this.url = options.url ? options.url + '/tileFeature/vectorstyles.json?type=MapBox_GL&styleonly=true' : "";
6237862378
_this.resolutions = options.resolutions;
6237962379
_this.style = options.style;
62380+
_this.layersBySourceLayer = {};
6238062381
(0, _olExtends.olExtends)(_this.map);
6238162382
if (_this.style) {
6238262383
_this._mbStyle = _this.style;
@@ -62403,6 +62404,50 @@ var MapboxStyles = exports.MapboxStyles = function (_ol$Observable) {
6240362404
value: function getStyleFunction() {
6240462405
return this.featureStyleFuntion;
6240562406
}
62407+
/**
62408+
* @function ol.supermap.MapboxStyles.getStylesBySourceLayer
62409+
* @param {string} sourceLayer - 数据图层名称。
62410+
* @return
62411+
*/
62412+
62413+
}, {
62414+
key: 'getStylesBySourceLayer',
62415+
value: function getStylesBySourceLayer(sourceLayer) {
62416+
if (this.layersBySourceLayer[sourceLayer]) {
62417+
return this.layersBySourceLayer[sourceLayer];
62418+
}
62419+
var layers = [];
62420+
var _iteratorNormalCompletion = true;
62421+
var _didIteratorError = false;
62422+
var _iteratorError = undefined;
62423+
62424+
try {
62425+
for (var _iterator = this._mbStyle.layers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
62426+
var layer = _step.value;
62427+
62428+
if (layer['source-layer'] !== sourceLayer) {
62429+
continue;
62430+
}
62431+
layers.push(layer);
62432+
}
62433+
} catch (err) {
62434+
_didIteratorError = true;
62435+
_iteratorError = err;
62436+
} finally {
62437+
try {
62438+
if (!_iteratorNormalCompletion && _iterator.return) {
62439+
_iterator.return();
62440+
}
62441+
} finally {
62442+
if (_didIteratorError) {
62443+
throw _iteratorError;
62444+
}
62445+
}
62446+
}
62447+
62448+
this.layersBySourceLayer[sourceLayer] = layers;
62449+
return layers;
62450+
}
6240662451
}, {
6240762452
key: 'updateStyles',
6240862453
value: function updateStyles(layerStyles) {

dist/iclient9-openlayers.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/openlayers/overlay/vectortile/MapboxStyles.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export class MapboxStyles extends ol.Observable {
6060
this.url = options.url ? options.url + '/tileFeature/vectorstyles.json?type=MapBox_GL&styleonly=true' : "";
6161
this.resolutions = options.resolutions;
6262
this.style = options.style;
63+
this.layersBySourceLayer = {};
6364
olExtends(this.map);
6465
if (this.style) {
6566
this._mbStyle = this.style;
@@ -80,6 +81,25 @@ export class MapboxStyles extends ol.Observable {
8081
getStyleFunction() {
8182
return this.featureStyleFuntion;
8283
}
84+
/**
85+
* @function ol.supermap.MapboxStyles.getStylesBySourceLayer
86+
* @param {string} sourceLayer - 数据图层名称。
87+
* @return
88+
*/
89+
getStylesBySourceLayer(sourceLayer) {
90+
if (this.layersBySourceLayer[sourceLayer]) {
91+
return this.layersBySourceLayer[sourceLayer];
92+
}
93+
const layers = [];
94+
for (const layer of this._mbStyle.layers) {
95+
if (layer['source-layer'] !== sourceLayer) {
96+
continue;
97+
}
98+
layers.push(layer);
99+
}
100+
this.layersBySourceLayer[sourceLayer] = layers;
101+
return layers;
102+
}
83103
updateStyles(layerStyles) {
84104
if (Object.prototype.toString.call(layerStyles) !== '[object Array]') {
85105
layerStyles = [layerStyles];

0 commit comments

Comments
 (0)