Skip to content

Commit 083533a

Browse files
[fix]mapbox经纬网加id review by songym
1 parent a52b3eb commit 083533a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/mapboxgl/overlay/GraticuleLayer.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
* thanks dereklieu, cloudybay
1010
*/
1111

12-
import { getWrapNum, conversionDegree } from '@supermap/iclient-common';
12+
import { getWrapNum, conversionDegree, CommonUtil } from '@supermap/iclient-common';
1313
import mapboxgl from 'mapbox-gl';
1414
/**
1515
* @class mapboxgl.supermap.GraticuleLayer
1616
* @category Visualization GraticuleLayer
1717
* @classdesc 经纬网。
1818
* @version 10.1.1
1919
* @param {Object} options -经纬网参数。
20+
* @param {string} [options.layerID] - 图层 ID。默认使用 CommonUtil.createUniqueID("graticuleLayer_") 创建图层 ID。
2021
* @param {boolean} [options.visible=true] - 是否显示经纬网。
2122
* @param {boolean} [options.showLabel=true] - 是否显示标签。
2223
* @param {number} [options.opacity=1] - 画布透明度。
@@ -82,9 +83,10 @@ const defaultOptions = {
8283
latLabelStyle: defaultTextStyle
8384
};
8485
export class GraticuleLayer {
85-
constructor(options, sourceId = 'sm-graticule-layer') {
86-
this.canvasId = 'sm-graticule-canvasid';
87-
this.sourceId = sourceId;
86+
constructor(options) {
87+
this.id = options.layerID ? options.layerID : CommonUtil.createUniqueID('graticuleLayer_');
88+
this.sourceId = this.id;
89+
this.canvasId = this.id;
8890
this.options = options;
8991
this.resetEvent = this._reset.bind(this);
9092
this.styleDataEevent = this._setLayerTop.bind(this);
@@ -118,7 +120,7 @@ export class GraticuleLayer {
118120
* @param {boolean} visible - 是否可见。
119121
*/
120122
setVisibility(visible) {
121-
const zoom = this.map.getZoom();
123+
const zoom = this.map && this.map.getZoom();
122124
this.options.visible = typeof visible === 'boolean' ? visible : this.options.visible;
123125
this.visible =
124126
typeof visible === 'boolean'
@@ -178,6 +180,9 @@ export class GraticuleLayer {
178180
* @param {mapboxgl.supermap.GraticuleLayer.StrokeStyle} strokeStyle - 经纬线样式。
179181
*/
180182
setStrokeStyle(strokeStyle) {
183+
if (!this.map || !this.map.getLayer(this.sourceId)) {
184+
return;
185+
}
181186
this.options.strokeStyle = strokeStyle;
182187
const { layout, paint } = this._transformStrokeStyle(strokeStyle);
183188
for (let key in layout) {
@@ -251,6 +256,7 @@ export class GraticuleLayer {
251256
this.oldExtent = this.options.extent;
252257
this._calcInterval();
253258
this.isRotate = false;
259+
this.visible = true;
254260
this.features = this._getGraticuleFeatures();
255261
}
256262

@@ -831,6 +837,7 @@ export class GraticuleLayer {
831837
return { paint: { 'line-color': strokeStyle || 'rgba(0,0,0,0.2)' } };
832838
}
833839
const layout = {
840+
visibility: this.visible ? 'visible' : 'none',
834841
'line-join': strokeStyle.lineJoin || 'round',
835842
'line-cap': strokeStyle.lineCap || 'round'
836843
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy