1- import { IMap } from "../types" ;
1+ import { IMap , TIdentityGeoJSONFeature } from "../types" ;
22import { Tools } from "../utils/tools" ;
33
44export type TFeatureEvent = "all" | "add" | "update" | "delete" | "clear" | "destory" ;
5- export type TIdentityGeoJSONFeature = GeoJSON . Feature < GeoJSON . Geometry , { id : string } > ;
65
76export interface GeoJSONLayerManagerOptions < TFeature extends TIdentityGeoJSONFeature = TIdentityGeoJSONFeature > {
87 map : IMap ;
@@ -13,6 +12,7 @@ export abstract class GeoJSONLayerManagerBase<TFeature extends TIdentityGeoJSONF
1312 private events = new Map < string , Array < ( e : { features ?: TFeature [ ] } ) => void > > ( ) ;
1413 protected readonly layers = new Array < string > ( ) ;
1514 protected data = new Map < string , TFeature > ( ) ;
15+ protected hiddenData = new Map < string , TFeature > ( ) ;
1616
1717 readonly map : IMap ;
1818 readonly source : string = Tools . uuid ( ) ;
@@ -42,6 +42,15 @@ export abstract class GeoJSONLayerManagerBase<TFeature extends TIdentityGeoJSONF
4242
4343 protected abstract onChange ( mode : TFeatureEvent , features ?: TFeature [ ] ) : void ;
4444
45+ /**
46+ * 获取数据
47+ * @param id
48+ * @returns
49+ */
50+ query ( id : string ) : TFeature | undefined {
51+ return this . data . get ( id ) ;
52+ }
53+
4554 /**
4655 * 添加图层
4756 * @param layer
@@ -55,15 +64,6 @@ export abstract class GeoJSONLayerManagerBase<TFeature extends TIdentityGeoJSONF
5564 }
5665 }
5766
58- /**
59- * 获取数据
60- * @param id
61- * @returns
62- */
63- query ( id : string ) : TFeature | undefined {
64- return this . data . get ( id ) ;
65- }
66-
6767 /**
6868 * 创建数据
6969 * @param features
@@ -133,6 +133,65 @@ export abstract class GeoJSONLayerManagerBase<TFeature extends TIdentityGeoJSONF
133133 this . map . removeSource ( this . source ) ;
134134 }
135135
136+ /**
137+ * 设置Feature隐藏
138+ * @param id
139+ * @returns
140+ */
141+ setFeatureHidden ( ...id : string [ ] ) {
142+ const fs = new Array < TFeature > ( ) ;
143+ id . forEach ( i => {
144+ const f = this . data . get ( i ) ;
145+ if ( ! f ) return ;
146+
147+ // 如果已经隐藏,则不处理
148+ if ( this . hiddenData . has ( i ) ) return ;
149+
150+ // 处理隐藏
151+ this . data . delete ( i )
152+ this . hiddenData . set ( i , f ) ;
153+ fs . push ( f ) ;
154+ } ) ;
155+
156+ this . onChange ( "delete" , fs ) ;
157+ }
158+
159+ /**
160+ *
161+ * @param id 当id为空时清除所有隐藏
162+ */
163+ clearFeatureHidden ( ...id : string [ ] ) {
164+ const fs = new Array < TFeature > ( ) ;
165+ if ( id . length === 0 )
166+ id . forEach ( i => {
167+ const f = this . hiddenData . get ( i ) ;
168+ if ( ! f ) return ;
169+
170+ this . hiddenData . delete ( i ) ;
171+ this . data . set ( i , f ) ;
172+ fs . push ( f ) ;
173+ } ) ;
174+ else {
175+ this . hiddenData . forEach ( ( v , k ) => {
176+ this . data . set ( k , v ) ;
177+ fs . push ( v ) ;
178+ } ) ;
179+ this . hiddenData . clear ( ) ;
180+ }
181+
182+ this . onChange ( 'add' , fs ) ;
183+ }
184+
185+ /**
186+ * 设置是否显示
187+ * @param visible
188+ */
189+ setVisible ( visible : boolean ) {
190+ this . layers . forEach ( l => {
191+ this . map . setLayoutProperty ( l , 'visibility' , visible ? 'visible' : 'none' ) ;
192+ } ) ;
193+ }
194+
136195 /**
137196 * 挂在事件
138197 * @param mode
0 commit comments