@antv/l7-layers 2.8.36 → 2.8.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,7 @@ export default class DataMappingPlugin implements ILayerPlugin {
11
11
  private getArrowPoints;
12
12
  private mapping;
13
13
  private adjustData2Amap2Coordinates;
14
+ private getLayerCenter;
14
15
  private adjustData2SimpleCoordinates;
15
16
  private unProjectCoordinates;
16
17
  private applyAttributeMapping;
@@ -70,10 +70,10 @@ var DataMappingPlugin = (_dec = injectable(), _dec2 = inject(TYPES.IGlobalConfig
70
70
 
71
71
  if (attributesToRemapping.length) {
72
72
  if (filter !== null && filter !== void 0 && filter.needRemapping) {
73
- layer.setEncodedData(_this.mapping(attributes, filterData, undefined, bottomColor, layer));
73
+ layer.setEncodedData(_this.mapping(layer, attributes, filterData, undefined, bottomColor));
74
74
  filter.needRemapping = false;
75
75
  } else {
76
- layer.setEncodedData(_this.mapping(attributesToRemapping, filterData, layer.getEncodedData(), bottomColor, layer));
76
+ layer.setEncodedData(_this.mapping(layer, attributesToRemapping, filterData, layer.getEncodedData(), bottomColor));
77
77
  }
78
78
 
79
79
  layer.emit('remapping', null);
@@ -98,7 +98,7 @@ var DataMappingPlugin = (_dec = injectable(), _dec2 = inject(TYPES.IGlobalConfig
98
98
  });
99
99
  }
100
100
 
101
- layer.setEncodedData(this.mapping(attributes, filterData, undefined, bottomColor, layer));
101
+ layer.setEncodedData(this.mapping(layer, attributes, filterData, undefined, bottomColor));
102
102
  layer.emit('dataUpdate', null);
103
103
  }
104
104
  }, {
@@ -111,10 +111,10 @@ var DataMappingPlugin = (_dec = injectable(), _dec2 = inject(TYPES.IGlobalConfig
111
111
  }
112
112
  }, {
113
113
  key: "mapping",
114
- value: function mapping(attributes, data, predata, minimumColor, layer) {
114
+ value: function mapping(layer, attributes, data, predata, minimumColor) {
115
115
  var _this3 = this;
116
116
 
117
- var _ref3 = layer === null || layer === void 0 ? void 0 : layer.getLayerConfig(),
117
+ var _ref3 = layer.getLayerConfig(),
118
118
  _ref3$arrow = _ref3.arrow,
119
119
  arrow = _ref3$arrow === void 0 ? {
120
120
  enable: false
@@ -158,16 +158,18 @@ var DataMappingPlugin = (_dec = injectable(), _dec2 = inject(TYPES.IGlobalConfig
158
158
 
159
159
  return encodeRecord;
160
160
  });
161
- this.adjustData2Amap2Coordinates(mappedData);
161
+ this.adjustData2Amap2Coordinates(mappedData, layer);
162
162
  this.adjustData2SimpleCoordinates(mappedData);
163
163
  return mappedData;
164
164
  }
165
165
  }, {
166
166
  key: "adjustData2Amap2Coordinates",
167
- value: function adjustData2Amap2Coordinates(mappedData) {
167
+ value: function adjustData2Amap2Coordinates(mappedData, layer) {
168
168
  var _this4 = this;
169
169
 
170
170
  if (mappedData.length > 0 && this.mapService.version === Version['GAODE2.x']) {
171
+ var layerCenter = this.getLayerCenter(layer);
172
+
171
173
  if (typeof mappedData[0].coordinates[0] === 'number') {
172
174
  mappedData.filter(function (d) {
173
175
  return !d.originCoordinates;
@@ -187,6 +189,12 @@ var DataMappingPlugin = (_dec = injectable(), _dec2 = inject(TYPES.IGlobalConfig
187
189
  }
188
190
  }
189
191
  }
192
+ }, {
193
+ key: "getLayerCenter",
194
+ value: function getLayerCenter(layer) {
195
+ var source = layer.getSource();
196
+ return source.center;
197
+ }
190
198
  }, {
191
199
  key: "adjustData2SimpleCoordinates",
192
200
  value: function adjustData2SimpleCoordinates(mappedData) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/DataMappingPlugin.ts"],"names":["TYPES","Version","isColor","normalize","rgb2arr","inject","injectable","DataMappingPlugin","IGlobalConfigService","IMapService","IFontService","layer","styleAttributeService","hooks","init","tap","generateMaping","beforeRenderData","dataState","dataMappingNeedUpdate","beforeRender","layerModelNeedUpdate","bottomColor","getBottomColor","attributes","getLayerStyleAttributes","filter","getLayerStyleAttribute","dataArray","getSource","data","attributesToRemapping","attribute","needRemapping","filterData","scale","record","applyAttributeMapping","length","setEncodedData","mapping","undefined","getEncodedData","emit","p1","p2","dir","normalizeDir","arrowPoint","predata","minimumColor","getLayerConfig","arrow","enable","mappedData","map","i","preRecord","encodeRecord","id","_id","coordinates","forEach","values","name","c","Array","isArray","shape","fontService","getIconFontKey","coords","getArrowPoints","splice","adjustData2Amap2Coordinates","adjustData2SimpleCoordinates","mapService","version","d","originCoordinates","lngLatToCoord","lngLatToCoords","SIMPLE","simpleCoordinate","unProjectCoordinates","simpleMapCoord","unproject","coord","c1","co","push","scalers","params","field","hasOwnProperty","type","mappingResult"],"mappings":";;;;;;;;;;;;;;AAAA,SAYEA,KAZF,QAaO,eAbP;AAcA,SAASC,OAAT,QAAwB,eAAxB;AACA,SAASC,OAAT,EAAkBC,SAAlB,EAA6BC,OAA7B,QAA2D,gBAA3D;AACA,SAASC,MAAT,EAAiBC,UAAjB,QAAmC,WAAnC;AAEA,OAAO,kBAAP;IAIqBC,iB,WADpBD,UAAU,E,UAERD,MAAM,CAACL,KAAK,CAACQ,oBAAP,C,UAGNH,MAAM,CAACL,KAAK,CAACS,WAAP,C,UAGNJ,MAAM,CAACL,KAAK,CAACU,YAAP,C;;;;;;;;;;;;;WAGP,eACEC,KADF,QAKE;AAAA;;AAAA,UAFEC,qBAEF,QAFEA,qBAEF;AACAD,MAAAA,KAAK,CAACE,KAAN,CAAYC,IAAZ,CAAiBC,GAAjB,CAAqB,mBAArB,EAA0C,YAAM;AAE9C,QAAA,KAAI,CAACC,cAAL,CAAoBL,KAApB,EAA2B;AAAEC,UAAAA,qBAAqB,EAArBA;AAAF,SAA3B;AACD,OAHD;AAKAD,MAAAA,KAAK,CAACE,KAAN,CAAYI,gBAAZ,CAA6BF,GAA7B,CAAiC,mBAAjC,EAAsD,YAAM;AAC1DJ,QAAAA,KAAK,CAACO,SAAN,CAAgBC,qBAAhB,GAAwC,KAAxC;;AACA,QAAA,KAAI,CAACH,cAAL,CAAoBL,KAApB,EAA2B;AAAEC,UAAAA,qBAAqB,EAArBA;A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,KAAX,sEAAkBwD,OAAlB,KAA6B,EAA7C;AACA,UAAMC,MAAiB,GAAG,EAA1B;AAEAD,MAAAA,OAAO,CAAC7B,OAAR,CAAgB,iBAAe;AAAA;;AAAA,YAAZ+B,KAAY,SAAZA,KAAY;;AAC7B,YACEzD,MAAM,CAAC0D,cAAP,CAAsBD,KAAtB,KACA,sBAAA7D,SAAS,CAACG,KAAV,wEAAiB4D,IAAjB,MAA0B,UAF5B,EAGE;AAEAH,UAAAA,MAAM,CAACF,IAAP,CAAYtD,MAAM,CAACyD,KAAD,CAAlB;AACD;AACF,OARD;AAYA,UAAMG,aAAa,GAAGhE,SAAS,CAACQ,OAAV,GAAoBR,SAAS,CAACQ,OAAV,CAAkBoD,MAAlB,CAApB,GAAgD,EAAtE;;AACA,UAAI5D,SAAS,CAACgC,IAAV,KAAmB,OAAnB,IAA8B,CAAC9D,OAAO,CAAC8F,aAAa,CAAC,CAAD,CAAd,CAA1C,EAA8D;AAC5D,eAAO,CAAC9C,YAAD,CAAP;AACD;;AACD,aAAO8C,aAAP;AAED;;;;;;;;;;;;;;;;;;;;SAhSkBzF,iB","sourcesContent":["import {\n IEncodeFeature,\n IFontService,\n IGlobalConfigService,\n ILayer,\n ILayerPlugin,\n ILngLat,\n IMapService,\n IParseDataItem,\n IStyleAttribute,\n IStyleAttributeService,\n Position,\n TYPES,\n} from '@antv/l7-core';\nimport { Version } from '@antv/l7-maps';\nimport { isColor, normalize, rgb2arr, unProjectFlat } from '@antv/l7-utils';\nimport { inject, injectable } from 'inversify';\nimport { cloneDeep } from 'lodash';\nimport 'reflect-metadata';\nimport { ILineLayerStyleOptions } from '../core/interface';\n\n@injectable()\nexport default class DataMappingPlugin implements ILayerPlugin {\n @inject(TYPES.IGlobalConfigService)\n private readonly configService: IGlobalConfigService;\n\n @inject(TYPES.IMapService)\n private readonly mapService: IMapService;\n\n @inject(TYPES.IFontService)\n private readonly fontService: IFontService;\n\n public apply(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n layer.hooks.init.tap('DataMappingPlugin', () => {\n // 初始化重新生成 map\n this.generateMaping(layer, { styleAttributeService });\n });\n\n layer.hooks.beforeRenderData.tap('DataMappingPlugin', () => {\n layer.dataState.dataMappingNeedUpdate = false;\n this.generateMaping(layer, { styleAttributeService });\n return true;\n });\n\n // remapping before render\n layer.hooks.beforeRender.tap('DataMappingPlugin', () => {\n if (layer.layerModelNeedUpdate) {\n return;\n }\n const bottomColor = layer.getBottomColor();\n const attributes = styleAttributeService.getLayerStyleAttributes() || [];\n const filter = styleAttributeService.getLayerStyleAttribute('filter');\n const { dataArray } = layer.getSource().data;\n\n const attributesToRemapping = attributes.filter(\n (attribute) => attribute.needRemapping, // 如果filter变化\n );\n let filterData = dataArray;\n\n // 数据过滤完 再执行数据映射\n if (filter?.needRemapping && filter?.scale) {\n filterData = dataArray.filter((record: IParseDataItem) => {\n return this.applyAttributeMapping(filter, record, bottomColor)[0];\n });\n }\n\n if (attributesToRemapping.length) {\n // 过滤数据\n if (filter?.needRemapping) {\n layer.setEncodedData(\n this.mapping(attributes, filterData, undefined, bottomColor, layer),\n );\n filter.needRemapping = false;\n } else {\n layer.setEncodedData(\n this.mapping(\n attributesToRemapping,\n filterData,\n layer.getEncodedData(),\n bottomColor,\n layer,\n ),\n );\n }\n // 处理文本更新\n layer.emit('remapping', null);\n }\n });\n }\n private generateMaping(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n const bottomColor = layer.getBottomColor();\n const attributes = styleAttributeService.getLayerStyleAttributes() || [];\n const filter = styleAttributeService.getLayerStyleAttribute('filter');\n const { dataArray } = layer.getSource().data;\n let filterData = dataArray;\n // 数据过滤完 再执行数据映射\n if (filter?.scale) {\n filterData = dataArray.filter((record: IParseDataItem) => {\n return this.applyAttributeMapping(filter, record, bottomColor)[0];\n });\n }\n layer.setEncodedData(\n this.mapping(attributes, filterData, undefined, bottomColor, layer),\n );\n // 对外暴露事件\n layer.emit('dataUpdate', null);\n }\n\n private getArrowPoints(p1: Position, p2: Position) {\n const dir = [p2[0] - p1[0], p2[1] - p1[1]];\n const normalizeDir = normalize(dir);\n const arrowPoint = [\n p1[0] + normalizeDir[0] * 0.0001,\n p1[1] + normalizeDir[1] * 0.0001,\n ];\n return arrowPoint;\n }\n\n private mapping(\n attributes: IStyleAttribute[],\n data: IParseDataItem[],\n predata?: IEncodeFeature[],\n minimumColor?: string,\n layer?: ILayer,\n ): IEncodeFeature[] {\n const {\n arrow = {\n enable: false,\n },\n } = layer?.getLayerConfig() as ILineLayerStyleOptions;\n const mappedData = data.map((record: IParseDataItem, i) => {\n const preRecord = predata ? predata[i] : {};\n const encodeRecord: IEncodeFeature = {\n id: record._id,\n coordinates: record.coordinates,\n ...preRecord,\n };\n attributes\n .filter((attribute) => attribute.scale !== undefined)\n .forEach((attribute: IStyleAttribute) => {\n // console.log('record', record)\n let values = this.applyAttributeMapping(\n attribute,\n record,\n minimumColor,\n );\n // console.log('values', values)\n attribute.needRemapping = false;\n\n // TODO: 支持每个属性配置 postprocess\n if (attribute.name === 'color') {\n // console.log('attribute', attribute)\n values = values.map((c: unknown) => {\n return rgb2arr(c as string);\n });\n }\n // @ts-ignore\n encodeRecord[attribute.name] =\n Array.isArray(values) && values.length === 1 ? values[0] : values;\n\n // 增加对 layer/text/iconfont unicode 映射的解析\n if (attribute.name === 'shape') {\n encodeRecord.shape = this.fontService.getIconFontKey(\n encodeRecord[attribute.name] as string,\n );\n }\n });\n\n if (encodeRecord.shape === 'line' && arrow.enable) {\n // 只有在线图层且支持配置箭头的时候进行插入顶点的处理\n const coords = encodeRecord.coordinates as Position[];\n const arrowPoint = this.getArrowPoints(coords[0], coords[1]);\n encodeRecord.coordinates.splice(1, 0, arrowPoint, arrowPoint);\n }\n return encodeRecord;\n }) as IEncodeFeature[];\n // console.log('mappedData', mappedData)\n\n // 调整数据兼容 Amap2.0\n this.adjustData2Amap2Coordinates(mappedData);\n\n // 调整数据兼容 SimpleCoordinates\n this.adjustData2SimpleCoordinates(mappedData);\n\n return mappedData;\n }\n\n private adjustData2Amap2Coordinates(mappedData: IEncodeFeature[]) {\n // 根据地图的类型判断是否需要对点位数据进行处理, 若是高德2.0则需要对坐标进行相对偏移\n if (\n mappedData.length > 0 &&\n this.mapService.version === Version['GAODE2.x']\n ) {\n if (typeof mappedData[0].coordinates[0] === 'number') {\n // 单个的点数据\n // @ts-ignore\n mappedData\n // TODO: 避免经纬度被重复计算导致坐标位置偏移\n .filter((d) => !d.originCoordinates)\n .map((d) => {\n d.version = Version['GAODE2.x'];\n // @ts-ignore\n d.originCoordinates = cloneDeep(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)\n // @ts-ignore\n d.coordinates = this.mapService.lngLatToCoord(d.coordinates);\n });\n } else {\n // 连续的线、面数据\n // @ts-ignore\n mappedData\n // TODO: 避免经纬度被重复计算导致坐标位置偏移\n .filter((d) => !d.originCoordinates)\n .map((d) => {\n d.version = Version['GAODE2.x'];\n // @ts-ignore\n d.originCoordinates = cloneDeep(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)\n // @ts-ignore\n d.coordinates = this.mapService.lngLatToCoords(d.coordinates);\n });\n }\n }\n }\n\n private adjustData2SimpleCoordinates(mappedData: IEncodeFeature[]) {\n if (mappedData.length > 0 && this.mapService.version === Version.SIMPLE) {\n mappedData.map((d) => {\n if (!d.simpleCoordinate) {\n d.coordinates = this.unProjectCoordinates(d.coordinates);\n d.simpleCoordinate = true;\n }\n });\n }\n }\n\n private unProjectCoordinates(coordinates: any) {\n if (typeof coordinates[0] === 'number') {\n return this.mapService.simpleMapCoord.unproject(\n coordinates as [number, number],\n );\n }\n\n if (coordinates[0] && coordinates[0][0] instanceof Array) {\n // @ts-ignore\n const coords = [];\n coordinates.map((coord: any) => {\n // @ts-ignore\n const c1 = [];\n coord.map((co: any) => {\n c1.push(\n this.mapService.simpleMapCoord.unproject(co as [number, number]),\n );\n });\n // @ts-ignore\n coords.push(c1);\n });\n // @ts-ignore\n return coords;\n } else {\n // @ts-ignore\n const coords = [];\n // @ts-ignore\n coordinates.map((coord) => {\n coords.push(\n this.mapService.simpleMapCoord.unproject(coord as [number, number]),\n );\n });\n // @ts-ignore\n return coords;\n }\n }\n\n private applyAttributeMapping(\n attribute: IStyleAttribute,\n record: { [key: string]: unknown },\n minimumColor?: string,\n ) {\n if (!attribute.scale) {\n return [];\n }\n const scalers = attribute?.scale?.scalers || [];\n const params: unknown[] = [];\n\n scalers.forEach(({ field }) => {\n if (\n record.hasOwnProperty(field) ||\n attribute.scale?.type === 'variable'\n ) {\n // TODO:多字段,常量\n params.push(record[field]);\n }\n });\n // console.log('params', params)\n // console.log('attribute', attribute)\n\n const mappingResult = attribute.mapping ? attribute.mapping(params) : [];\n if (attribute.name === 'color' && !isColor(mappingResult[0])) {\n return [minimumColor];\n }\n return mappingResult;\n // return attribute.mapping ? attribute.mapping(params) : [];\n }\n}\n"],"file":"DataMappingPlugin.js"}
1
+ {"version":3,"sources":["../../src/plugins/DataMappingPlugin.ts"],"names":["TYPES","Version","isColor","normalize","rgb2arr","inject","injectable","DataMappingPlugin","IGlobalConfigService","IMapService","IFontService","layer","styleAttributeService","hooks","init","tap","generateMaping","beforeRenderData","dataState","dataMappingNeedUpdate","beforeRender","layerModelNeedUpdate","bottomColor","getBottomColor","attributes","getLayerStyleAttributes","filter","getLayerStyleAttribute","dataArray","getSource","data","attributesToRemapping","attribute","needRemapping","filterData","scale","record","applyAttributeMapping","length","setEncodedData","mapping","undefined","getEncodedData","emit","p1","p2","dir","normalizeDir","arrowPoint","predata","minimumColor","getLayerConfig","arrow","enable","mappedData","map","i","preRecord","encodeRecord","id","_id","coordinates","forEach","values","name","c","Array","isArray","shape","fontService","getIconFontKey","coords","getArrowPoints","splice","adjustData2Amap2Coordinates","adjustData2SimpleCoordinates","mapService","version","layerCenter","getLayerCenter","d","originCoordinates","lngLatToCoord","lngLatToCoords","source","center","SIMPLE","simpleCoordinate","unProjectCoordinates","simpleMapCoord","unproject","coord","c1","co","push","scalers","params","field","hasOwnProperty","type","mappingResult"],"mappings":";;;;;;;;;;;;;;AAAA,SAYEA,KAZF,QAaO,eAbP;AAcA,SAASC,OAAT,QAAwB,eAAxB;AACA,SAASC,OAAT,EAAkBC,SAAlB,EAA6BC,OAA7B,QAA2D,gBAA3D;AACA,SAASC,MAAT,EAAiBC,UAAjB,QAAmC,WAAnC;AAEA,OAAO,kBAAP;IAIqBC,iB,WADpBD,UAAU,E,UAERD,MAAM,CAACL,KAAK,CAACQ,oBAAP,C,UAGNH,MAAM,CAACL,KAAK,CAACS,WAAP,C,UAGNJ,MAAM,CAACL,KAAK,CAACU,YAAP,C;;;;;;;;;;;;;WAGP,eACEC,KADF,QAKE;AAAA;;AAAA,UAFEC,qBAEF,QAFEA,qBAEF;AACAD,MAAAA,KAAK,CAACE,KAAN,CAAYC,IAAZ,CAAiBC,GAAjB,CAAqB,mBAArB,EAA0C,YAAM;AAE9C,QAAA,KAAI,CAACC,cAAL,CAAoBL,KAApB,EAA2B;AAAEC,UAAAA,qBAAqB,EAArBA;AAAF,SAA3B;AACD,OAHD;AAKAD,MAAAA,KAAK,CAACE,KAAN,CAAYI,gBAAZ,CAA6BF,GAA7B,CAAiC,mBAAjC,EAAsD,YAAM;AAC1DJ,QAAAA,KAAK,CAACO,SAAN,CAAgBC,qBAAhB,GAAwC,KAAxC;;AACA,QAAA,KAAI,CAACH,cAAL,CAAoBL,KAApB,EAA2B;AAAEC,UAAAA,qBAAqB,EAArBA;AAAF,SAA3B;;AACA,eAAO,IAAP;AACD,OAJD;AAOAD,MAAAA,KAAK,CAACE,KAAN,CAAYO,YAAZ,CAAyBL,GAAzB,CAA6B,mBAA7B,EAAkD,YAAM;AACtD,YAAIJ,KAAK,CAACU,oBAAV,EAAgC;AAC9B;AACD;;AACD,YAAMC,WAAW,GA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AAkB4D,OAAlB,KAA6B,EAA7C;AACA,UAAMC,MAAiB,GAAG,EAA1B;AAEAD,MAAAA,OAAO,CAACjC,OAAR,CAAgB,iBAAe;AAAA;;AAAA,YAAZmC,KAAY,SAAZA,KAAY;;AAC7B,YACE7D,MAAM,CAAC8D,cAAP,CAAsBD,KAAtB,KACA,sBAAAjE,SAAS,CAACG,KAAV,wEAAiBgE,IAAjB,MAA0B,UAF5B,EAGE;AAEAH,UAAAA,MAAM,CAACF,IAAP,CAAY1D,MAAM,CAAC6D,KAAD,CAAlB;AACD;AACF,OARD;AAYA,UAAMG,aAAa,GAAGpE,SAAS,CAACQ,OAAV,GAAoBR,SAAS,CAACQ,OAAV,CAAkBwD,MAAlB,CAApB,GAAgD,EAAtE;;AACA,UAAIhE,SAAS,CAACgC,IAAV,KAAmB,OAAnB,IAA8B,CAAC9D,OAAO,CAACkG,aAAa,CAAC,CAAD,CAAd,CAA1C,EAA8D;AAC5D,eAAO,CAAClD,YAAD,CAAP;AACD;;AACD,aAAOkD,aAAP;AAED;;;;;;;;;;;;;;;;;;;;SAjTkB7F,iB","sourcesContent":["import {\n IEncodeFeature,\n IFontService,\n IGlobalConfigService,\n ILayer,\n ILayerPlugin,\n ILngLat,\n IMapService,\n IParseDataItem,\n IStyleAttribute,\n IStyleAttributeService,\n Position,\n TYPES,\n} from '@antv/l7-core';\nimport { Version } from '@antv/l7-maps';\nimport { isColor, normalize, rgb2arr, unProjectFlat } from '@antv/l7-utils';\nimport { inject, injectable } from 'inversify';\nimport { cloneDeep } from 'lodash';\nimport 'reflect-metadata';\nimport { ILineLayerStyleOptions } from '../core/interface';\n\n@injectable()\nexport default class DataMappingPlugin implements ILayerPlugin {\n @inject(TYPES.IGlobalConfigService)\n private readonly configService: IGlobalConfigService;\n\n @inject(TYPES.IMapService)\n private readonly mapService: IMapService;\n\n @inject(TYPES.IFontService)\n private readonly fontService: IFontService;\n\n public apply(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n layer.hooks.init.tap('DataMappingPlugin', () => {\n // 初始化重新生成 map\n this.generateMaping(layer, { styleAttributeService });\n });\n\n layer.hooks.beforeRenderData.tap('DataMappingPlugin', () => {\n layer.dataState.dataMappingNeedUpdate = false;\n this.generateMaping(layer, { styleAttributeService });\n return true;\n });\n\n // remapping before render\n layer.hooks.beforeRender.tap('DataMappingPlugin', () => {\n if (layer.layerModelNeedUpdate) {\n return;\n }\n const bottomColor = layer.getBottomColor();\n const attributes = styleAttributeService.getLayerStyleAttributes() || [];\n const filter = styleAttributeService.getLayerStyleAttribute('filter');\n const { dataArray } = layer.getSource().data;\n\n const attributesToRemapping = attributes.filter(\n (attribute) => attribute.needRemapping, // 如果filter变化\n );\n let filterData = dataArray;\n\n // 数据过滤完 再执行数据映射\n if (filter?.needRemapping && filter?.scale) {\n filterData = dataArray.filter((record: IParseDataItem) => {\n return this.applyAttributeMapping(filter, record, bottomColor)[0];\n });\n }\n\n if (attributesToRemapping.length) {\n // 过滤数据\n if (filter?.needRemapping) {\n layer.setEncodedData(\n this.mapping(layer, attributes, filterData, undefined, bottomColor),\n );\n filter.needRemapping = false;\n } else {\n layer.setEncodedData(\n this.mapping(\n layer,\n attributesToRemapping,\n filterData,\n layer.getEncodedData(),\n bottomColor,\n ),\n );\n }\n // 处理文本更新\n layer.emit('remapping', null);\n }\n });\n }\n private generateMaping(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n const bottomColor = layer.getBottomColor();\n const attributes = styleAttributeService.getLayerStyleAttributes() || [];\n const filter = styleAttributeService.getLayerStyleAttribute('filter');\n const { dataArray } = layer.getSource().data;\n let filterData = dataArray;\n // 数据过滤完 再执行数据映射\n if (filter?.scale) {\n filterData = dataArray.filter((record: IParseDataItem) => {\n return this.applyAttributeMapping(filter, record, bottomColor)[0];\n });\n }\n layer.setEncodedData(\n this.mapping(layer, attributes, filterData, undefined, bottomColor),\n );\n // 对外暴露事件\n layer.emit('dataUpdate', null);\n }\n\n private getArrowPoints(p1: Position, p2: Position) {\n const dir = [p2[0] - p1[0], p2[1] - p1[1]];\n const normalizeDir = normalize(dir);\n const arrowPoint = [\n p1[0] + normalizeDir[0] * 0.0001,\n p1[1] + normalizeDir[1] * 0.0001,\n ];\n return arrowPoint;\n }\n\n private mapping(\n layer: ILayer,\n attributes: IStyleAttribute[],\n data: IParseDataItem[],\n predata?: IEncodeFeature[],\n minimumColor?: string,\n ): IEncodeFeature[] {\n const {\n arrow = {\n enable: false,\n },\n } = layer.getLayerConfig() as ILineLayerStyleOptions;\n const mappedData = data.map((record: IParseDataItem, i) => {\n const preRecord = predata ? predata[i] : {};\n const encodeRecord: IEncodeFeature = {\n id: record._id,\n coordinates: record.coordinates,\n ...preRecord,\n };\n attributes\n .filter((attribute) => attribute.scale !== undefined)\n .forEach((attribute: IStyleAttribute) => {\n // console.log('record', record)\n let values = this.applyAttributeMapping(\n attribute,\n record,\n minimumColor,\n );\n // console.log('values', values)\n attribute.needRemapping = false;\n\n // TODO: 支持每个属性配置 postprocess\n if (attribute.name === 'color') {\n // console.log('attribute', attribute)\n values = values.map((c: unknown) => {\n return rgb2arr(c as string);\n });\n }\n // @ts-ignore\n encodeRecord[attribute.name] =\n Array.isArray(values) && values.length === 1 ? values[0] : values;\n\n // 增加对 layer/text/iconfont unicode 映射的解析\n if (attribute.name === 'shape') {\n encodeRecord.shape = this.fontService.getIconFontKey(\n encodeRecord[attribute.name] as string,\n );\n }\n });\n\n if (encodeRecord.shape === 'line' && arrow.enable) {\n // 只有在线图层且支持配置箭头的时候进行插入顶点的处理\n const coords = encodeRecord.coordinates as Position[];\n const arrowPoint = this.getArrowPoints(coords[0], coords[1]);\n encodeRecord.coordinates.splice(1, 0, arrowPoint, arrowPoint);\n }\n return encodeRecord;\n }) as IEncodeFeature[];\n // console.log('mappedData', mappedData)\n\n // 调整数据兼容 Amap2.0\n this.adjustData2Amap2Coordinates(mappedData, layer);\n\n // 调整数据兼容 SimpleCoordinates\n this.adjustData2SimpleCoordinates(mappedData);\n\n return mappedData;\n }\n\n private adjustData2Amap2Coordinates(\n mappedData: IEncodeFeature[],\n layer: ILayer,\n ) {\n // 根据地图的类型判断是否需要对点位数据进行处理, 若是高德2.0则需要对坐标进行相对偏移\n if (\n mappedData.length > 0 &&\n this.mapService.version === Version['GAODE2.x']\n ) {\n const layerCenter = this.getLayerCenter(layer);\n if (typeof mappedData[0].coordinates[0] === 'number') {\n // 单个的点数据\n // @ts-ignore\n mappedData\n // TODO: 避免经纬度被重复计算导致坐标位置偏移\n .filter((d) => !d.originCoordinates)\n .map((d) => {\n d.version = Version['GAODE2.x'];\n // @ts-ignore\n d.originCoordinates = cloneDeep(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)\n // @ts-ignore\n d.coordinates = this.mapService.lngLatToCoord(d.coordinates);\n // d.coordinates = this.mapService.lngLatToCoordByLayer(\n // d.coordinates,\n // layerCenter,\n // );\n });\n } else {\n // 连续的线、面数据\n // @ts-ignore\n mappedData\n // TODO: 避免经纬度被重复计算导致坐标位置偏移\n .filter((d) => !d.originCoordinates)\n .map((d) => {\n d.version = Version['GAODE2.x'];\n // @ts-ignore\n d.originCoordinates = cloneDeep(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)\n // @ts-ignore\n d.coordinates = this.mapService.lngLatToCoords(d.coordinates);\n // d.coordinates = this.mapService.lngLatToCoordsByLayer(\n // d.coordinates,\n // layerCenter,\n // );\n });\n }\n }\n }\n\n private getLayerCenter(layer: ILayer) {\n const source = layer.getSource();\n return source.center;\n }\n\n private adjustData2SimpleCoordinates(mappedData: IEncodeFeature[]) {\n if (mappedData.length > 0 && this.mapService.version === Version.SIMPLE) {\n mappedData.map((d) => {\n if (!d.simpleCoordinate) {\n d.coordinates = this.unProjectCoordinates(d.coordinates);\n d.simpleCoordinate = true;\n }\n });\n }\n }\n\n private unProjectCoordinates(coordinates: any) {\n if (typeof coordinates[0] === 'number') {\n return this.mapService.simpleMapCoord.unproject(\n coordinates as [number, number],\n );\n }\n\n if (coordinates[0] && coordinates[0][0] instanceof Array) {\n // @ts-ignore\n const coords = [];\n coordinates.map((coord: any) => {\n // @ts-ignore\n const c1 = [];\n coord.map((co: any) => {\n c1.push(\n this.mapService.simpleMapCoord.unproject(co as [number, number]),\n );\n });\n // @ts-ignore\n coords.push(c1);\n });\n // @ts-ignore\n return coords;\n } else {\n // @ts-ignore\n const coords = [];\n // @ts-ignore\n coordinates.map((coord) => {\n coords.push(\n this.mapService.simpleMapCoord.unproject(coord as [number, number]),\n );\n });\n // @ts-ignore\n return coords;\n }\n }\n\n private applyAttributeMapping(\n attribute: IStyleAttribute,\n record: { [key: string]: unknown },\n minimumColor?: string,\n ) {\n if (!attribute.scale) {\n return [];\n }\n const scalers = attribute?.scale?.scalers || [];\n const params: unknown[] = [];\n\n scalers.forEach(({ field }) => {\n if (\n record.hasOwnProperty(field) ||\n attribute.scale?.type === 'variable'\n ) {\n // TODO:多字段,常量\n params.push(record[field]);\n }\n });\n // console.log('params', params)\n // console.log('attribute', attribute)\n\n const mappingResult = attribute.mapping ? attribute.mapping(params) : [];\n if (attribute.name === 'color' && !isColor(mappingResult[0])) {\n return [minimumColor];\n }\n return mappingResult;\n // return attribute.mapping ? attribute.mapping(params) : [];\n }\n}\n"],"file":"DataMappingPlugin.js"}
@@ -12,7 +12,6 @@ export default class FeatureScalePlugin implements ILayerPlugin {
12
12
  }): void;
13
13
  private isNumber;
14
14
  private caculateScalesForAttributes;
15
- private getOrCreateScale;
16
15
  /**
17
16
  * @example
18
17
  * 'w*h' => ['w', 'h']
@@ -21,6 +20,6 @@ export default class FeatureScalePlugin implements ILayerPlugin {
21
20
  private parseFields;
22
21
  private createScale;
23
22
  private getDefaultType;
24
- private createDefaultScaleConfig;
23
+ private createScaleConfig;
25
24
  private createDefaultScale;
26
25
  }
@@ -10,13 +10,18 @@ import _isNil from "lodash/isNil";
10
10
 
11
11
  var _scaleMap, _dec, _dec2, _class, _class2, _descriptor;
12
12
 
13
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
14
+
15
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
16
+
13
17
  import { ScaleTypes, StyleScaleType, TYPES } from '@antv/l7-core';
14
18
  import { extent } from 'd3-array';
19
+ import * as d3interpolate from 'd3-interpolate';
15
20
  import * as d3 from 'd3-scale';
16
21
  import { inject, injectable } from 'inversify';
17
22
  import 'reflect-metadata';
18
23
  var dateRegex = /^(?:(?!0000)[0-9]{4}([-/.]+)(?:(?:0?[1-9]|1[0-2])\1(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])\1(?:29|30)|(?:0?[13578]|1[02])\1(?:31))|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)([-/.]?)0?2\2(?:29))(\s+([01]|([01][0-9]|2[0-3])):([0-9]|[0-5][0-9]):([0-9]|[0-5][0-9]))?$/;
19
- var scaleMap = (_scaleMap = {}, _defineProperty(_scaleMap, ScaleTypes.LINEAR, d3.scaleLinear), _defineProperty(_scaleMap, ScaleTypes.POWER, d3.scalePow), _defineProperty(_scaleMap, ScaleTypes.LOG, d3.scaleLog), _defineProperty(_scaleMap, ScaleTypes.IDENTITY, d3.scaleIdentity), _defineProperty(_scaleMap, ScaleTypes.TIME, d3.scaleTime), _defineProperty(_scaleMap, ScaleTypes.QUANTILE, d3.scaleQuantile), _defineProperty(_scaleMap, ScaleTypes.QUANTIZE, d3.scaleQuantize), _defineProperty(_scaleMap, ScaleTypes.THRESHOLD, d3.scaleThreshold), _defineProperty(_scaleMap, ScaleTypes.CAT, d3.scaleOrdinal), _scaleMap);
24
+ var scaleMap = (_scaleMap = {}, _defineProperty(_scaleMap, ScaleTypes.LINEAR, d3.scaleLinear), _defineProperty(_scaleMap, ScaleTypes.POWER, d3.scalePow), _defineProperty(_scaleMap, ScaleTypes.LOG, d3.scaleLog), _defineProperty(_scaleMap, ScaleTypes.IDENTITY, d3.scaleIdentity), _defineProperty(_scaleMap, ScaleTypes.SEQUENTIAL, d3.scaleSequential), _defineProperty(_scaleMap, ScaleTypes.TIME, d3.scaleTime), _defineProperty(_scaleMap, ScaleTypes.QUANTILE, d3.scaleQuantile), _defineProperty(_scaleMap, ScaleTypes.QUANTIZE, d3.scaleQuantize), _defineProperty(_scaleMap, ScaleTypes.THRESHOLD, d3.scaleThreshold), _defineProperty(_scaleMap, ScaleTypes.CAT, d3.scaleOrdinal), _defineProperty(_scaleMap, ScaleTypes.DIVERGING, d3.scaleDiverging), _scaleMap);
20
25
  var FeatureScalePlugin = (_dec = injectable(), _dec2 = inject(TYPES.IGlobalConfigService), _dec(_class = (_class2 = function () {
21
26
  function FeatureScalePlugin() {
22
27
  _classCallCheck(this, FeatureScalePlugin);
@@ -98,7 +103,9 @@ var FeatureScalePlugin = (_dec = injectable(), _dec2 = inject(TYPES.IGlobalConfi
98
103
  attributeScale.names = _this2.parseFields(attribute.scale.field || []);
99
104
  var scales = [];
100
105
  attributeScale.names.forEach(function (field) {
101
- scales.push(_this2.getOrCreateScale(field, attribute, dataArray));
106
+ var _attribute$scale;
107
+
108
+ scales.push(_this2.createScale(field, attribute.name, (_attribute$scale = attribute.scale) === null || _attribute$scale === void 0 ? void 0 : _attribute$scale.values, dataArray));
102
109
  });
103
110
 
104
111
  if (scales.some(function (scale) {
@@ -107,22 +114,14 @@ var FeatureScalePlugin = (_dec = injectable(), _dec2 = inject(TYPES.IGlobalConfi
107
114
  attributeScale.type = StyleScaleType.VARIABLE;
108
115
  scales.forEach(function (scale) {
109
116
  if (!attributeScale.callback) {
110
- var _scale$option2;
111
-
112
- if (attributeScale.values && attributeScale.values !== 'text') {
113
- var _scale$option;
114
-
115
- if (((_scale$option = scale.option) === null || _scale$option === void 0 ? void 0 : _scale$option.type) === 'linear' && attributeScale.values.length > 2) {
116
- var tick = scale.scale.ticks(attributeScale.values.length);
117
-
118
- if (type === 'color') {
119
- scale.scale.domain(tick);
120
- }
121
- }
117
+ var _scale$option, _scale$option2, _scale$option3, _scale$option4, _scale$option5;
122
118
 
119
+ if (attributeScale.values && attributeScale.values !== 'text' && ((_scale$option = scale.option) === null || _scale$option === void 0 ? void 0 : _scale$option.type) !== ScaleTypes.DIVERGING && ((_scale$option2 = scale.option) === null || _scale$option2 === void 0 ? void 0 : _scale$option2.type) !== ScaleTypes.SEQUENTIAL) {
123
120
  scale.scale.range(attributeScale.values);
124
- } else if (((_scale$option2 = scale.option) === null || _scale$option2 === void 0 ? void 0 : _scale$option2.type) === 'cat') {
121
+ } else if (((_scale$option3 = scale.option) === null || _scale$option3 === void 0 ? void 0 : _scale$option3.type) === ScaleTypes.CAT) {
125
122
  scale.scale.range(scale.option.domain);
123
+ } else if (((_scale$option4 = scale.option) === null || _scale$option4 === void 0 ? void 0 : _scale$option4.type) === ScaleTypes.DIVERGING || ((_scale$option5 = scale.option) === null || _scale$option5 === void 0 ? void 0 : _scale$option5.type) === ScaleTypes.SEQUENTIAL) {
124
+ scale.scale.interpolator(d3interpolate.interpolateRgbBasis(attributeScale.values));
126
125
  }
127
126
  }
128
127
  });
@@ -144,16 +143,6 @@ var FeatureScalePlugin = (_dec = injectable(), _dec2 = inject(TYPES.IGlobalConfi
144
143
  }
145
144
  });
146
145
  }
147
- }, {
148
- key: "getOrCreateScale",
149
- value: function getOrCreateScale(field, attribute, dataArray) {
150
- var _attribute$scale;
151
-
152
- var scalekey = [field, attribute.name].join('_');
153
- var values = (_attribute$scale = attribute.scale) === null || _attribute$scale === void 0 ? void 0 : _attribute$scale.values;
154
- var styleScale = this.createScale(field, attribute.name, values, dataArray);
155
- return styleScale;
156
- }
157
146
  }, {
158
147
  key: "parseFields",
159
148
  value: function parseFields(field) {
@@ -205,8 +194,7 @@ var FeatureScalePlugin = (_dec = injectable(), _dec2 = inject(TYPES.IGlobalConfi
205
194
  type = ScaleTypes.CAT;
206
195
  }
207
196
 
208
- var cfg = this.createDefaultScaleConfig(type, field, data);
209
- Object.assign(cfg, scaleOption);
197
+ var cfg = this.createScaleConfig(type, field, scaleOption, data);
210
198
  styleScale.scale = this.createDefaultScale(cfg);
211
199
  styleScale.option = cfg;
212
200
  }
@@ -225,8 +213,8 @@ var FeatureScalePlugin = (_dec = injectable(), _dec2 = inject(TYPES.IGlobalConfi
225
213
  return type;
226
214
  }
227
215
  }, {
228
- key: "createDefaultScaleConfig",
229
- value: function createDefaultScaleConfig(type, field, data) {
216
+ key: "createScaleConfig",
217
+ value: function createScaleConfig(type, field, scaleOption, data) {
230
218
  var cfg = {
231
219
  type: type
232
220
  };
@@ -234,27 +222,48 @@ var FeatureScalePlugin = (_dec = injectable(), _dec2 = inject(TYPES.IGlobalConfi
234
222
  return item[field];
235
223
  })) || [];
236
224
 
237
- if (type !== ScaleTypes.CAT && type !== ScaleTypes.QUANTILE) {
225
+ if (scaleOption !== null && scaleOption !== void 0 && scaleOption.domain) {
226
+ cfg.domain = scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.domain;
227
+ } else if (type !== ScaleTypes.CAT && type !== ScaleTypes.QUANTILE && type !== ScaleTypes.DIVERGING) {
238
228
  cfg.domain = extent(values);
239
229
  } else if (type === ScaleTypes.CAT) {
240
230
  cfg.domain = _uniq(values);
241
231
  } else if (type === ScaleTypes.QUANTILE) {
242
232
  cfg.domain = values;
233
+ } else if (type === ScaleTypes.DIVERGING) {
234
+ var minMax = extent(values);
235
+ var neutral = (scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.neutral) !== undefined ? scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.neutral : (minMax[0] + minMax[1]) / 2;
236
+ cfg.domain = [minMax[0], neutral, minMax[1]];
243
237
  }
244
238
 
245
- return cfg;
239
+ return _objectSpread(_objectSpread({}, cfg), scaleOption);
246
240
  }
247
241
  }, {
248
242
  key: "createDefaultScale",
249
243
  value: function createDefaultScale(_ref2) {
250
244
  var type = _ref2.type,
251
- domain = _ref2.domain;
245
+ domain = _ref2.domain,
246
+ unknown = _ref2.unknown,
247
+ clamp = _ref2.clamp,
248
+ nice = _ref2.nice;
252
249
  var scale = scaleMap[type]();
253
250
 
254
- if (domain) {
251
+ if (domain && scale.domain) {
255
252
  scale.domain(domain);
256
253
  }
257
254
 
255
+ if (unknown) {
256
+ scale.unknown(unknown);
257
+ }
258
+
259
+ if (clamp !== undefined && scale.clamp) {
260
+ scale.clamp(clamp);
261
+ }
262
+
263
+ if (nice !== undefined && scale.nice) {
264
+ scale.nice(nice);
265
+ }
266
+
258
267
  return scale;
259
268
  }
260
269
  }]);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/FeatureScalePlugin.ts"],"names":["ScaleTypes","StyleScaleType","TYPES","extent","d3","inject","injectable","dateRegex","scaleMap","LINEAR","scaleLinear","POWER","scalePow","LOG","scaleLog","IDENTITY","scaleIdentity","TIME","scaleTime","QUANTILE","scaleQuantile","QUANTIZE","scaleQuantize","THRESHOLD","scaleThreshold","CAT","scaleOrdinal","FeatureScalePlugin","IGlobalConfigService","layer","styleAttributeService","hooks","init","tap","scaleOptions","getScaleOptions","attributes","getLayerStyleAttributes","dataArray","getSource","data","length","caculateScalesForAttributes","beforeRenderData","layerModelNeedUpdate","beforeRender","attributesToRescale","filter","attribute","needRescale","n","isNaN","parseFloat","isFinite","scaleCache","forEach","scale","attributeScale","type","name","names","parseFields","field","scales","push","getOrCreateScale","some","VARIABLE","callback","values","option","tick","ticks","domain","range","CONSTANT","defaultValues","map","index","scalers","func","scalekey","join","styleScale","createScale","Array","isArray","split","scaleOption","undefined","createDefaultScale","firstValue","find","d","isNumber","getDefaultType","cfg","createDefaultScaleConfig","Object","assign","test","item"],"mappings":";;;;;;;;;;;;AAAA,SAUEA,UAVF,EAWEC,cAXF,EAYEC,KAZF,QAaO,eAbP;AAeA,SAASC,MAAT,QAA8B,UAA9B;AACA,OAAO,KAAKC,EAAZ,MAAoB,UAApB;AACA,SAASC,MAAT,EAAiBC,UAAjB,QAAmC,WAAnC;AAEA,OAAO,kBAAP;AAEA,IAAMC,SAAS,GAAG,sTAAlB;AAEA,IAAMC,QAAQ,+CACXR,UAAU,CAACS,MADA,EACSL,EAAE,CAACM,WADZ,8BAEXV,UAAU,CAACW,KAFA,EAEQP,EAAE,CAACQ,QAFX,8BAGXZ,UAAU,CAACa,GAHA,EAGMT,EAAE,CAACU,QAHT,8BAIXd,UAAU,CAACe,QAJA,EAIWX,EAAE,CAACY,aAJd,8BAKXhB,UAAU,CAACiB,IALA,EAKOb,EAAE,CAACc,SALV,8BAMXlB,UAAU,CAACmB,QANA,EAMWf,EAAE,CAACgB,aANd,8BAOXpB,UAAU,CAACqB,QAPA,EAOWjB,EAAE,CAACkB,aAPd,8BAQXtB,UAAU,CAACuB,SARA,EAQYnB,EAAE,CAACoB,cARf,8BASXxB,UAAU,CAACyB,GATA,EASMrB,EAAE,CAACsB,YATT,aAAd;IAgBqBC,kB,WADpBrB,UAAU,E,UAERD,MAAM,CAACH,KAAK,CAAC0B,oBAAP,C;;;;;;wCAKH,E;;0CAEkC,E;;;;;WAEtC,eACEC,KADF,QAKE;AAAA;;AAAA,UAFEC,qBAEF,QAFEA,qBAEF;AACAD,MAAAA,KAAK,CAACE,KAAN,CAAYC,IAAZ,CAAiBC,GAAjB,CAAqB,oBAArB,EAA2C,YAAM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;;;WAED,mCAAqD;AAAA,UAAxBtC,IAAwB,SAAxBA,IAAwB;AAAA,UAAlBe,MAAkB,SAAlBA,MAAkB;AAEnD,UAAMjB,KAAK,GAAGhD,QAAQ,CAACkD,IAAD,CAAR,EAAd;;AACA,UAAIe,MAAJ,EAAY;AACVjB,QAAAA,KAAK,CAACiB,MAAN,CAAaA,MAAb;AACD;;AAED,aAAOjB,KAAP;AACD;;;;;;;;;;SAjPkB7B,kB","sourcesContent":["import {\n IGlobalConfigService,\n ILayer,\n ILayerPlugin,\n IScale,\n IScaleOptions,\n IStyleAttribute,\n IStyleAttributeService,\n IStyleScale,\n ScaleTypeName,\n ScaleTypes,\n StyleScaleType,\n TYPES,\n} from '@antv/l7-core';\nimport { IParseDataItem } from '@antv/l7-source';\nimport { extent, ticks } from 'd3-array';\nimport * as d3 from 'd3-scale';\nimport { inject, injectable } from 'inversify';\nimport { isNil, isString, uniq } from 'lodash';\nimport 'reflect-metadata';\n\nconst dateRegex = /^(?:(?!0000)[0-9]{4}([-/.]+)(?:(?:0?[1-9]|1[0-2])\\1(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])\\1(?:29|30)|(?:0?[13578]|1[02])\\1(?:31))|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)([-/.]?)0?2\\2(?:29))(\\s+([01]|([01][0-9]|2[0-3])):([0-9]|[0-5][0-9]):([0-9]|[0-5][0-9]))?$/;\n\nconst scaleMap = {\n [ScaleTypes.LINEAR]: d3.scaleLinear,\n [ScaleTypes.POWER]: d3.scalePow,\n [ScaleTypes.LOG]: d3.scaleLog,\n [ScaleTypes.IDENTITY]: d3.scaleIdentity,\n [ScaleTypes.TIME]: d3.scaleTime,\n [ScaleTypes.QUANTILE]: d3.scaleQuantile,\n [ScaleTypes.QUANTIZE]: d3.scaleQuantize,\n [ScaleTypes.THRESHOLD]: d3.scaleThreshold,\n [ScaleTypes.CAT]: d3.scaleOrdinal,\n};\n\n/**\n * 根据 Source 原始数据为指定字段创建 Scale,保存在 StyleAttribute 上,供下游插件使用\n */\n@injectable()\nexport default class FeatureScalePlugin implements ILayerPlugin {\n @inject(TYPES.IGlobalConfigService)\n private readonly configService: IGlobalConfigService;\n // key = field_attribute name\n private scaleCache: {\n [field: string]: IStyleScale;\n } = {};\n\n private scaleOptions: IScaleOptions = {};\n\n public apply(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n layer.hooks.init.tap('FeatureScalePlugin', () => {\n this.scaleOptions = layer.getScaleOptions();\n const attributes = styleAttributeService.getLayerStyleAttributes();\n const { dataArray } = layer.getSource().data;\n if (dataArray.length === 0) {\n return;\n }\n this.caculateScalesForAttributes(attributes || [], dataArray);\n });\n\n // 检测数据是否需要更新\n layer.hooks.beforeRenderData.tap('FeatureScalePlugin', () => {\n this.scaleOptions = layer.getScaleOptions();\n const attributes = styleAttributeService.getLayerStyleAttributes();\n const { dataArray } = layer.getSource().data;\n this.caculateScalesForAttributes(attributes || [], dataArray);\n layer.layerModelNeedUpdate = true;\n return true;\n });\n\n layer.hooks.beforeRender.tap('FeatureScalePlugin', () => {\n if (layer.layerModelNeedUpdate) {\n return;\n }\n this.scaleOptions = layer.getScaleOptions();\n const attributes = styleAttributeService.getLayerStyleAttributes();\n if (attributes) {\n const { dataArray } = layer.getSource().data;\n if (dataArray.length === 0) {\n return;\n }\n const attributesToRescale = attributes.filter(\n (attribute) => attribute.needRescale,\n );\n if (attributesToRescale.length) {\n this.caculateScalesForAttributes(attributesToRescale, dataArray);\n }\n }\n });\n }\n private isNumber(n: any) {\n return !isNaN(parseFloat(n)) && isFinite(n);\n }\n\n private caculateScalesForAttributes(\n attributes: IStyleAttribute[],\n dataArray: IParseDataItem[],\n ) {\n this.scaleCache = {};\n attributes.forEach((attribute) => {\n if (attribute.scale) {\n // 创建Scale\n const attributeScale = attribute.scale;\n const type = attribute.name;\n attributeScale.names = this.parseFields(attribute!.scale!.field || []);\n const scales: IStyleScale[] = [];\n attributeScale.names.forEach((field: string | number) => {\n scales.push(this.getOrCreateScale(field, attribute, dataArray));\n });\n\n // 为scales 设置值区间\n if (scales.some((scale) => scale.type === StyleScaleType.VARIABLE)) {\n attributeScale.type = StyleScaleType.VARIABLE;\n scales.forEach((scale) => {\n // 如果设置了回调, 这不需要设置让range\n if (!attributeScale.callback) {\n if (attributeScale.values && attributeScale.values !== 'text') {\n if (\n scale.option?.type === 'linear' &&\n attributeScale.values.length > 2\n ) {\n const tick = scale.scale.ticks(attributeScale.values.length);\n if (type === 'color') {\n // TODO: 这里改变了值域,获取图例的时候有问题\n scale.scale.domain(tick);\n }\n }\n scale.scale.range(attributeScale.values); // 判断常量, 默认值\n } else if (scale.option?.type === 'cat') {\n // 如果没有设置初值且 类型为cat,range ==domain;\n\n scale.scale.range(scale.option.domain);\n }\n }\n });\n } else {\n // 设置attribute 常量值 常量直接在value取值\n attributeScale.type = StyleScaleType.CONSTANT;\n attributeScale.defaultValues = scales.map((scale, index) => {\n return scale.scale(attributeScale.names[index]);\n });\n }\n attributeScale.scalers = scales.map((scale: IStyleScale) => {\n return {\n field: scale.field,\n func: scale.scale,\n option: scale.option,\n };\n });\n\n attribute.needRescale = false;\n }\n });\n }\n private getOrCreateScale(\n field: string | number,\n attribute: IStyleAttribute,\n dataArray: IParseDataItem[],\n ) {\n const scalekey = [field, attribute.name].join('_');\n const values = attribute.scale?.values;\n // if (this.scaleCache[scalekey]) {\n // return this.scaleCache[scalekey];\n // }\n const styleScale = this.createScale(\n field,\n attribute.name,\n values,\n dataArray,\n );\n // this.scaleCache[scalekey] = styleScale;\n return styleScale;\n }\n\n /**\n * @example\n * 'w*h' => ['w', 'h']\n * 'w' => ['w']\n */\n private parseFields(\n field: string[] | string | number[] | number,\n ): string[] | number[] {\n if (Array.isArray(field)) {\n return field;\n }\n if (isString(field)) {\n return field.split('*');\n }\n return [field];\n }\n\n private createScale(\n field: string | number,\n name: string,\n values: unknown[] | string | undefined,\n data?: IParseDataItem[],\n ): IStyleScale {\n // scale 支持根据视觉通道和字段\n const scaleOption: IScale | undefined =\n this.scaleOptions[name] && this.scaleOptions[name]?.field === field\n ? this.scaleOptions[name]\n : this.scaleOptions[field];\n const styleScale: IStyleScale = {\n field,\n scale: undefined,\n type: StyleScaleType.VARIABLE,\n option: scaleOption,\n };\n\n if (!data || !data.length) {\n if (scaleOption && scaleOption.type) {\n styleScale.scale = this.createDefaultScale(scaleOption);\n } else {\n styleScale.scale = d3.scaleOrdinal([field]);\n styleScale.type = StyleScaleType.CONSTANT;\n }\n return styleScale;\n }\n const firstValue = data!.find((d) => !isNil(d[field]))?.[field];\n // 常量 Scale\n if (this.isNumber(field) || (isNil(firstValue) && !scaleOption)) {\n styleScale.scale = d3.scaleOrdinal([field]);\n styleScale.type = StyleScaleType.CONSTANT;\n } else {\n // 根据数据类型判断 默认等分位,时间,和枚举类型\n let type =\n (scaleOption && scaleOption.type) || this.getDefaultType(firstValue);\n if (values === 'text') {\n // text 为内置变 如果是文本则为cat\n type = ScaleTypes.CAT;\n }\n const cfg = this.createDefaultScaleConfig(type, field, data);\n Object.assign(cfg, scaleOption);\n styleScale.scale = this.createDefaultScale(cfg);\n styleScale.option = cfg;\n }\n return styleScale;\n }\n\n private getDefaultType(firstValue: unknown) {\n let type = ScaleTypes.LINEAR;\n if (typeof firstValue === 'string') {\n type = dateRegex.test(firstValue) ? ScaleTypes.TIME : ScaleTypes.CAT;\n }\n return type;\n }\n\n private createDefaultScaleConfig(\n type: ScaleTypeName,\n field: string | number,\n data?: IParseDataItem[],\n ) {\n const cfg: IScale = {\n type,\n };\n const values = data?.map((item) => item[field]) || [];\n // 默认类型为 Quantile Scales https://github.com/d3/d3-scale#quantile-scales\n if (type !== ScaleTypes.CAT && type !== ScaleTypes.QUANTILE) {\n cfg.domain = extent(values);\n } else if (type === ScaleTypes.CAT) {\n cfg.domain = uniq(values);\n } else if (type === ScaleTypes.QUANTILE) {\n cfg.domain = values;\n }\n return cfg;\n }\n\n private createDefaultScale({ type, domain }: IScale) {\n // @ts-ignore\n const scale = scaleMap[type]();\n if (domain) {\n scale.domain(domain);\n }\n // TODO 其他属性支持\n return scale;\n }\n}\n"],"file":"FeatureScalePlugin.js"}
1
+ {"version":3,"sources":["../../src/plugins/FeatureScalePlugin.ts"],"names":["ScaleTypes","StyleScaleType","TYPES","extent","d3interpolate","d3","inject","injectable","dateRegex","scaleMap","LINEAR","scaleLinear","POWER","scalePow","LOG","scaleLog","IDENTITY","scaleIdentity","SEQUENTIAL","scaleSequential","TIME","scaleTime","QUANTILE","scaleQuantile","QUANTIZE","scaleQuantize","THRESHOLD","scaleThreshold","CAT","scaleOrdinal","DIVERGING","scaleDiverging","FeatureScalePlugin","IGlobalConfigService","layer","styleAttributeService","hooks","init","tap","scaleOptions","getScaleOptions","attributes","getLayerStyleAttributes","dataArray","getSource","data","length","caculateScalesForAttributes","beforeRenderData","layerModelNeedUpdate","beforeRender","attributesToRescale","filter","attribute","needRescale","n","isNaN","parseFloat","isFinite","scaleCache","forEach","scale","attributeScale","type","name","names","parseFields","field","scales","push","createScale","values","some","VARIABLE","callback","option","range","domain","interpolator","interpolateRgbBasis","CONSTANT","defaultValues","map","index","scalers","func","Array","isArray","split","scaleOption","styleScale","undefined","createDefaultScale","firstValue","find","d","isNumber","getDefaultType","cfg","createScaleConfig","test","item","minMax","neutral","unknown","clamp","nice"],"mappings":";;;;;;;;;;;;;;;;AAAA,SAUEA,UAVF,EAWEC,cAXF,EAYEC,KAZF,QAaO,eAbP;AAeA,SAASC,MAAT,QAA8B,UAA9B;AACA,OAAO,KAAKC,aAAZ,MAA+B,gBAA/B;AACA,OAAO,KAAKC,EAAZ,MAAoB,UAApB;AACA,SAASC,MAAT,EAAiBC,UAAjB,QAAmC,WAAnC;AAEA,OAAO,kBAAP;AAEA,IAAMC,SAAS,GAAG,sTAAlB;AAEA,IAAMC,QAAQ,+CACXT,UAAU,CAACU,MADA,EACSL,EA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AAD,CAA3B,CAAb;AACD;;AACD,6CAAYJ,GAAZ,GAAoBT,WAApB;AACD;;;WAGD,mCAA2E;AAAA,UAA9C1B,IAA8C,SAA9CA,IAA8C;AAAA,UAAxCc,MAAwC,SAAxCA,MAAwC;AAAA,UAAhC2B,OAAgC,SAAhCA,OAAgC;AAAA,UAAvBC,KAAuB,SAAvBA,KAAuB;AAAA,UAAhBC,IAAgB,SAAhBA,IAAgB;AAEzE,UAAM7C,KAAK,GAAGpD,QAAQ,CAACsD,IAAD,CAAR,EAAd;;AACA,UAAIc,MAAM,IAAIhB,KAAK,CAACgB,MAApB,EAA4B;AAC1BhB,QAAAA,KAAK,CAACgB,MAAN,CAAaA,MAAb;AACD;;AACD,UAAI2B,OAAJ,EAAa;AACX3C,QAAAA,KAAK,CAAC2C,OAAN,CAAcA,OAAd;AACD;;AACD,UAAIC,KAAK,KAAKd,SAAV,IAAuB9B,KAAK,CAAC4C,KAAjC,EAAwC;AACtC5C,QAAAA,KAAK,CAAC4C,KAAN,CAAYA,KAAZ;AACD;;AACD,UAAIC,IAAI,KAAKf,SAAT,IAAsB9B,KAAK,CAAC6C,IAAhC,EAAsC;AACpC7C,QAAAA,KAAK,CAAC6C,IAAN,CAAWA,IAAX;AACD;;AAED,aAAO7C,KAAP;AACD;;;;;;;;;;SAlQkB7B,kB","sourcesContent":["import {\n IGlobalConfigService,\n ILayer,\n ILayerPlugin,\n IScale,\n IScaleOptions,\n IStyleAttribute,\n IStyleAttributeService,\n IStyleScale,\n ScaleTypeName,\n ScaleTypes,\n StyleScaleType,\n TYPES,\n} from '@antv/l7-core';\nimport { IParseDataItem } from '@antv/l7-source';\nimport { extent, ticks } from 'd3-array';\nimport * as d3interpolate from 'd3-interpolate';\nimport * as d3 from 'd3-scale';\nimport { inject, injectable } from 'inversify';\nimport { isNil, isString, uniq } from 'lodash';\nimport 'reflect-metadata';\n\nconst dateRegex = /^(?:(?!0000)[0-9]{4}([-/.]+)(?:(?:0?[1-9]|1[0-2])\\1(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])\\1(?:29|30)|(?:0?[13578]|1[02])\\1(?:31))|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)([-/.]?)0?2\\2(?:29))(\\s+([01]|([01][0-9]|2[0-3])):([0-9]|[0-5][0-9]):([0-9]|[0-5][0-9]))?$/;\n\nconst scaleMap = {\n [ScaleTypes.LINEAR]: d3.scaleLinear,\n [ScaleTypes.POWER]: d3.scalePow,\n [ScaleTypes.LOG]: d3.scaleLog,\n [ScaleTypes.IDENTITY]: d3.scaleIdentity,\n [ScaleTypes.SEQUENTIAL]: d3.scaleSequential,\n [ScaleTypes.TIME]: d3.scaleTime,\n [ScaleTypes.QUANTILE]: d3.scaleQuantile,\n [ScaleTypes.QUANTIZE]: d3.scaleQuantize,\n [ScaleTypes.THRESHOLD]: d3.scaleThreshold,\n [ScaleTypes.CAT]: d3.scaleOrdinal,\n [ScaleTypes.DIVERGING]: d3.scaleDiverging,\n};\n\n/**\n * 根据 Source 原始数据为指定字段创建 Scale,保存在 StyleAttribute 上,供下游插件使用\n */\n@injectable()\nexport default class FeatureScalePlugin implements ILayerPlugin {\n @inject(TYPES.IGlobalConfigService)\n private readonly configService: IGlobalConfigService;\n // key = field_attribute name\n private scaleCache: {\n [field: string]: IStyleScale;\n } = {};\n\n private scaleOptions: IScaleOptions = {};\n\n public apply(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n layer.hooks.init.tap('FeatureScalePlugin', () => {\n this.scaleOptions = layer.getScaleOptions();\n const attributes = styleAttributeService.getLayerStyleAttributes();\n const { dataArray } = layer.getSource().data;\n if (dataArray.length === 0) {\n return;\n }\n this.caculateScalesForAttributes(attributes || [], dataArray);\n });\n\n // 检测数据是否需要更新\n layer.hooks.beforeRenderData.tap('FeatureScalePlugin', () => {\n this.scaleOptions = layer.getScaleOptions();\n const attributes = styleAttributeService.getLayerStyleAttributes();\n const { dataArray } = layer.getSource().data;\n this.caculateScalesForAttributes(attributes || [], dataArray);\n layer.layerModelNeedUpdate = true;\n return true;\n });\n\n layer.hooks.beforeRender.tap('FeatureScalePlugin', () => {\n if (layer.layerModelNeedUpdate) {\n return;\n }\n this.scaleOptions = layer.getScaleOptions();\n const attributes = styleAttributeService.getLayerStyleAttributes();\n if (attributes) {\n const { dataArray } = layer.getSource().data;\n if (dataArray.length === 0) {\n return;\n }\n const attributesToRescale = attributes.filter(\n (attribute) => attribute.needRescale,\n );\n if (attributesToRescale.length) {\n this.caculateScalesForAttributes(attributesToRescale, dataArray);\n }\n }\n });\n }\n private isNumber(n: any) {\n return !isNaN(parseFloat(n)) && isFinite(n);\n }\n\n private caculateScalesForAttributes(\n attributes: IStyleAttribute[],\n dataArray: IParseDataItem[],\n ) {\n this.scaleCache = {};\n attributes.forEach((attribute) => {\n if (attribute.scale) {\n // 创建Scale\n const attributeScale = attribute.scale;\n const type = attribute.name;\n attributeScale.names = this.parseFields(attribute!.scale!.field || []);\n const scales: IStyleScale[] = [];\n // 为每个字段创建 Scale\n attributeScale.names.forEach((field: string | number) => {\n scales.push(\n this.createScale(\n field,\n attribute.name,\n attribute.scale?.values,\n dataArray,\n ),\n );\n });\n\n // 为scales 设置值区间 Range\n if (scales.some((scale) => scale.type === StyleScaleType.VARIABLE)) {\n attributeScale.type = StyleScaleType.VARIABLE;\n scales.forEach((scale) => {\n // 如果设置了回调, 这不需要设置range\n if (!attributeScale.callback) {\n if (\n attributeScale.values &&\n attributeScale.values !== 'text' &&\n scale.option?.type !== ScaleTypes.DIVERGING &&\n scale.option?.type !== ScaleTypes.SEQUENTIAL\n ) {\n scale.scale.range(attributeScale.values); // 判断常量, 默认值\n } else if (scale.option?.type === ScaleTypes.CAT) {\n // 如果没有设置初值且 类型为cat,range ==domain;\n scale.scale.range(scale.option.domain);\n } else if (\n scale.option?.type === ScaleTypes.DIVERGING ||\n scale.option?.type === ScaleTypes.SEQUENTIAL\n ) {\n scale.scale.interpolator(\n // @ts-ignore\n d3interpolate.interpolateRgbBasis(attributeScale.values),\n );\n }\n }\n });\n } else {\n // 设置attribute 常量值 常量直接在value取值\n attributeScale.type = StyleScaleType.CONSTANT;\n attributeScale.defaultValues = scales.map((scale, index) => {\n return scale.scale(attributeScale.names[index]);\n });\n }\n attributeScale.scalers = scales.map((scale: IStyleScale) => {\n return {\n field: scale.field,\n func: scale.scale,\n option: scale.option,\n };\n });\n\n attribute.needRescale = false;\n }\n });\n }\n\n /**\n * @example\n * 'w*h' => ['w', 'h']\n * 'w' => ['w']\n */\n private parseFields(\n field: string[] | string | number[] | number,\n ): string[] | number[] {\n if (Array.isArray(field)) {\n return field;\n }\n if (isString(field)) {\n return field.split('*');\n }\n return [field];\n }\n\n private createScale(\n field: string | number,\n name: string,\n values: unknown[] | string | undefined,\n data?: IParseDataItem[],\n ): IStyleScale {\n // scale 支持根据视觉通道和字段\n const scaleOption: IScale | undefined =\n this.scaleOptions[name] && this.scaleOptions[name]?.field === field\n ? this.scaleOptions[name] // TODO zi\n : this.scaleOptions[field];\n const styleScale: IStyleScale = {\n field,\n scale: undefined,\n type: StyleScaleType.VARIABLE,\n option: scaleOption,\n };\n\n if (!data || !data.length) {\n if (scaleOption && scaleOption.type) {\n styleScale.scale = this.createDefaultScale(scaleOption);\n } else {\n styleScale.scale = d3.scaleOrdinal([field]);\n styleScale.type = StyleScaleType.CONSTANT;\n }\n return styleScale;\n }\n const firstValue = data!.find((d) => !isNil(d[field]))?.[field];\n // 常量 Scale\n if (this.isNumber(field) || (isNil(firstValue) && !scaleOption)) {\n styleScale.scale = d3.scaleOrdinal([field]);\n styleScale.type = StyleScaleType.CONSTANT;\n } else {\n // 根据数据类型判断 默认等分位,时间,和枚举类型\n let type =\n (scaleOption && scaleOption.type) || this.getDefaultType(firstValue);\n if (values === 'text') {\n // text 为内置变 如果是文本则为cat\n type = ScaleTypes.CAT;\n }\n const cfg = this.createScaleConfig(type, field, scaleOption, data);\n\n styleScale.scale = this.createDefaultScale(cfg);\n styleScale.option = cfg;\n }\n return styleScale;\n }\n\n private getDefaultType(firstValue: unknown) {\n let type = ScaleTypes.LINEAR;\n if (typeof firstValue === 'string') {\n type = dateRegex.test(firstValue) ? ScaleTypes.TIME : ScaleTypes.CAT;\n }\n return type;\n }\n // 生成Scale 默认配置\n private createScaleConfig(\n type: ScaleTypeName,\n field: string | number,\n scaleOption: IScale | undefined,\n data?: IParseDataItem[],\n ) {\n const cfg: IScale = {\n type,\n };\n const values = data?.map((item) => item[field]) || [];\n if (scaleOption?.domain) {\n cfg.domain = scaleOption?.domain;\n }\n // 默认类型为 Quantile Scales https://github.com/d3/d3-scale#quantile-scales\n else if (\n type !== ScaleTypes.CAT &&\n type !== ScaleTypes.QUANTILE &&\n type !== ScaleTypes.DIVERGING\n ) {\n // linear/\n cfg.domain = extent(values);\n } else if (type === ScaleTypes.CAT) {\n cfg.domain = uniq(values);\n } else if (type === ScaleTypes.QUANTILE) {\n cfg.domain = values;\n } else if (type === ScaleTypes.DIVERGING) {\n const minMax = extent(values);\n const neutral =\n scaleOption?.neutral !== undefined\n ? scaleOption?.neutral\n : (minMax[0] + minMax[1]) / 2;\n cfg.domain = [minMax[0], neutral, minMax[1]];\n }\n return { ...cfg, ...scaleOption };\n }\n\n // 创建Scale 实例\n private createDefaultScale({ type, domain, unknown, clamp, nice }: IScale) {\n // @ts-ignore\n const scale = scaleMap[type]();\n if (domain && scale.domain) {\n scale.domain(domain);\n }\n if (unknown) {\n scale.unknown(unknown);\n }\n if (clamp !== undefined && scale.clamp) {\n scale.clamp(clamp);\n }\n if (nice !== undefined && scale.nice) {\n scale.nice(nice);\n }\n // TODO 其他属性支持\n return scale;\n }\n}\n"],"file":"FeatureScalePlugin.js"}
@@ -13,4 +13,5 @@ export default class ShaderUniformPlugin implements ILayerPlugin {
13
13
  private readonly rendererService;
14
14
  private readonly mapService;
15
15
  apply(layer: ILayer): void;
16
+ private getLayerCenter;
16
17
  }
@@ -51,6 +51,12 @@ var ShaderUniformPlugin = (_dec = injectable(), _dec2 = inject(TYPES.ICameraServ
51
51
  });
52
52
  });
53
53
  }
54
+ }, {
55
+ key: "getLayerCenter",
56
+ value: function getLayerCenter(layer) {
57
+ var source = layer.getSource();
58
+ return source.center;
59
+ }
54
60
  }]);
55
61
 
56
62
  return ShaderUniformPlugin;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/ShaderUniformPlugin.ts"],"names":["CameraUniform","CoordinateUniform","TYPES","$window","inject","injectable","ShaderUniformPlugin","ICameraService","ICoordinateSystemService","IRendererService","IMapService","layer","version","mapService","mvp","sceneCenterMKT","hooks","beforeRender","tap","coordinateSystemService","refresh","map","customCoords","getMVPMatrix","getCustomCoordCenter","rendererService","getViewportSize","width","height","models","forEach","model","addUniforms","ProjectionMatrix","cameraService","getProjectionMatrix","ViewMatrix","getViewMatrix","ViewProjectionMatrix","getViewProjectionMatrix","Zoom","getZoom","ZoomScale","getZoomScale","FocalDistance","getFocalDistance","CameraPosition","getCameraPosition","CoordinateSystem","getCoordinateSystem","ViewportCenter","getViewportCenter","ViewportCenterProjection","getViewportCenterProjection","PixelsPerDegree","getPixelsPerDegree","PixelsPerDegree2","getPixelsPerDegree2","PixelsPerMeter","getPixelsPerMeter","Mvp","getModelMatrix","devicePixelRatio","getLayerConfig","pickingBuffer","Number","getShaderPickStat"],"mappings":";;;;;;;;;AAAA,SACEA,aADF,EAEEC,iBAFF,EASEC,KATF,QAUO,eAVP;AAWA,SAASC,OAAT,QAAwB,gBAAxB;AACA,SAASC,MAAT,EAAiBC,UAAjB,QAAmC,WAAnC;AACA,OAAO,kBAAP;IAUqBC,mB,WADpBD,UAAU,E,UAERD,MAAM,CAACF,KAAK,CAACK,cAAP,C,UAGNH,MAAM,CAACF,KAAK,CAACM,wBAAP,C,UAGNJ,MAAM,CAACF,KAAK,CAACO,gBAAP,C,UAGNL,MAAM,CAACF,KAAK,CAACQ,WAAP,C;;;;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5D,mB","sourcesContent":["import {\n CameraUniform,\n CoordinateUniform,\n ICameraService,\n ICoordinateSystemService,\n ILayer,\n ILayerPlugin,\n IMapService,\n IRendererService,\n TYPES,\n} from '@antv/l7-core';\nimport { $window } from '@antv/l7-utils';\nimport { inject, injectable } from 'inversify';\nimport 'reflect-metadata';\n\n/**\n * 在渲染之前需要获取当前 Shader 所需 Uniform,例如:\n * 1. 从相机服务中获取 View & ProjectionMatrix,当前缩放等级等等\n * 2. 从坐标系服务中获取当前坐标系,例如是否是偏移坐标系\n * @see https://yuque.antfin-inc.com/yuqi.pyq/fgetpa/doml91\n * 3. 当前 Layer 本身的样式属性\n */\n@injectable()\nexport default class ShaderUniformPlugin implements ILayerPlugin {\n @inject(TYPES.ICameraService)\n private readonly cameraService: ICameraService;\n\n @inject(TYPES.ICoordinateSystemService)\n private readonly coordinateSystemService: ICoordinateSystemService;\n\n @inject(TYPES.IRendererService)\n private readonly rendererService: IRendererService;\n\n @inject(TYPES.IMapService)\n private readonly mapService: IMapService;\n\n public apply(layer: ILayer) {\n const version = this.mapService.version;\n\n let mvp = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; // default matrix (for gaode2.x)\n let sceneCenterMKT = [0, 0];\n layer.hooks.beforeRender.tap('ShaderUniformPlugin', () => {\n // 重新计算坐标系参数\n this.coordinateSystemService.refresh();\n\n if (version === 'GAODE2.x') {\n // @ts-ignore\n mvp = this.mapService.map.customCoords.getMVPMatrix();\n // mvp = amapCustomCoords.getMVPMatrix()\n // @ts-ignore\n sceneCenterMKT = this.mapService.getCustomCoordCenter();\n }\n\n const { width, height } = this.rendererService.getViewportSize();\n layer.models.forEach((model) => {\n model.addUniforms({\n // 相机参数,包含 VP 矩阵、缩放等级\n [CameraUniform.ProjectionMatrix]: this.cameraService.getProjectionMatrix(),\n [CameraUniform.ViewMatrix]: this.cameraService.getViewMatrix(),\n [CameraUniform.ViewProjectionMatrix]: this.cameraService.getViewProjectionMatrix(),\n [CameraUniform.Zoom]: this.cameraService.getZoom(),\n [CameraUniform.ZoomScale]: this.cameraService.getZoomScale(),\n [CameraUniform.FocalDistance]: this.cameraService.getFocalDistance(),\n [CameraUniform.CameraPosition]: this.cameraService.getCameraPosition(),\n // 坐标系参数\n [CoordinateUniform.CoordinateSystem]: this.coordinateSystemService.getCoordinateSystem(),\n [CoordinateUniform.ViewportCenter]: this.coordinateSystemService.getViewportCenter(),\n [CoordinateUniform.ViewportCenterProjection]: this.coordinateSystemService.getViewportCenterProjection(),\n [CoordinateUniform.PixelsPerDegree]: this.coordinateSystemService.getPixelsPerDegree(),\n [CoordinateUniform.PixelsPerDegree2]: this.coordinateSystemService.getPixelsPerDegree2(),\n [CoordinateUniform.PixelsPerMeter]: this.coordinateSystemService.getPixelsPerMeter(),\n // 坐标系是高德2.0的时候单独计算\n [CoordinateUniform.Mvp]: mvp,\n u_SceneCenterMKT: sceneCenterMKT,\n // 其他参数,例如视口大小、DPR 等\n u_ViewportSize: [width, height],\n u_ModelMatrix: this.cameraService.getModelMatrix(),\n u_DevicePixelRatio: $window.devicePixelRatio,\n // u_ModelMatrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],\n u_PickingBuffer: layer.getLayerConfig().pickingBuffer || 0,\n // TODO: 当前地图是否在拖动\n u_shaderPick: Number(layer.getShaderPickStat()),\n });\n });\n\n // TODO:脏检查,决定是否需要渲染\n });\n }\n}\n"],"file":"ShaderUniformPlugin.js"}
1
+ {"version":3,"sources":["../../src/plugins/ShaderUniformPlugin.ts"],"names":["CameraUniform","CoordinateUniform","TYPES","$window","inject","injectable","ShaderUniformPlugin","ICameraService","ICoordinateSystemService","IRendererService","IMapService","layer","version","mapService","mvp","sceneCenterMKT","hooks","beforeRender","tap","coordinateSystemService","refresh","map","customCoords","getMVPMatrix","getCustomCoordCenter","rendererService","getViewportSize","width","height","models","forEach","model","addUniforms","ProjectionMatrix","cameraService","getProjectionMatrix","ViewMatrix","getViewMatrix","ViewProjectionMatrix","getViewProjectionMatrix","Zoom","getZoom","ZoomScale","getZoomScale","FocalDistance","getFocalDistance","CameraPosition","getCameraPosition","CoordinateSystem","getCoordinateSystem","ViewportCenter","getViewportCenter","ViewportCenterProjection","getViewportCenterProjection","PixelsPerDegree","getPixelsPerDegree","PixelsPerDegree2","getPixelsPerDegree2","PixelsPerMeter","getPixelsPerMeter","Mvp","getModelMatrix","devicePixelRatio","getLayerConfig","pickingBuffer","Number","getShaderPickStat","source","getSource","center"],"mappings":";;;;;;;;;AAAA,SACEA,aADF,EAEEC,iBAFF,EASEC,KATF,QAUO,eAVP;AAWA,SAASC,OAAT,QAAwB,gBAAxB;AACA,SAASC,MAAT,EAAiBC,UAAjB,QAAmC,WAAnC;AACA,OAAO,kBAAP;IAUqBC,mB,WADpBD,UAAU,E,UAERD,MAAM,CAACF,KAAK,CAACK,cAAP,C,UAGNH,MAAM,CAACF,KAAK,CAACM,wBAAP,C,UAGNJ,MAAM,CAACF,KAAK,CAACO,gBAAP,C,UAGNL,MAAM,CAACF,KAAK,CAACQ,WAAP,C;;;;;;;;;;;;;;;WAGP,eAAaC,KAAb,EAA4B;AAAA;;AAC1B,UAAMC,OAAO,GAAG,KAAKC,UAAL,CAAgBD,OAAhC;AAEA,UAAIE,GAAG,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,EAA4B,CAA5B,EAA+B,CAA/B,EAAkC,CAAlC,EAAqC,CAArC,EAAwC,CAAxC,EAA2C,CAA3C,EAA8C,CAA9C,CAAV;AACA,UAAIC,cAAc,GAAG,CAAC,CAAD,EAAI,CAAJ,CAArB;AACAJ,MAAAA,KAAK,CAACK,KAAN,CAAYC,YAAZ,CAAyBC,GAAzB,CAA6B,qBAA7B,EAAoD,YAAM;AAExD,QAAA,KAAI,CAACC,uBAAL,CAA6BC,OAA7B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C,uBAAL,CAA6BkC,2BAA7B,EAZhD,uCAaGpD,iBAAiB,CAACqD,eAbrB,EAauC,KAAI,CAACnC,uBAAL,CAA6BoC,kBAA7B,EAbvC,uCAcGtD,iBAAiB,CAACuD,gBAdrB,EAcwC,KAAI,CAACrC,uBAAL,CAA6BsC,mBAA7B,EAdxC,uCAeGxD,iBAAiB,CAACyD,cAfrB,EAesC,KAAI,CAACvC,uBAAL,CAA6BwC,iBAA7B,EAftC,uCAiBG1D,iBAAiB,CAAC2D,GAjBrB,EAiB2B9C,GAjB3B,2DAkBoBC,cAlBpB,yDAoBkB,CAACY,KAAD,EAAQC,MAAR,CApBlB,wDAqBiB,KAAI,CAACM,aAAL,CAAmB2B,cAAnB,EArBjB,6DAsBsB1D,OAAO,CAAC2D,gBAtB9B,0DAwBmBnD,KAAK,CAACoD,cAAN,GAAuBC,aAAvB,IAAwC,CAxB3D,uDA0BgBC,MAAM,CAACtD,KAAK,CAACuD,iBAAN,EAAD,CA1BtB;AA4BD,SA7BD;AAgCD,OAlDD;AAmDD;;;WAED,wBAAuBvD,KAAvB,EAAsC;AACpC,UAAMwD,MAAM,GAAGxD,KAAK,CAACyD,SAAN,EAAf;AACA,aAAOD,MAAM,CAACE,MAAd;AACD;;;;;;;;;;;;;;;;;;;;;;;;;SA1EkB/D,mB","sourcesContent":["import {\n CameraUniform,\n CoordinateUniform,\n ICameraService,\n ICoordinateSystemService,\n ILayer,\n ILayerPlugin,\n IMapService,\n IRendererService,\n TYPES,\n} from '@antv/l7-core';\nimport { $window } from '@antv/l7-utils';\nimport { inject, injectable } from 'inversify';\nimport 'reflect-metadata';\n\n/**\n * 在渲染之前需要获取当前 Shader 所需 Uniform,例如:\n * 1. 从相机服务中获取 View & ProjectionMatrix,当前缩放等级等等\n * 2. 从坐标系服务中获取当前坐标系,例如是否是偏移坐标系\n * @see https://yuque.antfin-inc.com/yuqi.pyq/fgetpa/doml91\n * 3. 当前 Layer 本身的样式属性\n */\n@injectable()\nexport default class ShaderUniformPlugin implements ILayerPlugin {\n @inject(TYPES.ICameraService)\n private readonly cameraService: ICameraService;\n\n @inject(TYPES.ICoordinateSystemService)\n private readonly coordinateSystemService: ICoordinateSystemService;\n\n @inject(TYPES.IRendererService)\n private readonly rendererService: IRendererService;\n\n @inject(TYPES.IMapService)\n private readonly mapService: IMapService;\n\n public apply(layer: ILayer) {\n const version = this.mapService.version;\n\n let mvp = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; // default matrix (for gaode2.x)\n let sceneCenterMKT = [0, 0];\n layer.hooks.beforeRender.tap('ShaderUniformPlugin', () => {\n // 重新计算坐标系参数\n this.coordinateSystemService.refresh();\n\n if (version === 'GAODE2.x') {\n // const layerCenter = this.getLayerCenter(layer);\n // // @ts-ignore\n // this.mapService.map.customCoords.setCenter(layerCenter);\n // // @ts-ignore\n // this.mapService.setCustomCoordCenter(layerCenter);\n // @ts-ignore\n mvp = this.mapService.map.customCoords.getMVPMatrix();\n // mvp = amapCustomCoords.getMVPMatrix()\n // @ts-ignore\n sceneCenterMKT = this.mapService.getCustomCoordCenter();\n }\n\n const { width, height } = this.rendererService.getViewportSize();\n layer.models.forEach((model) => {\n model.addUniforms({\n // 相机参数,包含 VP 矩阵、缩放等级\n [CameraUniform.ProjectionMatrix]: this.cameraService.getProjectionMatrix(),\n [CameraUniform.ViewMatrix]: this.cameraService.getViewMatrix(),\n [CameraUniform.ViewProjectionMatrix]: this.cameraService.getViewProjectionMatrix(),\n [CameraUniform.Zoom]: this.cameraService.getZoom(),\n [CameraUniform.ZoomScale]: this.cameraService.getZoomScale(),\n [CameraUniform.FocalDistance]: this.cameraService.getFocalDistance(),\n [CameraUniform.CameraPosition]: this.cameraService.getCameraPosition(),\n // 坐标系参数\n [CoordinateUniform.CoordinateSystem]: this.coordinateSystemService.getCoordinateSystem(),\n [CoordinateUniform.ViewportCenter]: this.coordinateSystemService.getViewportCenter(),\n [CoordinateUniform.ViewportCenterProjection]: this.coordinateSystemService.getViewportCenterProjection(),\n [CoordinateUniform.PixelsPerDegree]: this.coordinateSystemService.getPixelsPerDegree(),\n [CoordinateUniform.PixelsPerDegree2]: this.coordinateSystemService.getPixelsPerDegree2(),\n [CoordinateUniform.PixelsPerMeter]: this.coordinateSystemService.getPixelsPerMeter(),\n // 坐标系是高德2.0的时候单独计算\n [CoordinateUniform.Mvp]: mvp,\n u_SceneCenterMKT: sceneCenterMKT,\n // 其他参数,例如视口大小、DPR 等\n u_ViewportSize: [width, height],\n u_ModelMatrix: this.cameraService.getModelMatrix(),\n u_DevicePixelRatio: $window.devicePixelRatio,\n // u_ModelMatrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],\n u_PickingBuffer: layer.getLayerConfig().pickingBuffer || 0,\n // TODO: 当前地图是否在拖动\n u_shaderPick: Number(layer.getShaderPickStat()),\n });\n });\n\n // TODO:脏检查,决定是否需要渲染\n });\n }\n\n private getLayerCenter(layer: ILayer) {\n const source = layer.getSource();\n return source.center;\n }\n}\n"],"file":"ShaderUniformPlugin.js"}
@@ -16,7 +16,7 @@ import { getMask, rgb2arr } from '@antv/l7-utils';
16
16
  import BaseModel from '../../core/BaseModel';
17
17
  import { PolygonExtrudeTriangulation } from '../../core/triangulation';
18
18
  var polygonExtrudeFrag = "uniform float u_opacity: 1.0;\nuniform vec4 u_sourceColor;\nuniform vec4 u_targetColor;\nuniform float u_linearColor: 0;\n\nuniform float u_topsurface: 1.0;\nuniform float u_sidesurface: 1.0;\n\nvarying vec4 v_Color;\nvarying mat4 styleMappingMat; // \u4F20\u9012\u4ECE\u7247\u5143\u4E2D\u4F20\u9012\u7684\u6620\u5C04\u6570\u636E\n#pragma include \"picking\"\n\nvoid main() {\n float opacity = styleMappingMat[0][0]; \n float isSide = styleMappingMat[0][3];\n float sidey = styleMappingMat[3][0];\n float lightWeight = styleMappingMat[3][1];\n\n if(isSide < 1.0) {\n // side face\n if(u_sidesurface < 1.0) {\n discard;\n }\n\n if(u_linearColor == 1.0) {\n vec4 linearColor = mix(u_targetColor, u_sourceColor, sidey);\n linearColor.rgb *= lightWeight;\n gl_FragColor = linearColor;\n } else {\n gl_FragColor = v_Color;\n }\n\n } else {\n // top face\n if(u_topsurface < 1.0) {\n discard;\n }\n\n gl_FragColor = v_Color;\n }\n\n gl_FragColor.a *= opacity;\n gl_FragColor = filterColor(gl_FragColor);\n}\n";
19
- var polygonExtrudeVert = "precision highp float;\n\n#define ambientRatio 0.5\n#define diffuseRatio 0.3\n#define specularRatio 0.2\n\nattribute vec4 a_Color;\nattribute vec3 a_Position;\nattribute vec3 a_Normal;\nattribute float a_Size;\nattribute vec3 a_uvs;\nuniform mat4 u_ModelMatrix;\nuniform mat4 u_Mvp;\n\nvarying vec4 v_Color;\nuniform float u_heightfixed: 0.0; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\nuniform float u_raisingHeight: 0.0;\nuniform float u_opacity: 1.0;\nvarying mat4 styleMappingMat; // \u7528\u4E8E\u5C06\u5728\u9876\u70B9\u7740\u8272\u5668\u4E2D\u8BA1\u7B97\u597D\u7684\u6837\u5F0F\u503C\u4F20\u9012\u7ED9\u7247\u5143\n\n#pragma include \"styleMapping\"\n#pragma include \"styleMappingCalOpacity\"\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nvoid main() {\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n styleMappingMat = mat4(\n 0.0, 0.0, 0.0, 0.0, // opacity - strokeOpacity - strokeWidth - isSide\n 0.0, 0.0, 0.0, 0.0, // strokeR - strokeG - strokeB - strokeA\n 0.0, 0.0, 0.0, 0.0, // offsets[0] - offsets[1]\n 0.0, 0.0, 0.0, 0.0 // sidey\n );\n styleMappingMat[0][3] = a_Position.z;\n styleMappingMat[3][0] = a_uvs[2];\n\n float rowCount = u_cellTypeLayout[0][0]; // \u5F53\u524D\u7684\u6570\u636E\u7EB9\u7406\u6709\u51E0\u884C\n float columnCount = u_cellTypeLayout[0][1]; // \u5F53\u770B\u5230\u6570\u636E\u7EB9\u7406\u6709\u51E0\u5217\n float columnWidth = 1.0/columnCount; // \u5217\u5BBD\n float rowHeight = 1.0/rowCount; // \u884C\u9AD8\n float cellCount = calCellCount(); // opacity - strokeOpacity - strokeWidth - stroke - offsets\n float id = a_vertexId; // \u7B2Cn\u4E2A\u9876\u70B9\n float cellCurrentRow = floor(id * cellCount / columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u884C\n float cellCurrentColumn = mod(id * cellCount, columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u5217\n \n // cell \u56FA\u5B9A\u987A\u5E8F opacity -> strokeOpacity -> strokeWidth -> stroke ... \n // \u6309\u987A\u5E8F\u4ECE cell \u4E2D\u53D6\u503C\u3001\u82E5\u6CA1\u6709\u5219\u81EA\u52A8\u5F80\u4E0B\u53D6\u503C\n float textureOffset = 0.0; // \u5728 cell \u4E2D\u53D6\u503C\u7684\u504F\u79FB\u91CF\n\n vec2 opacityAndOffset = calOpacityAndOffset(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset, columnWidth, rowHeight);\n styleMappingMat[0][0] = opacityAndOffset.r;\n textureOffset = opacityAndOffset.g;\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n\n if(styleMappingMat[0][3] < 1.0 ) {\n // side\n styleMappingMat[0][0] = 0.0;\n } else {\n\n }\n\n vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size, 1.0);\n vec4 project_pos = project_position(pos);\n\n if(u_heightfixed > 0.0) { // \u5224\u65AD\u51E0\u4F55\u4F53\u662F\u5426\u56FA\u5B9A\u9AD8\u5EA6\n project_pos.z = a_Position.z * a_Size;\n project_pos.z += u_raisingHeight;\n\n if(u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {\n float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);\n project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n }\n\n // project_pos.z += 500000.0; // amap1\n\n // project_pos.z += (500000.0 * 4.0)/pow(2.0, 21.0 - u_Zoom); // mapbox\n // gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x\n // gl_Position = u_Mvp * (vec4(project_pos.xyz * vec3(1.0, 1.0, -1.0), 1.0));\n gl_Position = u_Mvp * (vec4(project_pos.xyz, 1.0));\n } else {\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n }\n\n float lightWeight = calc_lighting(pos);\n // v_Color = a_Color;\n v_Color = vec4(a_Color.rgb * lightWeight, a_Color.w);\n\n styleMappingMat[3][1] = lightWeight;\n\n setPickingColor(a_PickingColor);\n}\n";
19
+ var polygonExtrudeVert = "precision highp float;\n\n#define ambientRatio 0.5\n#define diffuseRatio 0.3\n#define specularRatio 0.2\n\nattribute vec4 a_Color;\nattribute vec3 a_Position;\nattribute vec3 a_Normal;\nattribute float a_Size;\nattribute vec3 a_uvs;\nuniform mat4 u_ModelMatrix;\nuniform mat4 u_Mvp;\n\nvarying vec4 v_Color;\nuniform float u_heightfixed: 0.0; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\nuniform float u_raisingHeight: 0.0;\nuniform float u_opacity: 1.0;\nvarying mat4 styleMappingMat; // \u7528\u4E8E\u5C06\u5728\u9876\u70B9\u7740\u8272\u5668\u4E2D\u8BA1\u7B97\u597D\u7684\u6837\u5F0F\u503C\u4F20\u9012\u7ED9\u7247\u5143\n\n#pragma include \"styleMapping\"\n#pragma include \"styleMappingCalOpacity\"\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nvoid main() {\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n styleMappingMat = mat4(\n 0.0, 0.0, 0.0, 0.0, // opacity - strokeOpacity - strokeWidth - isSide\n 0.0, 0.0, 0.0, 0.0, // strokeR - strokeG - strokeB - strokeA\n 0.0, 0.0, 0.0, 0.0, // offsets[0] - offsets[1]\n 0.0, 0.0, 0.0, 0.0 // sidey\n );\n styleMappingMat[0][3] = a_Position.z;\n styleMappingMat[3][0] = a_uvs[2];\n\n float rowCount = u_cellTypeLayout[0][0]; // \u5F53\u524D\u7684\u6570\u636E\u7EB9\u7406\u6709\u51E0\u884C\n float columnCount = u_cellTypeLayout[0][1]; // \u5F53\u770B\u5230\u6570\u636E\u7EB9\u7406\u6709\u51E0\u5217\n float columnWidth = 1.0/columnCount; // \u5217\u5BBD\n float rowHeight = 1.0/rowCount; // \u884C\u9AD8\n float cellCount = calCellCount(); // opacity - strokeOpacity - strokeWidth - stroke - offsets\n float id = a_vertexId; // \u7B2Cn\u4E2A\u9876\u70B9\n float cellCurrentRow = floor(id * cellCount / columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u884C\n float cellCurrentColumn = mod(id * cellCount, columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u5217\n \n // cell \u56FA\u5B9A\u987A\u5E8F opacity -> strokeOpacity -> strokeWidth -> stroke ... \n // \u6309\u987A\u5E8F\u4ECE cell \u4E2D\u53D6\u503C\u3001\u82E5\u6CA1\u6709\u5219\u81EA\u52A8\u5F80\u4E0B\u53D6\u503C\n float textureOffset = 0.0; // \u5728 cell \u4E2D\u53D6\u503C\u7684\u504F\u79FB\u91CF\n\n vec2 opacityAndOffset = calOpacityAndOffset(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset, columnWidth, rowHeight);\n styleMappingMat[0][0] = opacityAndOffset.r;\n textureOffset = opacityAndOffset.g;\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n\n vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size, 1.0);\n vec4 project_pos = project_position(pos);\n\n if(u_heightfixed > 0.0) { // \u5224\u65AD\u51E0\u4F55\u4F53\u662F\u5426\u56FA\u5B9A\u9AD8\u5EA6\n project_pos.z = a_Position.z * a_Size;\n project_pos.z += u_raisingHeight;\n\n if(u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {\n float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);\n project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n }\n\n // project_pos.z += 500000.0; // amap1\n\n // project_pos.z += (500000.0 * 4.0)/pow(2.0, 21.0 - u_Zoom); // mapbox\n // gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x\n // gl_Position = u_Mvp * (vec4(project_pos.xyz * vec3(1.0, 1.0, -1.0), 1.0));\n gl_Position = u_Mvp * (vec4(project_pos.xyz, 1.0));\n } else {\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n }\n\n float lightWeight = calc_lighting(pos);\n // v_Color = a_Color;\n v_Color = vec4(a_Color.rgb * lightWeight, a_Color.w);\n\n styleMappingMat[3][1] = lightWeight;\n\n setPickingColor(a_PickingColor);\n}\n";
20
20
  var polygonExtrudeTexFrag = "uniform sampler2D u_texture;\nuniform float u_opacity: 1.0;\nuniform vec4 u_sourceColor;\nuniform vec4 u_targetColor;\nuniform float u_linearColor: 0;\n\nuniform float u_topsurface: 1.0;\nuniform float u_sidesurface: 1.0;\n\nvarying vec4 v_Color;\nvarying mat4 styleMappingMat; // \u4F20\u9012\u4ECE\u7247\u5143\u4E2D\u4F20\u9012\u7684\u6620\u5C04\u6570\u636E\n#pragma include \"picking\"\n\nvoid main() {\n float opacity = styleMappingMat[0][0];\n float isSide = styleMappingMat[0][3];\n float lightWeight = styleMappingMat[3][1];\n float topU = styleMappingMat[2][2];\n float topV = styleMappingMat[2][3];\n\n float sidey = styleMappingMat[3][0];\n if(isSide < 1.0) {\n // side face\n if(u_sidesurface < 1.0) {\n discard;\n }\n\n if(u_linearColor == 1.0) {\n vec4 linearColor = mix(u_targetColor, u_sourceColor, sidey);\n linearColor.rgb *= lightWeight;\n gl_FragColor = linearColor;\n } else {\n gl_FragColor = v_Color;\n }\n } else {\n\n // top face\n if(u_topsurface < 1.0) {\n discard;\n }\n\n gl_FragColor = texture2D(u_texture, vec2(topU, topV));\n }\n \n\n gl_FragColor.a *= opacity;\n gl_FragColor = filterColor(gl_FragColor);\n}\n";
21
21
  var polygonExtrudeTexVert = "precision highp float;\n\n#define ambientRatio 0.5\n#define diffuseRatio 0.3\n#define specularRatio 0.2\n\nattribute vec4 a_Color;\nattribute vec3 a_Position;\nattribute vec3 a_Normal;\nattribute float a_Size;\nattribute vec3 a_uvs;\nuniform mat4 u_ModelMatrix;\nuniform mat4 u_Mvp;\n\nvarying vec4 v_Color;\nuniform float u_heightfixed: 0.0; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\nuniform float u_raisingHeight: 0.0;\nuniform float u_opacity: 1.0;\nvarying mat4 styleMappingMat; // \u7528\u4E8E\u5C06\u5728\u9876\u70B9\u7740\u8272\u5668\u4E2D\u8BA1\u7B97\u597D\u7684\u6837\u5F0F\u503C\u4F20\u9012\u7ED9\u7247\u5143\n\n#pragma include \"styleMapping\"\n#pragma include \"styleMappingCalOpacity\"\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nvoid main() {\n v_Color = a_Color;\n\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n styleMappingMat = mat4(\n 0.0, 0.0, 0.0, 0.0, // opacity - strokeOpacity - strokeWidth - a_Position.z(judge side by a_Position.z)\n 0.0, 0.0, 0.0, 0.0, // strokeR - strokeG - strokeB - strokeA\n 0.0, 0.0, 0.0, 0.0, // offsets[0] - offsets[1] - u - v\n 0.0, 0.0, 0.0, 0.0 // sidey\n );\n \n styleMappingMat[0][3] = a_Position.z;\n styleMappingMat[2][2] = a_uvs[0];\n styleMappingMat[2][3] = 1.0 - a_uvs[1];\n styleMappingMat[3][0] = a_uvs[2];\n\n\n float rowCount = u_cellTypeLayout[0][0]; // \u5F53\u524D\u7684\u6570\u636E\u7EB9\u7406\u6709\u51E0\u884C\n float columnCount = u_cellTypeLayout[0][1]; // \u5F53\u770B\u5230\u6570\u636E\u7EB9\u7406\u6709\u51E0\u5217\n float columnWidth = 1.0/columnCount; // \u5217\u5BBD\n float rowHeight = 1.0/rowCount; // \u884C\u9AD8\n float cellCount = calCellCount(); // opacity - strokeOpacity - strokeWidth - stroke - offsets\n float id = a_vertexId; // \u7B2Cn\u4E2A\u9876\u70B9\n float cellCurrentRow = floor(id * cellCount / columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u884C\n float cellCurrentColumn = mod(id * cellCount, columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u5217\n \n // cell \u56FA\u5B9A\u987A\u5E8F opacity -> strokeOpacity -> strokeWidth -> stroke ... \n // \u6309\u987A\u5E8F\u4ECE cell \u4E2D\u53D6\u503C\u3001\u82E5\u6CA1\u6709\u5219\u81EA\u52A8\u5F80\u4E0B\u53D6\u503C\n float textureOffset = 0.0; // \u5728 cell \u4E2D\u53D6\u503C\u7684\u504F\u79FB\u91CF\n\n vec2 opacityAndOffset = calOpacityAndOffset(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset, columnWidth, rowHeight);\n styleMappingMat[0][0] = opacityAndOffset.r;\n textureOffset = opacityAndOffset.g;\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n\n vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size, 1.0);\n vec4 project_pos = project_position(pos);\n\n if(u_heightfixed > 0.0) { // \u5224\u65AD\u51E0\u4F55\u4F53\u662F\u5426\u56FA\u5B9A\u9AD8\u5EA6\n project_pos.z = a_Position.z * a_Size;\n project_pos.z += u_raisingHeight;\n\n if(u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {\n float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);\n project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n }\n\n // project_pos.z += 500000.0; // amap1\n\n // project_pos.z += (500000.0 * 4.0)/pow(2.0, 21.0 - u_Zoom); // mapbox\n // gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x\n // gl_Position = u_Mvp * (vec4(project_pos.xyz * vec3(1.0, 1.0, -1.0), 1.0));\n gl_Position = u_Mvp * (vec4(project_pos.xyz, 1.0));\n } else {\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n }\n\n float lightWeight = calc_lighting(pos);\n styleMappingMat[3][1] = lightWeight;\n\n setPickingColor(a_PickingColor);\n}\n";
22
22
  var polygonExtrudePickLightFrag = "uniform float u_opacity: 1.0;\nuniform vec4 u_sourceColor;\nuniform vec4 u_targetColor;\nuniform float u_linearColor: 0;\n\nuniform float u_topsurface: 1.0;\nuniform float u_sidesurface: 1.0;\n\nvarying vec4 v_Color;\nvarying mat4 styleMappingMat; // \u4F20\u9012\u4ECE\u7247\u5143\u4E2D\u4F20\u9012\u7684\u6620\u5C04\u6570\u636E\n#pragma include \"picking\"\n\nvoid main() {\n float opacity = styleMappingMat[0][0];\n float isSide = styleMappingMat[0][3];\n float sidey = styleMappingMat[3][0];\n float lightWeight = styleMappingMat[3][1];\n\n if(isSide < 1.0) {\n // side face\n if(u_sidesurface < 1.0) {\n discard;\n }\n \n if( u_linearColor == 1.0) {\n // side use linear\n vec4 linearColor = mix(u_targetColor, u_sourceColor, sidey);\n linearColor.rgb *= lightWeight;\n gl_FragColor = linearColor;\n } else {\n // side notuse linear\n gl_FragColor = v_Color;\n }\n } else {\n // top face\n if(u_topsurface < 1.0) {\n discard;\n }\n gl_FragColor = v_Color;\n }\n\n gl_FragColor.a *= opacity;\n gl_FragColor = filterColorAlpha(gl_FragColor, lightWeight);\n}\n";
@@ -87,10 +87,10 @@ var DataMappingPlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inver
87
87
 
88
88
  if (attributesToRemapping.length) {
89
89
  if (filter !== null && filter !== void 0 && filter.needRemapping) {
90
- layer.setEncodedData(_this.mapping(attributes, filterData, undefined, bottomColor, layer));
90
+ layer.setEncodedData(_this.mapping(layer, attributes, filterData, undefined, bottomColor));
91
91
  filter.needRemapping = false;
92
92
  } else {
93
- layer.setEncodedData(_this.mapping(attributesToRemapping, filterData, layer.getEncodedData(), bottomColor, layer));
93
+ layer.setEncodedData(_this.mapping(layer, attributesToRemapping, filterData, layer.getEncodedData(), bottomColor));
94
94
  }
95
95
 
96
96
  layer.emit('remapping', null);
@@ -115,7 +115,7 @@ var DataMappingPlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inver
115
115
  });
116
116
  }
117
117
 
118
- layer.setEncodedData(this.mapping(attributes, filterData, undefined, bottomColor, layer));
118
+ layer.setEncodedData(this.mapping(layer, attributes, filterData, undefined, bottomColor));
119
119
  layer.emit('dataUpdate', null);
120
120
  }
121
121
  }, {
@@ -128,10 +128,10 @@ var DataMappingPlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inver
128
128
  }
129
129
  }, {
130
130
  key: "mapping",
131
- value: function mapping(attributes, data, predata, minimumColor, layer) {
131
+ value: function mapping(layer, attributes, data, predata, minimumColor) {
132
132
  var _this3 = this;
133
133
 
134
- var _ref3 = layer === null || layer === void 0 ? void 0 : layer.getLayerConfig(),
134
+ var _ref3 = layer.getLayerConfig(),
135
135
  _ref3$arrow = _ref3.arrow,
136
136
  arrow = _ref3$arrow === void 0 ? {
137
137
  enable: false
@@ -175,16 +175,18 @@ var DataMappingPlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inver
175
175
 
176
176
  return encodeRecord;
177
177
  });
178
- this.adjustData2Amap2Coordinates(mappedData);
178
+ this.adjustData2Amap2Coordinates(mappedData, layer);
179
179
  this.adjustData2SimpleCoordinates(mappedData);
180
180
  return mappedData;
181
181
  }
182
182
  }, {
183
183
  key: "adjustData2Amap2Coordinates",
184
- value: function adjustData2Amap2Coordinates(mappedData) {
184
+ value: function adjustData2Amap2Coordinates(mappedData, layer) {
185
185
  var _this4 = this;
186
186
 
187
187
  if (mappedData.length > 0 && this.mapService.version === _l7Maps.Version['GAODE2.x']) {
188
+ var layerCenter = this.getLayerCenter(layer);
189
+
188
190
  if (typeof mappedData[0].coordinates[0] === 'number') {
189
191
  mappedData.filter(function (d) {
190
192
  return !d.originCoordinates;
@@ -204,6 +206,12 @@ var DataMappingPlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inver
204
206
  }
205
207
  }
206
208
  }
209
+ }, {
210
+ key: "getLayerCenter",
211
+ value: function getLayerCenter(layer) {
212
+ var source = layer.getSource();
213
+ return source.center;
214
+ }
207
215
  }, {
208
216
  key: "adjustData2SimpleCoordinates",
209
217
  value: function adjustData2SimpleCoordinates(mappedData) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/DataMappingPlugin.ts"],"names":["DataMappingPlugin","TYPES","IGlobalConfigService","IMapService","IFontService","layer","styleAttributeService","hooks","init","tap","generateMaping","beforeRenderData","dataState","dataMappingNeedUpdate","beforeRender","layerModelNeedUpdate","bottomColor","getBottomColor","attributes","getLayerStyleAttributes","filter","getLayerStyleAttribute","dataArray","getSource","data","attributesToRemapping","attribute","needRemapping","filterData","scale","record","applyAttributeMapping","length","setEncodedData","mapping","undefined","getEncodedData","emit","p1","p2","dir","normalizeDir","arrowPoint","predata","minimumColor","getLayerConfig","arrow","enable","mappedData","map","i","preRecord","encodeRecord","id","_id","coordinates","forEach","values","name","c","Array","isArray","shape","fontService","getIconFontKey","coords","getArrowPoints","splice","adjustData2Amap2Coordinates","adjustData2SimpleCoordinates","mapService","version","Version","d","originCoordinates","lngLatToCoord","lngLatToCoords","SIMPLE","simpleCoordinate","unProjectCoordinates","simpleMapCoord","unproject","coord","c1","co","push","scalers","params","field","hasOwnProperty","type","mappingResult"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAcA;;AACA;;AACA;;AAEA;;;;;;;;IAIqBA,iB,WADpB,4B,UAEE,uBAAOC,cAAMC,oBAAb,C,UAGA,uBAAOD,cAAME,WAAb,C,UAGA,uBAAOF,cAAMG,YAAb,C;;;;;;;;;;WAGD,eACEC,KADF,QAKE;AAAA;;AAAA,UAFEC,qBAEF,QAFEA,qBAEF;AACAD,MAAAA,KAAK,CAACE,KAAN,CAAYC,IAAZ,CAAiBC,GAAjB,CAAqB,mBAArB,EAA0C,YAAM;AAE9C,QAAA,KAAI,CAACC,cAAL,CAAoBL,KAApB,EAA2B;AAAEC,UAAAA,qBAAqB,EAArBA;AAAF,SAA3B;AACD,OAHD;AAKAD,MAAAA,KAAK,CAACE,KAAN,CAAYI,gBAAZ,CAA6BF,GAA7B,CAAiC,mBAAjC,EAAsD,YAAM;AAC1DJ,QAAAA,KAAK,CAACO,SAAN,CAAgBC,qBAAhB,GAAwC,KAAxC;;AACA,QAAA,KAAI,CAACH,cAAL,CAAoBL,KAApB,EAA2B;AAAEC,UAAAA,qBAAqB,EAArBA;AAAF,SAA3B;;AACA,eAAO,IAAP;AACD,OAJD;AAOAD,MAAAA,KAAK,CAACE,KAAN,CAAYO,YAAZ,CAAyBL,GAAzB,CAA6B,mBAA7B,EAAkD,YAAM;AACtD,YAAIJ,KAAK,CAACU,oBAAV,EAAgC;AAC9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,sBAAA9D,SAAS,CAACG,KAAV,wEAAiB6D,IAAjB,MAA0B,UAF5B,EAGE;AAEAH,UAAAA,MAAM,CAACF,IAAP,CAAYvD,MAAM,CAAC0D,KAAD,CAAlB;AACD;AACF,OARD;AAYA,UAAMG,aAAa,GAAGjE,SAAS,CAACQ,OAAV,GAAoBR,SAAS,CAACQ,OAAV,CAAkBqD,MAAlB,CAApB,GAAgD,EAAtE;;AACA,UAAI7D,SAAS,CAACgC,IAAV,KAAmB,OAAnB,IAA8B,CAAC,sBAAQiC,aAAa,CAAC,CAAD,CAArB,CAAnC,EAA8D;AAC5D,eAAO,CAAC/C,YAAD,CAAP;AACD;;AACD,aAAO+C,aAAP;AAED","sourcesContent":["import {\n IEncodeFeature,\n IFontService,\n IGlobalConfigService,\n ILayer,\n ILayerPlugin,\n ILngLat,\n IMapService,\n IParseDataItem,\n IStyleAttribute,\n IStyleAttributeService,\n Position,\n TYPES,\n} from '@antv/l7-core';\nimport { Version } from '@antv/l7-maps';\nimport { isColor, normalize, rgb2arr, unProjectFlat } from '@antv/l7-utils';\nimport { inject, injectable } from 'inversify';\nimport { cloneDeep } from 'lodash';\nimport 'reflect-metadata';\nimport { ILineLayerStyleOptions } from '../core/interface';\n\n@injectable()\nexport default class DataMappingPlugin implements ILayerPlugin {\n @inject(TYPES.IGlobalConfigService)\n private readonly configService: IGlobalConfigService;\n\n @inject(TYPES.IMapService)\n private readonly mapService: IMapService;\n\n @inject(TYPES.IFontService)\n private readonly fontService: IFontService;\n\n public apply(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n layer.hooks.init.tap('DataMappingPlugin', () => {\n // 初始化重新生成 map\n this.generateMaping(layer, { styleAttributeService });\n });\n\n layer.hooks.beforeRenderData.tap('DataMappingPlugin', () => {\n layer.dataState.dataMappingNeedUpdate = false;\n this.generateMaping(layer, { styleAttributeService });\n return true;\n });\n\n // remapping before render\n layer.hooks.beforeRender.tap('DataMappingPlugin', () => {\n if (layer.layerModelNeedUpdate) {\n return;\n }\n const bottomColor = layer.getBottomColor();\n const attributes = styleAttributeService.getLayerStyleAttributes() || [];\n const filter = styleAttributeService.getLayerStyleAttribute('filter');\n const { dataArray } = layer.getSource().data;\n\n const attributesToRemapping = attributes.filter(\n (attribute) => attribute.needRemapping, // 如果filter变化\n );\n let filterData = dataArray;\n\n // 数据过滤完 再执行数据映射\n if (filter?.needRemapping && filter?.scale) {\n filterData = dataArray.filter((record: IParseDataItem) => {\n return this.applyAttributeMapping(filter, record, bottomColor)[0];\n });\n }\n\n if (attributesToRemapping.length) {\n // 过滤数据\n if (filter?.needRemapping) {\n layer.setEncodedData(\n this.mapping(attributes, filterData, undefined, bottomColor, layer),\n );\n filter.needRemapping = false;\n } else {\n layer.setEncodedData(\n this.mapping(\n attributesToRemapping,\n filterData,\n layer.getEncodedData(),\n bottomColor,\n layer,\n ),\n );\n }\n // 处理文本更新\n layer.emit('remapping', null);\n }\n });\n }\n private generateMaping(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n const bottomColor = layer.getBottomColor();\n const attributes = styleAttributeService.getLayerStyleAttributes() || [];\n const filter = styleAttributeService.getLayerStyleAttribute('filter');\n const { dataArray } = layer.getSource().data;\n let filterData = dataArray;\n // 数据过滤完 再执行数据映射\n if (filter?.scale) {\n filterData = dataArray.filter((record: IParseDataItem) => {\n return this.applyAttributeMapping(filter, record, bottomColor)[0];\n });\n }\n layer.setEncodedData(\n this.mapping(attributes, filterData, undefined, bottomColor, layer),\n );\n // 对外暴露事件\n layer.emit('dataUpdate', null);\n }\n\n private getArrowPoints(p1: Position, p2: Position) {\n const dir = [p2[0] - p1[0], p2[1] - p1[1]];\n const normalizeDir = normalize(dir);\n const arrowPoint = [\n p1[0] + normalizeDir[0] * 0.0001,\n p1[1] + normalizeDir[1] * 0.0001,\n ];\n return arrowPoint;\n }\n\n private mapping(\n attributes: IStyleAttribute[],\n data: IParseDataItem[],\n predata?: IEncodeFeature[],\n minimumColor?: string,\n layer?: ILayer,\n ): IEncodeFeature[] {\n const {\n arrow = {\n enable: false,\n },\n } = layer?.getLayerConfig() as ILineLayerStyleOptions;\n const mappedData = data.map((record: IParseDataItem, i) => {\n const preRecord = predata ? predata[i] : {};\n const encodeRecord: IEncodeFeature = {\n id: record._id,\n coordinates: record.coordinates,\n ...preRecord,\n };\n attributes\n .filter((attribute) => attribute.scale !== undefined)\n .forEach((attribute: IStyleAttribute) => {\n // console.log('record', record)\n let values = this.applyAttributeMapping(\n attribute,\n record,\n minimumColor,\n );\n // console.log('values', values)\n attribute.needRemapping = false;\n\n // TODO: 支持每个属性配置 postprocess\n if (attribute.name === 'color') {\n // console.log('attribute', attribute)\n values = values.map((c: unknown) => {\n return rgb2arr(c as string);\n });\n }\n // @ts-ignore\n encodeRecord[attribute.name] =\n Array.isArray(values) && values.length === 1 ? values[0] : values;\n\n // 增加对 layer/text/iconfont unicode 映射的解析\n if (attribute.name === 'shape') {\n encodeRecord.shape = this.fontService.getIconFontKey(\n encodeRecord[attribute.name] as string,\n );\n }\n });\n\n if (encodeRecord.shape === 'line' && arrow.enable) {\n // 只有在线图层且支持配置箭头的时候进行插入顶点的处理\n const coords = encodeRecord.coordinates as Position[];\n const arrowPoint = this.getArrowPoints(coords[0], coords[1]);\n encodeRecord.coordinates.splice(1, 0, arrowPoint, arrowPoint);\n }\n return encodeRecord;\n }) as IEncodeFeature[];\n // console.log('mappedData', mappedData)\n\n // 调整数据兼容 Amap2.0\n this.adjustData2Amap2Coordinates(mappedData);\n\n // 调整数据兼容 SimpleCoordinates\n this.adjustData2SimpleCoordinates(mappedData);\n\n return mappedData;\n }\n\n private adjustData2Amap2Coordinates(mappedData: IEncodeFeature[]) {\n // 根据地图的类型判断是否需要对点位数据进行处理, 若是高德2.0则需要对坐标进行相对偏移\n if (\n mappedData.length > 0 &&\n this.mapService.version === Version['GAODE2.x']\n ) {\n if (typeof mappedData[0].coordinates[0] === 'number') {\n // 单个的点数据\n // @ts-ignore\n mappedData\n // TODO: 避免经纬度被重复计算导致坐标位置偏移\n .filter((d) => !d.originCoordinates)\n .map((d) => {\n d.version = Version['GAODE2.x'];\n // @ts-ignore\n d.originCoordinates = cloneDeep(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)\n // @ts-ignore\n d.coordinates = this.mapService.lngLatToCoord(d.coordinates);\n });\n } else {\n // 连续的线、面数据\n // @ts-ignore\n mappedData\n // TODO: 避免经纬度被重复计算导致坐标位置偏移\n .filter((d) => !d.originCoordinates)\n .map((d) => {\n d.version = Version['GAODE2.x'];\n // @ts-ignore\n d.originCoordinates = cloneDeep(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)\n // @ts-ignore\n d.coordinates = this.mapService.lngLatToCoords(d.coordinates);\n });\n }\n }\n }\n\n private adjustData2SimpleCoordinates(mappedData: IEncodeFeature[]) {\n if (mappedData.length > 0 && this.mapService.version === Version.SIMPLE) {\n mappedData.map((d) => {\n if (!d.simpleCoordinate) {\n d.coordinates = this.unProjectCoordinates(d.coordinates);\n d.simpleCoordinate = true;\n }\n });\n }\n }\n\n private unProjectCoordinates(coordinates: any) {\n if (typeof coordinates[0] === 'number') {\n return this.mapService.simpleMapCoord.unproject(\n coordinates as [number, number],\n );\n }\n\n if (coordinates[0] && coordinates[0][0] instanceof Array) {\n // @ts-ignore\n const coords = [];\n coordinates.map((coord: any) => {\n // @ts-ignore\n const c1 = [];\n coord.map((co: any) => {\n c1.push(\n this.mapService.simpleMapCoord.unproject(co as [number, number]),\n );\n });\n // @ts-ignore\n coords.push(c1);\n });\n // @ts-ignore\n return coords;\n } else {\n // @ts-ignore\n const coords = [];\n // @ts-ignore\n coordinates.map((coord) => {\n coords.push(\n this.mapService.simpleMapCoord.unproject(coord as [number, number]),\n );\n });\n // @ts-ignore\n return coords;\n }\n }\n\n private applyAttributeMapping(\n attribute: IStyleAttribute,\n record: { [key: string]: unknown },\n minimumColor?: string,\n ) {\n if (!attribute.scale) {\n return [];\n }\n const scalers = attribute?.scale?.scalers || [];\n const params: unknown[] = [];\n\n scalers.forEach(({ field }) => {\n if (\n record.hasOwnProperty(field) ||\n attribute.scale?.type === 'variable'\n ) {\n // TODO:多字段,常量\n params.push(record[field]);\n }\n });\n // console.log('params', params)\n // console.log('attribute', attribute)\n\n const mappingResult = attribute.mapping ? attribute.mapping(params) : [];\n if (attribute.name === 'color' && !isColor(mappingResult[0])) {\n return [minimumColor];\n }\n return mappingResult;\n // return attribute.mapping ? attribute.mapping(params) : [];\n }\n}\n"],"file":"DataMappingPlugin.js"}
1
+ {"version":3,"sources":["../../src/plugins/DataMappingPlugin.ts"],"names":["DataMappingPlugin","TYPES","IGlobalConfigService","IMapService","IFontService","layer","styleAttributeService","hooks","init","tap","generateMaping","beforeRenderData","dataState","dataMappingNeedUpdate","beforeRender","layerModelNeedUpdate","bottomColor","getBottomColor","attributes","getLayerStyleAttributes","filter","getLayerStyleAttribute","dataArray","getSource","data","attributesToRemapping","attribute","needRemapping","filterData","scale","record","applyAttributeMapping","length","setEncodedData","mapping","undefined","getEncodedData","emit","p1","p2","dir","normalizeDir","arrowPoint","predata","minimumColor","getLayerConfig","arrow","enable","mappedData","map","i","preRecord","encodeRecord","id","_id","coordinates","forEach","values","name","c","Array","isArray","shape","fontService","getIconFontKey","coords","getArrowPoints","splice","adjustData2Amap2Coordinates","adjustData2SimpleCoordinates","mapService","version","Version","layerCenter","getLayerCenter","d","originCoordinates","lngLatToCoord","lngLatToCoords","source","center","SIMPLE","simpleCoordinate","unProjectCoordinates","simpleMapCoord","unproject","coord","c1","co","push","scalers","params","field","hasOwnProperty","type","mappingResult"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAcA;;AACA;;AACA;;AAEA;;;;;;;;IAIqBA,iB,WADpB,4B,UAEE,uBAAOC,cAAMC,oBAAb,C,UAGA,uBAAOD,cAAME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mB,OAAnB,IAA8B,CAAC,sBAAQqC,aAAa,CAAC,CAAD,CAArB,CAAnC,EAA8D;AAC5D,eAAO,CAACnD,YAAD,CAAP;AACD;;AACD,aAAOmD,aAAP;AAED","sourcesContent":["import {\n IEncodeFeature,\n IFontService,\n IGlobalConfigService,\n ILayer,\n ILayerPlugin,\n ILngLat,\n IMapService,\n IParseDataItem,\n IStyleAttribute,\n IStyleAttributeService,\n Position,\n TYPES,\n} from '@antv/l7-core';\nimport { Version } from '@antv/l7-maps';\nimport { isColor, normalize, rgb2arr, unProjectFlat } from '@antv/l7-utils';\nimport { inject, injectable } from 'inversify';\nimport { cloneDeep } from 'lodash';\nimport 'reflect-metadata';\nimport { ILineLayerStyleOptions } from '../core/interface';\n\n@injectable()\nexport default class DataMappingPlugin implements ILayerPlugin {\n @inject(TYPES.IGlobalConfigService)\n private readonly configService: IGlobalConfigService;\n\n @inject(TYPES.IMapService)\n private readonly mapService: IMapService;\n\n @inject(TYPES.IFontService)\n private readonly fontService: IFontService;\n\n public apply(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n layer.hooks.init.tap('DataMappingPlugin', () => {\n // 初始化重新生成 map\n this.generateMaping(layer, { styleAttributeService });\n });\n\n layer.hooks.beforeRenderData.tap('DataMappingPlugin', () => {\n layer.dataState.dataMappingNeedUpdate = false;\n this.generateMaping(layer, { styleAttributeService });\n return true;\n });\n\n // remapping before render\n layer.hooks.beforeRender.tap('DataMappingPlugin', () => {\n if (layer.layerModelNeedUpdate) {\n return;\n }\n const bottomColor = layer.getBottomColor();\n const attributes = styleAttributeService.getLayerStyleAttributes() || [];\n const filter = styleAttributeService.getLayerStyleAttribute('filter');\n const { dataArray } = layer.getSource().data;\n\n const attributesToRemapping = attributes.filter(\n (attribute) => attribute.needRemapping, // 如果filter变化\n );\n let filterData = dataArray;\n\n // 数据过滤完 再执行数据映射\n if (filter?.needRemapping && filter?.scale) {\n filterData = dataArray.filter((record: IParseDataItem) => {\n return this.applyAttributeMapping(filter, record, bottomColor)[0];\n });\n }\n\n if (attributesToRemapping.length) {\n // 过滤数据\n if (filter?.needRemapping) {\n layer.setEncodedData(\n this.mapping(layer, attributes, filterData, undefined, bottomColor),\n );\n filter.needRemapping = false;\n } else {\n layer.setEncodedData(\n this.mapping(\n layer,\n attributesToRemapping,\n filterData,\n layer.getEncodedData(),\n bottomColor,\n ),\n );\n }\n // 处理文本更新\n layer.emit('remapping', null);\n }\n });\n }\n private generateMaping(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n const bottomColor = layer.getBottomColor();\n const attributes = styleAttributeService.getLayerStyleAttributes() || [];\n const filter = styleAttributeService.getLayerStyleAttribute('filter');\n const { dataArray } = layer.getSource().data;\n let filterData = dataArray;\n // 数据过滤完 再执行数据映射\n if (filter?.scale) {\n filterData = dataArray.filter((record: IParseDataItem) => {\n return this.applyAttributeMapping(filter, record, bottomColor)[0];\n });\n }\n layer.setEncodedData(\n this.mapping(layer, attributes, filterData, undefined, bottomColor),\n );\n // 对外暴露事件\n layer.emit('dataUpdate', null);\n }\n\n private getArrowPoints(p1: Position, p2: Position) {\n const dir = [p2[0] - p1[0], p2[1] - p1[1]];\n const normalizeDir = normalize(dir);\n const arrowPoint = [\n p1[0] + normalizeDir[0] * 0.0001,\n p1[1] + normalizeDir[1] * 0.0001,\n ];\n return arrowPoint;\n }\n\n private mapping(\n layer: ILayer,\n attributes: IStyleAttribute[],\n data: IParseDataItem[],\n predata?: IEncodeFeature[],\n minimumColor?: string,\n ): IEncodeFeature[] {\n const {\n arrow = {\n enable: false,\n },\n } = layer.getLayerConfig() as ILineLayerStyleOptions;\n const mappedData = data.map((record: IParseDataItem, i) => {\n const preRecord = predata ? predata[i] : {};\n const encodeRecord: IEncodeFeature = {\n id: record._id,\n coordinates: record.coordinates,\n ...preRecord,\n };\n attributes\n .filter((attribute) => attribute.scale !== undefined)\n .forEach((attribute: IStyleAttribute) => {\n // console.log('record', record)\n let values = this.applyAttributeMapping(\n attribute,\n record,\n minimumColor,\n );\n // console.log('values', values)\n attribute.needRemapping = false;\n\n // TODO: 支持每个属性配置 postprocess\n if (attribute.name === 'color') {\n // console.log('attribute', attribute)\n values = values.map((c: unknown) => {\n return rgb2arr(c as string);\n });\n }\n // @ts-ignore\n encodeRecord[attribute.name] =\n Array.isArray(values) && values.length === 1 ? values[0] : values;\n\n // 增加对 layer/text/iconfont unicode 映射的解析\n if (attribute.name === 'shape') {\n encodeRecord.shape = this.fontService.getIconFontKey(\n encodeRecord[attribute.name] as string,\n );\n }\n });\n\n if (encodeRecord.shape === 'line' && arrow.enable) {\n // 只有在线图层且支持配置箭头的时候进行插入顶点的处理\n const coords = encodeRecord.coordinates as Position[];\n const arrowPoint = this.getArrowPoints(coords[0], coords[1]);\n encodeRecord.coordinates.splice(1, 0, arrowPoint, arrowPoint);\n }\n return encodeRecord;\n }) as IEncodeFeature[];\n // console.log('mappedData', mappedData)\n\n // 调整数据兼容 Amap2.0\n this.adjustData2Amap2Coordinates(mappedData, layer);\n\n // 调整数据兼容 SimpleCoordinates\n this.adjustData2SimpleCoordinates(mappedData);\n\n return mappedData;\n }\n\n private adjustData2Amap2Coordinates(\n mappedData: IEncodeFeature[],\n layer: ILayer,\n ) {\n // 根据地图的类型判断是否需要对点位数据进行处理, 若是高德2.0则需要对坐标进行相对偏移\n if (\n mappedData.length > 0 &&\n this.mapService.version === Version['GAODE2.x']\n ) {\n const layerCenter = this.getLayerCenter(layer);\n if (typeof mappedData[0].coordinates[0] === 'number') {\n // 单个的点数据\n // @ts-ignore\n mappedData\n // TODO: 避免经纬度被重复计算导致坐标位置偏移\n .filter((d) => !d.originCoordinates)\n .map((d) => {\n d.version = Version['GAODE2.x'];\n // @ts-ignore\n d.originCoordinates = cloneDeep(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)\n // @ts-ignore\n d.coordinates = this.mapService.lngLatToCoord(d.coordinates);\n // d.coordinates = this.mapService.lngLatToCoordByLayer(\n // d.coordinates,\n // layerCenter,\n // );\n });\n } else {\n // 连续的线、面数据\n // @ts-ignore\n mappedData\n // TODO: 避免经纬度被重复计算导致坐标位置偏移\n .filter((d) => !d.originCoordinates)\n .map((d) => {\n d.version = Version['GAODE2.x'];\n // @ts-ignore\n d.originCoordinates = cloneDeep(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)\n // @ts-ignore\n d.coordinates = this.mapService.lngLatToCoords(d.coordinates);\n // d.coordinates = this.mapService.lngLatToCoordsByLayer(\n // d.coordinates,\n // layerCenter,\n // );\n });\n }\n }\n }\n\n private getLayerCenter(layer: ILayer) {\n const source = layer.getSource();\n return source.center;\n }\n\n private adjustData2SimpleCoordinates(mappedData: IEncodeFeature[]) {\n if (mappedData.length > 0 && this.mapService.version === Version.SIMPLE) {\n mappedData.map((d) => {\n if (!d.simpleCoordinate) {\n d.coordinates = this.unProjectCoordinates(d.coordinates);\n d.simpleCoordinate = true;\n }\n });\n }\n }\n\n private unProjectCoordinates(coordinates: any) {\n if (typeof coordinates[0] === 'number') {\n return this.mapService.simpleMapCoord.unproject(\n coordinates as [number, number],\n );\n }\n\n if (coordinates[0] && coordinates[0][0] instanceof Array) {\n // @ts-ignore\n const coords = [];\n coordinates.map((coord: any) => {\n // @ts-ignore\n const c1 = [];\n coord.map((co: any) => {\n c1.push(\n this.mapService.simpleMapCoord.unproject(co as [number, number]),\n );\n });\n // @ts-ignore\n coords.push(c1);\n });\n // @ts-ignore\n return coords;\n } else {\n // @ts-ignore\n const coords = [];\n // @ts-ignore\n coordinates.map((coord) => {\n coords.push(\n this.mapService.simpleMapCoord.unproject(coord as [number, number]),\n );\n });\n // @ts-ignore\n return coords;\n }\n }\n\n private applyAttributeMapping(\n attribute: IStyleAttribute,\n record: { [key: string]: unknown },\n minimumColor?: string,\n ) {\n if (!attribute.scale) {\n return [];\n }\n const scalers = attribute?.scale?.scalers || [];\n const params: unknown[] = [];\n\n scalers.forEach(({ field }) => {\n if (\n record.hasOwnProperty(field) ||\n attribute.scale?.type === 'variable'\n ) {\n // TODO:多字段,常量\n params.push(record[field]);\n }\n });\n // console.log('params', params)\n // console.log('attribute', attribute)\n\n const mappingResult = attribute.mapping ? attribute.mapping(params) : [];\n if (attribute.name === 'color' && !isColor(mappingResult[0])) {\n return [minimumColor];\n }\n return mappingResult;\n // return attribute.mapping ? attribute.mapping(params) : [];\n }\n}\n"],"file":"DataMappingPlugin.js"}
@@ -31,6 +31,8 @@ var _l7Core = require("@antv/l7-core");
31
31
 
32
32
  var _d3Array = require("d3-array");
33
33
 
34
+ var d3interpolate = _interopRequireWildcard(require("d3-interpolate"));
35
+
34
36
  var d3 = _interopRequireWildcard(require("d3-scale"));
35
37
 
36
38
  var _inversify = require("inversify");
@@ -43,8 +45,12 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
43
45
 
44
46
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
45
47
 
48
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
49
+
50
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
51
+
46
52
  var dateRegex = /^(?:(?!0000)[0-9]{4}([-/.]+)(?:(?:0?[1-9]|1[0-2])\1(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])\1(?:29|30)|(?:0?[13578]|1[02])\1(?:31))|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)([-/.]?)0?2\2(?:29))(\s+([01]|([01][0-9]|2[0-3])):([0-9]|[0-5][0-9]):([0-9]|[0-5][0-9]))?$/;
47
- var scaleMap = (_scaleMap = {}, (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.LINEAR, d3.scaleLinear), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.POWER, d3.scalePow), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.LOG, d3.scaleLog), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.IDENTITY, d3.scaleIdentity), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.TIME, d3.scaleTime), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.QUANTILE, d3.scaleQuantile), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.QUANTIZE, d3.scaleQuantize), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.THRESHOLD, d3.scaleThreshold), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.CAT, d3.scaleOrdinal), _scaleMap);
53
+ var scaleMap = (_scaleMap = {}, (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.LINEAR, d3.scaleLinear), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.POWER, d3.scalePow), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.LOG, d3.scaleLog), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.IDENTITY, d3.scaleIdentity), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.SEQUENTIAL, d3.scaleSequential), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.TIME, d3.scaleTime), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.QUANTILE, d3.scaleQuantile), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.QUANTIZE, d3.scaleQuantize), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.THRESHOLD, d3.scaleThreshold), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.CAT, d3.scaleOrdinal), (0, _defineProperty2.default)(_scaleMap, _l7Core.ScaleTypes.DIVERGING, d3.scaleDiverging), _scaleMap);
48
54
  var FeatureScalePlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inversify.inject)(_l7Core.TYPES.IGlobalConfigService), _dec(_class = (_class2 = function () {
49
55
  function FeatureScalePlugin() {
50
56
  (0, _classCallCheck2.default)(this, FeatureScalePlugin);
@@ -123,7 +129,9 @@ var FeatureScalePlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inve
123
129
  attributeScale.names = _this2.parseFields(attribute.scale.field || []);
124
130
  var scales = [];
125
131
  attributeScale.names.forEach(function (field) {
126
- scales.push(_this2.getOrCreateScale(field, attribute, dataArray));
132
+ var _attribute$scale;
133
+
134
+ scales.push(_this2.createScale(field, attribute.name, (_attribute$scale = attribute.scale) === null || _attribute$scale === void 0 ? void 0 : _attribute$scale.values, dataArray));
127
135
  });
128
136
 
129
137
  if (scales.some(function (scale) {
@@ -132,22 +140,14 @@ var FeatureScalePlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inve
132
140
  attributeScale.type = _l7Core.StyleScaleType.VARIABLE;
133
141
  scales.forEach(function (scale) {
134
142
  if (!attributeScale.callback) {
135
- var _scale$option2;
136
-
137
- if (attributeScale.values && attributeScale.values !== 'text') {
138
- var _scale$option;
139
-
140
- if (((_scale$option = scale.option) === null || _scale$option === void 0 ? void 0 : _scale$option.type) === 'linear' && attributeScale.values.length > 2) {
141
- var tick = scale.scale.ticks(attributeScale.values.length);
142
-
143
- if (type === 'color') {
144
- scale.scale.domain(tick);
145
- }
146
- }
143
+ var _scale$option, _scale$option2, _scale$option3, _scale$option4, _scale$option5;
147
144
 
145
+ if (attributeScale.values && attributeScale.values !== 'text' && ((_scale$option = scale.option) === null || _scale$option === void 0 ? void 0 : _scale$option.type) !== _l7Core.ScaleTypes.DIVERGING && ((_scale$option2 = scale.option) === null || _scale$option2 === void 0 ? void 0 : _scale$option2.type) !== _l7Core.ScaleTypes.SEQUENTIAL) {
148
146
  scale.scale.range(attributeScale.values);
149
- } else if (((_scale$option2 = scale.option) === null || _scale$option2 === void 0 ? void 0 : _scale$option2.type) === 'cat') {
147
+ } else if (((_scale$option3 = scale.option) === null || _scale$option3 === void 0 ? void 0 : _scale$option3.type) === _l7Core.ScaleTypes.CAT) {
150
148
  scale.scale.range(scale.option.domain);
149
+ } else if (((_scale$option4 = scale.option) === null || _scale$option4 === void 0 ? void 0 : _scale$option4.type) === _l7Core.ScaleTypes.DIVERGING || ((_scale$option5 = scale.option) === null || _scale$option5 === void 0 ? void 0 : _scale$option5.type) === _l7Core.ScaleTypes.SEQUENTIAL) {
150
+ scale.scale.interpolator(d3interpolate.interpolateRgbBasis(attributeScale.values));
151
151
  }
152
152
  }
153
153
  });
@@ -169,16 +169,6 @@ var FeatureScalePlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inve
169
169
  }
170
170
  });
171
171
  }
172
- }, {
173
- key: "getOrCreateScale",
174
- value: function getOrCreateScale(field, attribute, dataArray) {
175
- var _attribute$scale;
176
-
177
- var scalekey = [field, attribute.name].join('_');
178
- var values = (_attribute$scale = attribute.scale) === null || _attribute$scale === void 0 ? void 0 : _attribute$scale.values;
179
- var styleScale = this.createScale(field, attribute.name, values, dataArray);
180
- return styleScale;
181
- }
182
172
  }, {
183
173
  key: "parseFields",
184
174
  value: function parseFields(field) {
@@ -230,8 +220,7 @@ var FeatureScalePlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inve
230
220
  type = _l7Core.ScaleTypes.CAT;
231
221
  }
232
222
 
233
- var cfg = this.createDefaultScaleConfig(type, field, data);
234
- Object.assign(cfg, scaleOption);
223
+ var cfg = this.createScaleConfig(type, field, scaleOption, data);
235
224
  styleScale.scale = this.createDefaultScale(cfg);
236
225
  styleScale.option = cfg;
237
226
  }
@@ -250,8 +239,8 @@ var FeatureScalePlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inve
250
239
  return type;
251
240
  }
252
241
  }, {
253
- key: "createDefaultScaleConfig",
254
- value: function createDefaultScaleConfig(type, field, data) {
242
+ key: "createScaleConfig",
243
+ value: function createScaleConfig(type, field, scaleOption, data) {
255
244
  var cfg = {
256
245
  type: type
257
246
  };
@@ -259,27 +248,48 @@ var FeatureScalePlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inve
259
248
  return item[field];
260
249
  })) || [];
261
250
 
262
- if (type !== _l7Core.ScaleTypes.CAT && type !== _l7Core.ScaleTypes.QUANTILE) {
251
+ if (scaleOption !== null && scaleOption !== void 0 && scaleOption.domain) {
252
+ cfg.domain = scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.domain;
253
+ } else if (type !== _l7Core.ScaleTypes.CAT && type !== _l7Core.ScaleTypes.QUANTILE && type !== _l7Core.ScaleTypes.DIVERGING) {
263
254
  cfg.domain = (0, _d3Array.extent)(values);
264
255
  } else if (type === _l7Core.ScaleTypes.CAT) {
265
256
  cfg.domain = (0, _uniq2.default)(values);
266
257
  } else if (type === _l7Core.ScaleTypes.QUANTILE) {
267
258
  cfg.domain = values;
259
+ } else if (type === _l7Core.ScaleTypes.DIVERGING) {
260
+ var minMax = (0, _d3Array.extent)(values);
261
+ var neutral = (scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.neutral) !== undefined ? scaleOption === null || scaleOption === void 0 ? void 0 : scaleOption.neutral : (minMax[0] + minMax[1]) / 2;
262
+ cfg.domain = [minMax[0], neutral, minMax[1]];
268
263
  }
269
264
 
270
- return cfg;
265
+ return _objectSpread(_objectSpread({}, cfg), scaleOption);
271
266
  }
272
267
  }, {
273
268
  key: "createDefaultScale",
274
269
  value: function createDefaultScale(_ref2) {
275
270
  var type = _ref2.type,
276
- domain = _ref2.domain;
271
+ domain = _ref2.domain,
272
+ unknown = _ref2.unknown,
273
+ clamp = _ref2.clamp,
274
+ nice = _ref2.nice;
277
275
  var scale = scaleMap[type]();
278
276
 
279
- if (domain) {
277
+ if (domain && scale.domain) {
280
278
  scale.domain(domain);
281
279
  }
282
280
 
281
+ if (unknown) {
282
+ scale.unknown(unknown);
283
+ }
284
+
285
+ if (clamp !== undefined && scale.clamp) {
286
+ scale.clamp(clamp);
287
+ }
288
+
289
+ if (nice !== undefined && scale.nice) {
290
+ scale.nice(nice);
291
+ }
292
+
283
293
  return scale;
284
294
  }
285
295
  }]);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/FeatureScalePlugin.ts"],"names":["dateRegex","scaleMap","ScaleTypes","LINEAR","d3","scaleLinear","POWER","scalePow","LOG","scaleLog","IDENTITY","scaleIdentity","TIME","scaleTime","QUANTILE","scaleQuantile","QUANTIZE","scaleQuantize","THRESHOLD","scaleThreshold","CAT","scaleOrdinal","FeatureScalePlugin","TYPES","IGlobalConfigService","layer","styleAttributeService","hooks","init","tap","scaleOptions","getScaleOptions","attributes","getLayerStyleAttributes","dataArray","getSource","data","length","caculateScalesForAttributes","beforeRenderData","layerModelNeedUpdate","beforeRender","attributesToRescale","filter","attribute","needRescale","n","isNaN","parseFloat","isFinite","scaleCache","forEach","scale","attributeScale","type","name","names","parseFields","field","scales","push","getOrCreateScale","some","StyleScaleType","VARIABLE","callback","values","option","tick","ticks","domain","range","CONSTANT","defaultValues","map","index","scalers","func","scalekey","join","styleScale","createScale","Array","isArray","split","scaleOption","undefined","createDefaultScale","firstValue","find","d","isNumber","getDefaultType","cfg","createDefaultScaleConfig","Object","assign","test","item"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAeA;;AACA;;AACA;;AAEA;;;;;;;;AAEA,IAAMA,SAAS,GAAG,sTAAlB;AAEA,IAAMC,QAAQ,6DACXC,mBAAWC,MADA,EACSC,EAAE,CAACC,WADZ,4CAEXH,mBAAWI,KAFA,EAEQF,EAAE,CAACG,QAFX,4CAGXL,mBAAWM,GAHA,EAGMJ,EAAE,CAACK,QAHT,4CAIXP,mBAAWQ,QAJA,EAIWN,EAAE,CAACO,aAJd,4CAKXT,mBAAWU,IALA,EAKOR,EAAE,CAACS,SALV,4CAMXX,mBAAWY,QANA,EAMWV,EAAE,CAACW,aANd,4CAOXb,mBAAWc,QAPA,EAOWZ,EAAE,CAACa,aAPd,4CAQXf,mBAAWgB,SARA,EAQYd,EAAE,CAACe,cARf,4CASXjB,mBAAWkB,GATA,EASMhB,EAAE,CAACiB,YATT,aAAd;IAgBqBC,kB,WADpB,4B,UAEE,uBAAOC,cAAMC,oBAAb,C;;;;sDAKG,E;wDAEkC,E;;;;;WAEtC,eACEC,KADF,QAKE;AAAA;;AAAA,UAFEC,qBAEF,QAFEA,qBAEF;AACAD,MAAAA,KAAK,CAACE,KAAN,CAAYC,IAAZ,CAAiBC,GAAjB,CAAqB,oBAArB,EAA2C,YAAM;AAC/C,QAAA,KAAI,CAACC,YAAL,GAAoBL,KAAK,CAACM,eAAN,EAApB;AACA,YAAMC,UAAU,GAAGN,qBAAqB,CAACO,uBAAtB,EAAnB;AACA,YAAQC,SAAR,GAAsBT,K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N,CAAaA,MAAb;AACD;;AAED,aAAOlB,KAAP;AACD","sourcesContent":["import {\n IGlobalConfigService,\n ILayer,\n ILayerPlugin,\n IScale,\n IScaleOptions,\n IStyleAttribute,\n IStyleAttributeService,\n IStyleScale,\n ScaleTypeName,\n ScaleTypes,\n StyleScaleType,\n TYPES,\n} from '@antv/l7-core';\nimport { IParseDataItem } from '@antv/l7-source';\nimport { extent, ticks } from 'd3-array';\nimport * as d3 from 'd3-scale';\nimport { inject, injectable } from 'inversify';\nimport { isNil, isString, uniq } from 'lodash';\nimport 'reflect-metadata';\n\nconst dateRegex = /^(?:(?!0000)[0-9]{4}([-/.]+)(?:(?:0?[1-9]|1[0-2])\\1(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])\\1(?:29|30)|(?:0?[13578]|1[02])\\1(?:31))|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)([-/.]?)0?2\\2(?:29))(\\s+([01]|([01][0-9]|2[0-3])):([0-9]|[0-5][0-9]):([0-9]|[0-5][0-9]))?$/;\n\nconst scaleMap = {\n [ScaleTypes.LINEAR]: d3.scaleLinear,\n [ScaleTypes.POWER]: d3.scalePow,\n [ScaleTypes.LOG]: d3.scaleLog,\n [ScaleTypes.IDENTITY]: d3.scaleIdentity,\n [ScaleTypes.TIME]: d3.scaleTime,\n [ScaleTypes.QUANTILE]: d3.scaleQuantile,\n [ScaleTypes.QUANTIZE]: d3.scaleQuantize,\n [ScaleTypes.THRESHOLD]: d3.scaleThreshold,\n [ScaleTypes.CAT]: d3.scaleOrdinal,\n};\n\n/**\n * 根据 Source 原始数据为指定字段创建 Scale,保存在 StyleAttribute 上,供下游插件使用\n */\n@injectable()\nexport default class FeatureScalePlugin implements ILayerPlugin {\n @inject(TYPES.IGlobalConfigService)\n private readonly configService: IGlobalConfigService;\n // key = field_attribute name\n private scaleCache: {\n [field: string]: IStyleScale;\n } = {};\n\n private scaleOptions: IScaleOptions = {};\n\n public apply(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n layer.hooks.init.tap('FeatureScalePlugin', () => {\n this.scaleOptions = layer.getScaleOptions();\n const attributes = styleAttributeService.getLayerStyleAttributes();\n const { dataArray } = layer.getSource().data;\n if (dataArray.length === 0) {\n return;\n }\n this.caculateScalesForAttributes(attributes || [], dataArray);\n });\n\n // 检测数据是否需要更新\n layer.hooks.beforeRenderData.tap('FeatureScalePlugin', () => {\n this.scaleOptions = layer.getScaleOptions();\n const attributes = styleAttributeService.getLayerStyleAttributes();\n const { dataArray } = layer.getSource().data;\n this.caculateScalesForAttributes(attributes || [], dataArray);\n layer.layerModelNeedUpdate = true;\n return true;\n });\n\n layer.hooks.beforeRender.tap('FeatureScalePlugin', () => {\n if (layer.layerModelNeedUpdate) {\n return;\n }\n this.scaleOptions = layer.getScaleOptions();\n const attributes = styleAttributeService.getLayerStyleAttributes();\n if (attributes) {\n const { dataArray } = layer.getSource().data;\n if (dataArray.length === 0) {\n return;\n }\n const attributesToRescale = attributes.filter(\n (attribute) => attribute.needRescale,\n );\n if (attributesToRescale.length) {\n this.caculateScalesForAttributes(attributesToRescale, dataArray);\n }\n }\n });\n }\n private isNumber(n: any) {\n return !isNaN(parseFloat(n)) && isFinite(n);\n }\n\n private caculateScalesForAttributes(\n attributes: IStyleAttribute[],\n dataArray: IParseDataItem[],\n ) {\n this.scaleCache = {};\n attributes.forEach((attribute) => {\n if (attribute.scale) {\n // 创建Scale\n const attributeScale = attribute.scale;\n const type = attribute.name;\n attributeScale.names = this.parseFields(attribute!.scale!.field || []);\n const scales: IStyleScale[] = [];\n attributeScale.names.forEach((field: string | number) => {\n scales.push(this.getOrCreateScale(field, attribute, dataArray));\n });\n\n // 为scales 设置值区间\n if (scales.some((scale) => scale.type === StyleScaleType.VARIABLE)) {\n attributeScale.type = StyleScaleType.VARIABLE;\n scales.forEach((scale) => {\n // 如果设置了回调, 这不需要设置让range\n if (!attributeScale.callback) {\n if (attributeScale.values && attributeScale.values !== 'text') {\n if (\n scale.option?.type === 'linear' &&\n attributeScale.values.length > 2\n ) {\n const tick = scale.scale.ticks(attributeScale.values.length);\n if (type === 'color') {\n // TODO: 这里改变了值域,获取图例的时候有问题\n scale.scale.domain(tick);\n }\n }\n scale.scale.range(attributeScale.values); // 判断常量, 默认值\n } else if (scale.option?.type === 'cat') {\n // 如果没有设置初值且 类型为cat,range ==domain;\n\n scale.scale.range(scale.option.domain);\n }\n }\n });\n } else {\n // 设置attribute 常量值 常量直接在value取值\n attributeScale.type = StyleScaleType.CONSTANT;\n attributeScale.defaultValues = scales.map((scale, index) => {\n return scale.scale(attributeScale.names[index]);\n });\n }\n attributeScale.scalers = scales.map((scale: IStyleScale) => {\n return {\n field: scale.field,\n func: scale.scale,\n option: scale.option,\n };\n });\n\n attribute.needRescale = false;\n }\n });\n }\n private getOrCreateScale(\n field: string | number,\n attribute: IStyleAttribute,\n dataArray: IParseDataItem[],\n ) {\n const scalekey = [field, attribute.name].join('_');\n const values = attribute.scale?.values;\n // if (this.scaleCache[scalekey]) {\n // return this.scaleCache[scalekey];\n // }\n const styleScale = this.createScale(\n field,\n attribute.name,\n values,\n dataArray,\n );\n // this.scaleCache[scalekey] = styleScale;\n return styleScale;\n }\n\n /**\n * @example\n * 'w*h' => ['w', 'h']\n * 'w' => ['w']\n */\n private parseFields(\n field: string[] | string | number[] | number,\n ): string[] | number[] {\n if (Array.isArray(field)) {\n return field;\n }\n if (isString(field)) {\n return field.split('*');\n }\n return [field];\n }\n\n private createScale(\n field: string | number,\n name: string,\n values: unknown[] | string | undefined,\n data?: IParseDataItem[],\n ): IStyleScale {\n // scale 支持根据视觉通道和字段\n const scaleOption: IScale | undefined =\n this.scaleOptions[name] && this.scaleOptions[name]?.field === field\n ? this.scaleOptions[name]\n : this.scaleOptions[field];\n const styleScale: IStyleScale = {\n field,\n scale: undefined,\n type: StyleScaleType.VARIABLE,\n option: scaleOption,\n };\n\n if (!data || !data.length) {\n if (scaleOption && scaleOption.type) {\n styleScale.scale = this.createDefaultScale(scaleOption);\n } else {\n styleScale.scale = d3.scaleOrdinal([field]);\n styleScale.type = StyleScaleType.CONSTANT;\n }\n return styleScale;\n }\n const firstValue = data!.find((d) => !isNil(d[field]))?.[field];\n // 常量 Scale\n if (this.isNumber(field) || (isNil(firstValue) && !scaleOption)) {\n styleScale.scale = d3.scaleOrdinal([field]);\n styleScale.type = StyleScaleType.CONSTANT;\n } else {\n // 根据数据类型判断 默认等分位,时间,和枚举类型\n let type =\n (scaleOption && scaleOption.type) || this.getDefaultType(firstValue);\n if (values === 'text') {\n // text 为内置变 如果是文本则为cat\n type = ScaleTypes.CAT;\n }\n const cfg = this.createDefaultScaleConfig(type, field, data);\n Object.assign(cfg, scaleOption);\n styleScale.scale = this.createDefaultScale(cfg);\n styleScale.option = cfg;\n }\n return styleScale;\n }\n\n private getDefaultType(firstValue: unknown) {\n let type = ScaleTypes.LINEAR;\n if (typeof firstValue === 'string') {\n type = dateRegex.test(firstValue) ? ScaleTypes.TIME : ScaleTypes.CAT;\n }\n return type;\n }\n\n private createDefaultScaleConfig(\n type: ScaleTypeName,\n field: string | number,\n data?: IParseDataItem[],\n ) {\n const cfg: IScale = {\n type,\n };\n const values = data?.map((item) => item[field]) || [];\n // 默认类型为 Quantile Scales https://github.com/d3/d3-scale#quantile-scales\n if (type !== ScaleTypes.CAT && type !== ScaleTypes.QUANTILE) {\n cfg.domain = extent(values);\n } else if (type === ScaleTypes.CAT) {\n cfg.domain = uniq(values);\n } else if (type === ScaleTypes.QUANTILE) {\n cfg.domain = values;\n }\n return cfg;\n }\n\n private createDefaultScale({ type, domain }: IScale) {\n // @ts-ignore\n const scale = scaleMap[type]();\n if (domain) {\n scale.domain(domain);\n }\n // TODO 其他属性支持\n return scale;\n }\n}\n"],"file":"FeatureScalePlugin.js"}
1
+ {"version":3,"sources":["../../src/plugins/FeatureScalePlugin.ts"],"names":["dateRegex","scaleMap","ScaleTypes","LINEAR","d3","scaleLinear","POWER","scalePow","LOG","scaleLog","IDENTITY","scaleIdentity","SEQUENTIAL","scaleSequential","TIME","scaleTime","QUANTILE","scaleQuantile","QUANTIZE","scaleQuantize","THRESHOLD","scaleThreshold","CAT","scaleOrdinal","DIVERGING","scaleDiverging","FeatureScalePlugin","TYPES","IGlobalConfigService","layer","styleAttributeService","hooks","init","tap","scaleOptions","getScaleOptions","attributes","getLayerStyleAttributes","dataArray","getSource","data","length","caculateScalesForAttributes","beforeRenderData","layerModelNeedUpdate","beforeRender","attributesToRescale","filter","attribute","needRescale","n","isNaN","parseFloat","isFinite","scaleCache","forEach","scale","attributeScale","type","name","names","parseFields","field","scales","push","createScale","values","some","StyleScaleType","VARIABLE","callback","option","range","domain","interpolator","d3interpolate","interpolateRgbBasis","CONSTANT","defaultValues","map","index","scalers","func","Array","isArray","split","scaleOption","styleScale","undefined","createDefaultScale","firstValue","find","d","isNumber","getDefaultType","cfg","createScaleConfig","test","item","minMax","neutral","unknown","clamp","nice"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAeA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;;;;;AAEA,IAAMA,SAAS,GAAG,sTAAlB;AAEA,IAAMC,QAAQ,6DACXC,mBAAWC,MADA,EACSC,EAAE,CAACC,WADZ,4CAEXH,mBAAWI,KAFA,EAEQF,EAAE,CAACG,QAFX,4CAGXL,mBAAWM,GAHA,EAGMJ,EAAE,CAACK,QAHT,4CAIXP,mBAAWQ,QAJA,EAIWN,EAAE,CAACO,aAJd,4CAKXT,mBAAWU,UALA,EAKaR,EAAE,CAACS,eALhB,4CAMXX,mBAAWY,IANA,EAMOV,EAAE,CAACW,SANV,4CAOXb,mBAAWc,QAPA,EAOWZ,EAAE,CAACa,aAPd,4CAQXf,mBAAWgB,QARA,EAQWd,EAAE,CAACe,aARd,4CASXjB,mBAAWkB,SATA,EASYhB,EAAE,CAACiB,cATf,4CAUXnB,mBAAWoB,GAV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AN,CAAYA,KAAZ;AACD;;AACD,UAAIC,IAAI,KAAKf,SAAT,IAAsBhC,KAAK,CAAC+C,IAAhC,EAAsC;AACpC/C,QAAAA,KAAK,CAAC+C,IAAN,CAAWA,IAAX;AACD;;AAED,aAAO/C,KAAP;AACD","sourcesContent":["import {\n IGlobalConfigService,\n ILayer,\n ILayerPlugin,\n IScale,\n IScaleOptions,\n IStyleAttribute,\n IStyleAttributeService,\n IStyleScale,\n ScaleTypeName,\n ScaleTypes,\n StyleScaleType,\n TYPES,\n} from '@antv/l7-core';\nimport { IParseDataItem } from '@antv/l7-source';\nimport { extent, ticks } from 'd3-array';\nimport * as d3interpolate from 'd3-interpolate';\nimport * as d3 from 'd3-scale';\nimport { inject, injectable } from 'inversify';\nimport { isNil, isString, uniq } from 'lodash';\nimport 'reflect-metadata';\n\nconst dateRegex = /^(?:(?!0000)[0-9]{4}([-/.]+)(?:(?:0?[1-9]|1[0-2])\\1(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])\\1(?:29|30)|(?:0?[13578]|1[02])\\1(?:31))|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)([-/.]?)0?2\\2(?:29))(\\s+([01]|([01][0-9]|2[0-3])):([0-9]|[0-5][0-9]):([0-9]|[0-5][0-9]))?$/;\n\nconst scaleMap = {\n [ScaleTypes.LINEAR]: d3.scaleLinear,\n [ScaleTypes.POWER]: d3.scalePow,\n [ScaleTypes.LOG]: d3.scaleLog,\n [ScaleTypes.IDENTITY]: d3.scaleIdentity,\n [ScaleTypes.SEQUENTIAL]: d3.scaleSequential,\n [ScaleTypes.TIME]: d3.scaleTime,\n [ScaleTypes.QUANTILE]: d3.scaleQuantile,\n [ScaleTypes.QUANTIZE]: d3.scaleQuantize,\n [ScaleTypes.THRESHOLD]: d3.scaleThreshold,\n [ScaleTypes.CAT]: d3.scaleOrdinal,\n [ScaleTypes.DIVERGING]: d3.scaleDiverging,\n};\n\n/**\n * 根据 Source 原始数据为指定字段创建 Scale,保存在 StyleAttribute 上,供下游插件使用\n */\n@injectable()\nexport default class FeatureScalePlugin implements ILayerPlugin {\n @inject(TYPES.IGlobalConfigService)\n private readonly configService: IGlobalConfigService;\n // key = field_attribute name\n private scaleCache: {\n [field: string]: IStyleScale;\n } = {};\n\n private scaleOptions: IScaleOptions = {};\n\n public apply(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n layer.hooks.init.tap('FeatureScalePlugin', () => {\n this.scaleOptions = layer.getScaleOptions();\n const attributes = styleAttributeService.getLayerStyleAttributes();\n const { dataArray } = layer.getSource().data;\n if (dataArray.length === 0) {\n return;\n }\n this.caculateScalesForAttributes(attributes || [], dataArray);\n });\n\n // 检测数据是否需要更新\n layer.hooks.beforeRenderData.tap('FeatureScalePlugin', () => {\n this.scaleOptions = layer.getScaleOptions();\n const attributes = styleAttributeService.getLayerStyleAttributes();\n const { dataArray } = layer.getSource().data;\n this.caculateScalesForAttributes(attributes || [], dataArray);\n layer.layerModelNeedUpdate = true;\n return true;\n });\n\n layer.hooks.beforeRender.tap('FeatureScalePlugin', () => {\n if (layer.layerModelNeedUpdate) {\n return;\n }\n this.scaleOptions = layer.getScaleOptions();\n const attributes = styleAttributeService.getLayerStyleAttributes();\n if (attributes) {\n const { dataArray } = layer.getSource().data;\n if (dataArray.length === 0) {\n return;\n }\n const attributesToRescale = attributes.filter(\n (attribute) => attribute.needRescale,\n );\n if (attributesToRescale.length) {\n this.caculateScalesForAttributes(attributesToRescale, dataArray);\n }\n }\n });\n }\n private isNumber(n: any) {\n return !isNaN(parseFloat(n)) && isFinite(n);\n }\n\n private caculateScalesForAttributes(\n attributes: IStyleAttribute[],\n dataArray: IParseDataItem[],\n ) {\n this.scaleCache = {};\n attributes.forEach((attribute) => {\n if (attribute.scale) {\n // 创建Scale\n const attributeScale = attribute.scale;\n const type = attribute.name;\n attributeScale.names = this.parseFields(attribute!.scale!.field || []);\n const scales: IStyleScale[] = [];\n // 为每个字段创建 Scale\n attributeScale.names.forEach((field: string | number) => {\n scales.push(\n this.createScale(\n field,\n attribute.name,\n attribute.scale?.values,\n dataArray,\n ),\n );\n });\n\n // 为scales 设置值区间 Range\n if (scales.some((scale) => scale.type === StyleScaleType.VARIABLE)) {\n attributeScale.type = StyleScaleType.VARIABLE;\n scales.forEach((scale) => {\n // 如果设置了回调, 这不需要设置range\n if (!attributeScale.callback) {\n if (\n attributeScale.values &&\n attributeScale.values !== 'text' &&\n scale.option?.type !== ScaleTypes.DIVERGING &&\n scale.option?.type !== ScaleTypes.SEQUENTIAL\n ) {\n scale.scale.range(attributeScale.values); // 判断常量, 默认值\n } else if (scale.option?.type === ScaleTypes.CAT) {\n // 如果没有设置初值且 类型为cat,range ==domain;\n scale.scale.range(scale.option.domain);\n } else if (\n scale.option?.type === ScaleTypes.DIVERGING ||\n scale.option?.type === ScaleTypes.SEQUENTIAL\n ) {\n scale.scale.interpolator(\n // @ts-ignore\n d3interpolate.interpolateRgbBasis(attributeScale.values),\n );\n }\n }\n });\n } else {\n // 设置attribute 常量值 常量直接在value取值\n attributeScale.type = StyleScaleType.CONSTANT;\n attributeScale.defaultValues = scales.map((scale, index) => {\n return scale.scale(attributeScale.names[index]);\n });\n }\n attributeScale.scalers = scales.map((scale: IStyleScale) => {\n return {\n field: scale.field,\n func: scale.scale,\n option: scale.option,\n };\n });\n\n attribute.needRescale = false;\n }\n });\n }\n\n /**\n * @example\n * 'w*h' => ['w', 'h']\n * 'w' => ['w']\n */\n private parseFields(\n field: string[] | string | number[] | number,\n ): string[] | number[] {\n if (Array.isArray(field)) {\n return field;\n }\n if (isString(field)) {\n return field.split('*');\n }\n return [field];\n }\n\n private createScale(\n field: string | number,\n name: string,\n values: unknown[] | string | undefined,\n data?: IParseDataItem[],\n ): IStyleScale {\n // scale 支持根据视觉通道和字段\n const scaleOption: IScale | undefined =\n this.scaleOptions[name] && this.scaleOptions[name]?.field === field\n ? this.scaleOptions[name] // TODO zi\n : this.scaleOptions[field];\n const styleScale: IStyleScale = {\n field,\n scale: undefined,\n type: StyleScaleType.VARIABLE,\n option: scaleOption,\n };\n\n if (!data || !data.length) {\n if (scaleOption && scaleOption.type) {\n styleScale.scale = this.createDefaultScale(scaleOption);\n } else {\n styleScale.scale = d3.scaleOrdinal([field]);\n styleScale.type = StyleScaleType.CONSTANT;\n }\n return styleScale;\n }\n const firstValue = data!.find((d) => !isNil(d[field]))?.[field];\n // 常量 Scale\n if (this.isNumber(field) || (isNil(firstValue) && !scaleOption)) {\n styleScale.scale = d3.scaleOrdinal([field]);\n styleScale.type = StyleScaleType.CONSTANT;\n } else {\n // 根据数据类型判断 默认等分位,时间,和枚举类型\n let type =\n (scaleOption && scaleOption.type) || this.getDefaultType(firstValue);\n if (values === 'text') {\n // text 为内置变 如果是文本则为cat\n type = ScaleTypes.CAT;\n }\n const cfg = this.createScaleConfig(type, field, scaleOption, data);\n\n styleScale.scale = this.createDefaultScale(cfg);\n styleScale.option = cfg;\n }\n return styleScale;\n }\n\n private getDefaultType(firstValue: unknown) {\n let type = ScaleTypes.LINEAR;\n if (typeof firstValue === 'string') {\n type = dateRegex.test(firstValue) ? ScaleTypes.TIME : ScaleTypes.CAT;\n }\n return type;\n }\n // 生成Scale 默认配置\n private createScaleConfig(\n type: ScaleTypeName,\n field: string | number,\n scaleOption: IScale | undefined,\n data?: IParseDataItem[],\n ) {\n const cfg: IScale = {\n type,\n };\n const values = data?.map((item) => item[field]) || [];\n if (scaleOption?.domain) {\n cfg.domain = scaleOption?.domain;\n }\n // 默认类型为 Quantile Scales https://github.com/d3/d3-scale#quantile-scales\n else if (\n type !== ScaleTypes.CAT &&\n type !== ScaleTypes.QUANTILE &&\n type !== ScaleTypes.DIVERGING\n ) {\n // linear/\n cfg.domain = extent(values);\n } else if (type === ScaleTypes.CAT) {\n cfg.domain = uniq(values);\n } else if (type === ScaleTypes.QUANTILE) {\n cfg.domain = values;\n } else if (type === ScaleTypes.DIVERGING) {\n const minMax = extent(values);\n const neutral =\n scaleOption?.neutral !== undefined\n ? scaleOption?.neutral\n : (minMax[0] + minMax[1]) / 2;\n cfg.domain = [minMax[0], neutral, minMax[1]];\n }\n return { ...cfg, ...scaleOption };\n }\n\n // 创建Scale 实例\n private createDefaultScale({ type, domain, unknown, clamp, nice }: IScale) {\n // @ts-ignore\n const scale = scaleMap[type]();\n if (domain && scale.domain) {\n scale.domain(domain);\n }\n if (unknown) {\n scale.unknown(unknown);\n }\n if (clamp !== undefined && scale.clamp) {\n scale.clamp(clamp);\n }\n if (nice !== undefined && scale.nice) {\n scale.nice(nice);\n }\n // TODO 其他属性支持\n return scale;\n }\n}\n"],"file":"FeatureScalePlugin.js"}
@@ -65,6 +65,12 @@ var ShaderUniformPlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inv
65
65
  });
66
66
  });
67
67
  }
68
+ }, {
69
+ key: "getLayerCenter",
70
+ value: function getLayerCenter(layer) {
71
+ var source = layer.getSource();
72
+ return source.center;
73
+ }
68
74
  }]);
69
75
  return ShaderUniformPlugin;
70
76
  }(), (_descriptor = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "cameraService", [_dec2], {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/ShaderUniformPlugin.ts"],"names":["ShaderUniformPlugin","TYPES","ICameraService","ICoordinateSystemService","IRendererService","IMapService","layer","version","mapService","mvp","sceneCenterMKT","hooks","beforeRender","tap","coordinateSystemService","refresh","map","customCoords","getMVPMatrix","getCustomCoordCenter","rendererService","getViewportSize","width","height","models","forEach","model","addUniforms","CameraUniform","ProjectionMatrix","cameraService","getProjectionMatrix","ViewMatrix","getViewMatrix","ViewProjectionMatrix","getViewProjectionMatrix","Zoom","getZoom","ZoomScale","getZoomScale","FocalDistance","getFocalDistance","CameraPosition","getCameraPosition","CoordinateUniform","CoordinateSystem","getCoordinateSystem","ViewportCenter","getViewportCenter","ViewportCenterProjection","getViewportCenterProjection","PixelsPerDegree","getPixelsPerDegree","PixelsPerDegree2","getPixelsPerDegree2","PixelsPerMeter","getPixelsPerMeter","Mvp","getModelMatrix","$window","devicePixelRatio","getLayerConfig","pickingBuffer","Number","getShaderPickStat"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AAWA;;AACA;;AACA;;;;IAUqBA,mB,WADpB,4B,UAEE,uBAAOC,cAAMC,cAAb,C,UAGA,uBAAOD,cAAME,wBAAb,C,UAGA,uBAAOF,cAAMG,gBAAb,C,UAGA,uBAAOH,cAAMI,WAAb,C;;;;;;;;;;;WAGD,eAAaC,KAAb,EAA4B;AAAA;;AAC1B,UAAMC,OAAO,GAAG,KAAKC,UAAL,CAAgBD,OAAhC;AAEA,UAAIE,GAAG,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,EAA4B,CAA5B,EAA+B,CAA/B,EAAkC,CAAlC,EAAqC,CAArC,EAAwC,CAAxC,EAA2C,CAA3C,EAA8C,CAA9C,CAAV;AACA,UAAIC,cAAc,GAAG,CAAC,CAAD,EAAI,CAAJ,CAArB;AACAJ,MAAAA,KAAK,CAACK,KAAN,CAAYC,YAAZ,CAAyBC,GAAzB,CAA6B,qBAA7B,EAAoD,YAAM;AAExD,QAAA,KAAI,CAACC,uBAAL,CAA6BC,OAA7B;;AAEA,YAAIR,OAAO,KAAK,UAAhB,EAA4B;AAE1BE,UAAAA,GAAG,GAAG,KAAI,CAACD,UAAL,CAAgBQ,GAAhB,CAAoBC,YAApB,CAAiCC,YAAjC,EAAN;AAGAR,UAAAA,cAAc,GAAG,KAAI,CAACF,UAAL,CAAgBW,oBAAhB,EAAjB;AACD;;AAED,oCAA0B,KAAI,CAACC,eAAL,CAAqBC,eAArB,EAA1B;AAAA,YAAQC,KAAR,yBAAQA,KAAR;AAAA,YAAeC,MAAf,yBAAeA,MAAf;;AACAjB,Q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,cAAnB,EArBjB,2EAsBsBC,iBAAQC,gBAtB9B,wEAwBmBtD,KAAK,CAACuD,cAAN,GAAuBC,aAAvB,IAAwC,CAxB3D,qEA0BgBC,MAAM,CAACzD,KAAK,CAAC0D,iBAAN,EAAD,CA1BtB;AA4BD,SA7BD;AAgCD,OA7CD;AA8CD","sourcesContent":["import {\n CameraUniform,\n CoordinateUniform,\n ICameraService,\n ICoordinateSystemService,\n ILayer,\n ILayerPlugin,\n IMapService,\n IRendererService,\n TYPES,\n} from '@antv/l7-core';\nimport { $window } from '@antv/l7-utils';\nimport { inject, injectable } from 'inversify';\nimport 'reflect-metadata';\n\n/**\n * 在渲染之前需要获取当前 Shader 所需 Uniform,例如:\n * 1. 从相机服务中获取 View & ProjectionMatrix,当前缩放等级等等\n * 2. 从坐标系服务中获取当前坐标系,例如是否是偏移坐标系\n * @see https://yuque.antfin-inc.com/yuqi.pyq/fgetpa/doml91\n * 3. 当前 Layer 本身的样式属性\n */\n@injectable()\nexport default class ShaderUniformPlugin implements ILayerPlugin {\n @inject(TYPES.ICameraService)\n private readonly cameraService: ICameraService;\n\n @inject(TYPES.ICoordinateSystemService)\n private readonly coordinateSystemService: ICoordinateSystemService;\n\n @inject(TYPES.IRendererService)\n private readonly rendererService: IRendererService;\n\n @inject(TYPES.IMapService)\n private readonly mapService: IMapService;\n\n public apply(layer: ILayer) {\n const version = this.mapService.version;\n\n let mvp = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; // default matrix (for gaode2.x)\n let sceneCenterMKT = [0, 0];\n layer.hooks.beforeRender.tap('ShaderUniformPlugin', () => {\n // 重新计算坐标系参数\n this.coordinateSystemService.refresh();\n\n if (version === 'GAODE2.x') {\n // @ts-ignore\n mvp = this.mapService.map.customCoords.getMVPMatrix();\n // mvp = amapCustomCoords.getMVPMatrix()\n // @ts-ignore\n sceneCenterMKT = this.mapService.getCustomCoordCenter();\n }\n\n const { width, height } = this.rendererService.getViewportSize();\n layer.models.forEach((model) => {\n model.addUniforms({\n // 相机参数,包含 VP 矩阵、缩放等级\n [CameraUniform.ProjectionMatrix]: this.cameraService.getProjectionMatrix(),\n [CameraUniform.ViewMatrix]: this.cameraService.getViewMatrix(),\n [CameraUniform.ViewProjectionMatrix]: this.cameraService.getViewProjectionMatrix(),\n [CameraUniform.Zoom]: this.cameraService.getZoom(),\n [CameraUniform.ZoomScale]: this.cameraService.getZoomScale(),\n [CameraUniform.FocalDistance]: this.cameraService.getFocalDistance(),\n [CameraUniform.CameraPosition]: this.cameraService.getCameraPosition(),\n // 坐标系参数\n [CoordinateUniform.CoordinateSystem]: this.coordinateSystemService.getCoordinateSystem(),\n [CoordinateUniform.ViewportCenter]: this.coordinateSystemService.getViewportCenter(),\n [CoordinateUniform.ViewportCenterProjection]: this.coordinateSystemService.getViewportCenterProjection(),\n [CoordinateUniform.PixelsPerDegree]: this.coordinateSystemService.getPixelsPerDegree(),\n [CoordinateUniform.PixelsPerDegree2]: this.coordinateSystemService.getPixelsPerDegree2(),\n [CoordinateUniform.PixelsPerMeter]: this.coordinateSystemService.getPixelsPerMeter(),\n // 坐标系是高德2.0的时候单独计算\n [CoordinateUniform.Mvp]: mvp,\n u_SceneCenterMKT: sceneCenterMKT,\n // 其他参数,例如视口大小、DPR 等\n u_ViewportSize: [width, height],\n u_ModelMatrix: this.cameraService.getModelMatrix(),\n u_DevicePixelRatio: $window.devicePixelRatio,\n // u_ModelMatrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],\n u_PickingBuffer: layer.getLayerConfig().pickingBuffer || 0,\n // TODO: 当前地图是否在拖动\n u_shaderPick: Number(layer.getShaderPickStat()),\n });\n });\n\n // TODO:脏检查,决定是否需要渲染\n });\n }\n}\n"],"file":"ShaderUniformPlugin.js"}
1
+ {"version":3,"sources":["../../src/plugins/ShaderUniformPlugin.ts"],"names":["ShaderUniformPlugin","TYPES","ICameraService","ICoordinateSystemService","IRendererService","IMapService","layer","version","mapService","mvp","sceneCenterMKT","hooks","beforeRender","tap","coordinateSystemService","refresh","map","customCoords","getMVPMatrix","getCustomCoordCenter","rendererService","getViewportSize","width","height","models","forEach","model","addUniforms","CameraUniform","ProjectionMatrix","cameraService","getProjectionMatrix","ViewMatrix","getViewMatrix","ViewProjectionMatrix","getViewProjectionMatrix","Zoom","getZoom","ZoomScale","getZoomScale","FocalDistance","getFocalDistance","CameraPosition","getCameraPosition","CoordinateUniform","CoordinateSystem","getCoordinateSystem","ViewportCenter","getViewportCenter","ViewportCenterProjection","getViewportCenterProjection","PixelsPerDegree","getPixelsPerDegree","PixelsPerDegree2","getPixelsPerDegree2","PixelsPerMeter","getPixelsPerMeter","Mvp","getModelMatrix","$window","devicePixelRatio","getLayerConfig","pickingBuffer","Number","getShaderPickStat","source","getSource","center"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AAWA;;AACA;;AACA;;;;IAUqBA,mB,WADpB,4B,UAEE,uBAAOC,cAAMC,cAAb,C,UAGA,uBAAOD,cAAME,wBAAb,C,UAGA,uBAAOF,cAAMG,gBAAb,C,UAGA,uBAAOH,cAAMI,WAAb,C;;;;;;;;;;;WAGD,eAAaC,KAAb,EAA4B;AAAA;;AAC1B,UAAMC,OAAO,GAAG,KAAKC,UAAL,CAAgBD,OAAhC;AAEA,UAAIE,GAAG,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,EAA4B,CAA5B,EAA+B,CAA/B,EAAkC,CAAlC,EAAqC,CAArC,EAAwC,CAAxC,EAA2C,CAA3C,EAA8C,CAA9C,CAAV;AACA,UAAIC,cAAc,GAAG,CAAC,CAAD,EAAI,CAAJ,CAArB;AACAJ,MAAAA,KAAK,CAACK,KAAN,CAAYC,YAAZ,CAAyBC,GAAzB,CAA6B,qBAA7B,EAAoD,YAAM;AAExD,QAAA,KAAI,C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N,0BAAkBO,eAbrB,EAauC,KAAI,CAACrC,uBAAL,CAA6BsC,kBAA7B,EAbvC,qDAcGR,0BAAkBS,gBAdrB,EAcwC,KAAI,CAACvC,uBAAL,CAA6BwC,mBAA7B,EAdxC,qDAeGV,0BAAkBW,cAfrB,EAesC,KAAI,CAACzC,uBAAL,CAA6B0C,iBAA7B,EAftC,qDAiBGZ,0BAAkBa,GAjBrB,EAiB2BhD,GAjB3B,yEAkBoBC,cAlBpB,uEAoBkB,CAACY,KAAD,EAAQC,MAAR,CApBlB,sEAqBiB,KAAI,CAACO,aAAL,CAAmB4B,cAAnB,EArBjB,2EAsBsBC,iBAAQC,gBAtB9B,wEAwBmBtD,KAAK,CAACuD,cAAN,GAAuBC,aAAvB,IAAwC,CAxB3D,qEA0BgBC,MAAM,CAACzD,KAAK,CAAC0D,iBAAN,EAAD,CA1BtB;AA4BD,SA7BD;AAgCD,OAlDD;AAmDD;;;WAED,wBAAuB1D,KAAvB,EAAsC;AACpC,UAAM2D,MAAM,GAAG3D,KAAK,CAAC4D,SAAN,EAAf;AACA,aAAOD,MAAM,CAACE,MAAd;AACD","sourcesContent":["import {\n CameraUniform,\n CoordinateUniform,\n ICameraService,\n ICoordinateSystemService,\n ILayer,\n ILayerPlugin,\n IMapService,\n IRendererService,\n TYPES,\n} from '@antv/l7-core';\nimport { $window } from '@antv/l7-utils';\nimport { inject, injectable } from 'inversify';\nimport 'reflect-metadata';\n\n/**\n * 在渲染之前需要获取当前 Shader 所需 Uniform,例如:\n * 1. 从相机服务中获取 View & ProjectionMatrix,当前缩放等级等等\n * 2. 从坐标系服务中获取当前坐标系,例如是否是偏移坐标系\n * @see https://yuque.antfin-inc.com/yuqi.pyq/fgetpa/doml91\n * 3. 当前 Layer 本身的样式属性\n */\n@injectable()\nexport default class ShaderUniformPlugin implements ILayerPlugin {\n @inject(TYPES.ICameraService)\n private readonly cameraService: ICameraService;\n\n @inject(TYPES.ICoordinateSystemService)\n private readonly coordinateSystemService: ICoordinateSystemService;\n\n @inject(TYPES.IRendererService)\n private readonly rendererService: IRendererService;\n\n @inject(TYPES.IMapService)\n private readonly mapService: IMapService;\n\n public apply(layer: ILayer) {\n const version = this.mapService.version;\n\n let mvp = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; // default matrix (for gaode2.x)\n let sceneCenterMKT = [0, 0];\n layer.hooks.beforeRender.tap('ShaderUniformPlugin', () => {\n // 重新计算坐标系参数\n this.coordinateSystemService.refresh();\n\n if (version === 'GAODE2.x') {\n // const layerCenter = this.getLayerCenter(layer);\n // // @ts-ignore\n // this.mapService.map.customCoords.setCenter(layerCenter);\n // // @ts-ignore\n // this.mapService.setCustomCoordCenter(layerCenter);\n // @ts-ignore\n mvp = this.mapService.map.customCoords.getMVPMatrix();\n // mvp = amapCustomCoords.getMVPMatrix()\n // @ts-ignore\n sceneCenterMKT = this.mapService.getCustomCoordCenter();\n }\n\n const { width, height } = this.rendererService.getViewportSize();\n layer.models.forEach((model) => {\n model.addUniforms({\n // 相机参数,包含 VP 矩阵、缩放等级\n [CameraUniform.ProjectionMatrix]: this.cameraService.getProjectionMatrix(),\n [CameraUniform.ViewMatrix]: this.cameraService.getViewMatrix(),\n [CameraUniform.ViewProjectionMatrix]: this.cameraService.getViewProjectionMatrix(),\n [CameraUniform.Zoom]: this.cameraService.getZoom(),\n [CameraUniform.ZoomScale]: this.cameraService.getZoomScale(),\n [CameraUniform.FocalDistance]: this.cameraService.getFocalDistance(),\n [CameraUniform.CameraPosition]: this.cameraService.getCameraPosition(),\n // 坐标系参数\n [CoordinateUniform.CoordinateSystem]: this.coordinateSystemService.getCoordinateSystem(),\n [CoordinateUniform.ViewportCenter]: this.coordinateSystemService.getViewportCenter(),\n [CoordinateUniform.ViewportCenterProjection]: this.coordinateSystemService.getViewportCenterProjection(),\n [CoordinateUniform.PixelsPerDegree]: this.coordinateSystemService.getPixelsPerDegree(),\n [CoordinateUniform.PixelsPerDegree2]: this.coordinateSystemService.getPixelsPerDegree2(),\n [CoordinateUniform.PixelsPerMeter]: this.coordinateSystemService.getPixelsPerMeter(),\n // 坐标系是高德2.0的时候单独计算\n [CoordinateUniform.Mvp]: mvp,\n u_SceneCenterMKT: sceneCenterMKT,\n // 其他参数,例如视口大小、DPR 等\n u_ViewportSize: [width, height],\n u_ModelMatrix: this.cameraService.getModelMatrix(),\n u_DevicePixelRatio: $window.devicePixelRatio,\n // u_ModelMatrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],\n u_PickingBuffer: layer.getLayerConfig().pickingBuffer || 0,\n // TODO: 当前地图是否在拖动\n u_shaderPick: Number(layer.getShaderPickStat()),\n });\n });\n\n // TODO:脏检查,决定是否需要渲染\n });\n }\n\n private getLayerCenter(layer: ILayer) {\n const source = layer.getSource();\n return source.center;\n }\n}\n"],"file":"ShaderUniformPlugin.js"}
@@ -36,7 +36,7 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
36
36
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
37
37
 
38
38
  var polygonExtrudeFrag = "uniform float u_opacity: 1.0;\nuniform vec4 u_sourceColor;\nuniform vec4 u_targetColor;\nuniform float u_linearColor: 0;\n\nuniform float u_topsurface: 1.0;\nuniform float u_sidesurface: 1.0;\n\nvarying vec4 v_Color;\nvarying mat4 styleMappingMat; // \u4F20\u9012\u4ECE\u7247\u5143\u4E2D\u4F20\u9012\u7684\u6620\u5C04\u6570\u636E\n#pragma include \"picking\"\n\nvoid main() {\n float opacity = styleMappingMat[0][0]; \n float isSide = styleMappingMat[0][3];\n float sidey = styleMappingMat[3][0];\n float lightWeight = styleMappingMat[3][1];\n\n if(isSide < 1.0) {\n // side face\n if(u_sidesurface < 1.0) {\n discard;\n }\n\n if(u_linearColor == 1.0) {\n vec4 linearColor = mix(u_targetColor, u_sourceColor, sidey);\n linearColor.rgb *= lightWeight;\n gl_FragColor = linearColor;\n } else {\n gl_FragColor = v_Color;\n }\n\n } else {\n // top face\n if(u_topsurface < 1.0) {\n discard;\n }\n\n gl_FragColor = v_Color;\n }\n\n gl_FragColor.a *= opacity;\n gl_FragColor = filterColor(gl_FragColor);\n}\n";
39
- var polygonExtrudeVert = "precision highp float;\n\n#define ambientRatio 0.5\n#define diffuseRatio 0.3\n#define specularRatio 0.2\n\nattribute vec4 a_Color;\nattribute vec3 a_Position;\nattribute vec3 a_Normal;\nattribute float a_Size;\nattribute vec3 a_uvs;\nuniform mat4 u_ModelMatrix;\nuniform mat4 u_Mvp;\n\nvarying vec4 v_Color;\nuniform float u_heightfixed: 0.0; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\nuniform float u_raisingHeight: 0.0;\nuniform float u_opacity: 1.0;\nvarying mat4 styleMappingMat; // \u7528\u4E8E\u5C06\u5728\u9876\u70B9\u7740\u8272\u5668\u4E2D\u8BA1\u7B97\u597D\u7684\u6837\u5F0F\u503C\u4F20\u9012\u7ED9\u7247\u5143\n\n#pragma include \"styleMapping\"\n#pragma include \"styleMappingCalOpacity\"\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nvoid main() {\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n styleMappingMat = mat4(\n 0.0, 0.0, 0.0, 0.0, // opacity - strokeOpacity - strokeWidth - isSide\n 0.0, 0.0, 0.0, 0.0, // strokeR - strokeG - strokeB - strokeA\n 0.0, 0.0, 0.0, 0.0, // offsets[0] - offsets[1]\n 0.0, 0.0, 0.0, 0.0 // sidey\n );\n styleMappingMat[0][3] = a_Position.z;\n styleMappingMat[3][0] = a_uvs[2];\n\n float rowCount = u_cellTypeLayout[0][0]; // \u5F53\u524D\u7684\u6570\u636E\u7EB9\u7406\u6709\u51E0\u884C\n float columnCount = u_cellTypeLayout[0][1]; // \u5F53\u770B\u5230\u6570\u636E\u7EB9\u7406\u6709\u51E0\u5217\n float columnWidth = 1.0/columnCount; // \u5217\u5BBD\n float rowHeight = 1.0/rowCount; // \u884C\u9AD8\n float cellCount = calCellCount(); // opacity - strokeOpacity - strokeWidth - stroke - offsets\n float id = a_vertexId; // \u7B2Cn\u4E2A\u9876\u70B9\n float cellCurrentRow = floor(id * cellCount / columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u884C\n float cellCurrentColumn = mod(id * cellCount, columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u5217\n \n // cell \u56FA\u5B9A\u987A\u5E8F opacity -> strokeOpacity -> strokeWidth -> stroke ... \n // \u6309\u987A\u5E8F\u4ECE cell \u4E2D\u53D6\u503C\u3001\u82E5\u6CA1\u6709\u5219\u81EA\u52A8\u5F80\u4E0B\u53D6\u503C\n float textureOffset = 0.0; // \u5728 cell \u4E2D\u53D6\u503C\u7684\u504F\u79FB\u91CF\n\n vec2 opacityAndOffset = calOpacityAndOffset(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset, columnWidth, rowHeight);\n styleMappingMat[0][0] = opacityAndOffset.r;\n textureOffset = opacityAndOffset.g;\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n\n if(styleMappingMat[0][3] < 1.0 ) {\n // side\n styleMappingMat[0][0] = 0.0;\n } else {\n\n }\n\n vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size, 1.0);\n vec4 project_pos = project_position(pos);\n\n if(u_heightfixed > 0.0) { // \u5224\u65AD\u51E0\u4F55\u4F53\u662F\u5426\u56FA\u5B9A\u9AD8\u5EA6\n project_pos.z = a_Position.z * a_Size;\n project_pos.z += u_raisingHeight;\n\n if(u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {\n float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);\n project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n }\n\n // project_pos.z += 500000.0; // amap1\n\n // project_pos.z += (500000.0 * 4.0)/pow(2.0, 21.0 - u_Zoom); // mapbox\n // gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x\n // gl_Position = u_Mvp * (vec4(project_pos.xyz * vec3(1.0, 1.0, -1.0), 1.0));\n gl_Position = u_Mvp * (vec4(project_pos.xyz, 1.0));\n } else {\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n }\n\n float lightWeight = calc_lighting(pos);\n // v_Color = a_Color;\n v_Color = vec4(a_Color.rgb * lightWeight, a_Color.w);\n\n styleMappingMat[3][1] = lightWeight;\n\n setPickingColor(a_PickingColor);\n}\n";
39
+ var polygonExtrudeVert = "precision highp float;\n\n#define ambientRatio 0.5\n#define diffuseRatio 0.3\n#define specularRatio 0.2\n\nattribute vec4 a_Color;\nattribute vec3 a_Position;\nattribute vec3 a_Normal;\nattribute float a_Size;\nattribute vec3 a_uvs;\nuniform mat4 u_ModelMatrix;\nuniform mat4 u_Mvp;\n\nvarying vec4 v_Color;\nuniform float u_heightfixed: 0.0; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\nuniform float u_raisingHeight: 0.0;\nuniform float u_opacity: 1.0;\nvarying mat4 styleMappingMat; // \u7528\u4E8E\u5C06\u5728\u9876\u70B9\u7740\u8272\u5668\u4E2D\u8BA1\u7B97\u597D\u7684\u6837\u5F0F\u503C\u4F20\u9012\u7ED9\u7247\u5143\n\n#pragma include \"styleMapping\"\n#pragma include \"styleMappingCalOpacity\"\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nvoid main() {\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n styleMappingMat = mat4(\n 0.0, 0.0, 0.0, 0.0, // opacity - strokeOpacity - strokeWidth - isSide\n 0.0, 0.0, 0.0, 0.0, // strokeR - strokeG - strokeB - strokeA\n 0.0, 0.0, 0.0, 0.0, // offsets[0] - offsets[1]\n 0.0, 0.0, 0.0, 0.0 // sidey\n );\n styleMappingMat[0][3] = a_Position.z;\n styleMappingMat[3][0] = a_uvs[2];\n\n float rowCount = u_cellTypeLayout[0][0]; // \u5F53\u524D\u7684\u6570\u636E\u7EB9\u7406\u6709\u51E0\u884C\n float columnCount = u_cellTypeLayout[0][1]; // \u5F53\u770B\u5230\u6570\u636E\u7EB9\u7406\u6709\u51E0\u5217\n float columnWidth = 1.0/columnCount; // \u5217\u5BBD\n float rowHeight = 1.0/rowCount; // \u884C\u9AD8\n float cellCount = calCellCount(); // opacity - strokeOpacity - strokeWidth - stroke - offsets\n float id = a_vertexId; // \u7B2Cn\u4E2A\u9876\u70B9\n float cellCurrentRow = floor(id * cellCount / columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u884C\n float cellCurrentColumn = mod(id * cellCount, columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u5217\n \n // cell \u56FA\u5B9A\u987A\u5E8F opacity -> strokeOpacity -> strokeWidth -> stroke ... \n // \u6309\u987A\u5E8F\u4ECE cell \u4E2D\u53D6\u503C\u3001\u82E5\u6CA1\u6709\u5219\u81EA\u52A8\u5F80\u4E0B\u53D6\u503C\n float textureOffset = 0.0; // \u5728 cell \u4E2D\u53D6\u503C\u7684\u504F\u79FB\u91CF\n\n vec2 opacityAndOffset = calOpacityAndOffset(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset, columnWidth, rowHeight);\n styleMappingMat[0][0] = opacityAndOffset.r;\n textureOffset = opacityAndOffset.g;\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n\n vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size, 1.0);\n vec4 project_pos = project_position(pos);\n\n if(u_heightfixed > 0.0) { // \u5224\u65AD\u51E0\u4F55\u4F53\u662F\u5426\u56FA\u5B9A\u9AD8\u5EA6\n project_pos.z = a_Position.z * a_Size;\n project_pos.z += u_raisingHeight;\n\n if(u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {\n float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);\n project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n }\n\n // project_pos.z += 500000.0; // amap1\n\n // project_pos.z += (500000.0 * 4.0)/pow(2.0, 21.0 - u_Zoom); // mapbox\n // gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x\n // gl_Position = u_Mvp * (vec4(project_pos.xyz * vec3(1.0, 1.0, -1.0), 1.0));\n gl_Position = u_Mvp * (vec4(project_pos.xyz, 1.0));\n } else {\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n }\n\n float lightWeight = calc_lighting(pos);\n // v_Color = a_Color;\n v_Color = vec4(a_Color.rgb * lightWeight, a_Color.w);\n\n styleMappingMat[3][1] = lightWeight;\n\n setPickingColor(a_PickingColor);\n}\n";
40
40
  var polygonExtrudeTexFrag = "uniform sampler2D u_texture;\nuniform float u_opacity: 1.0;\nuniform vec4 u_sourceColor;\nuniform vec4 u_targetColor;\nuniform float u_linearColor: 0;\n\nuniform float u_topsurface: 1.0;\nuniform float u_sidesurface: 1.0;\n\nvarying vec4 v_Color;\nvarying mat4 styleMappingMat; // \u4F20\u9012\u4ECE\u7247\u5143\u4E2D\u4F20\u9012\u7684\u6620\u5C04\u6570\u636E\n#pragma include \"picking\"\n\nvoid main() {\n float opacity = styleMappingMat[0][0];\n float isSide = styleMappingMat[0][3];\n float lightWeight = styleMappingMat[3][1];\n float topU = styleMappingMat[2][2];\n float topV = styleMappingMat[2][3];\n\n float sidey = styleMappingMat[3][0];\n if(isSide < 1.0) {\n // side face\n if(u_sidesurface < 1.0) {\n discard;\n }\n\n if(u_linearColor == 1.0) {\n vec4 linearColor = mix(u_targetColor, u_sourceColor, sidey);\n linearColor.rgb *= lightWeight;\n gl_FragColor = linearColor;\n } else {\n gl_FragColor = v_Color;\n }\n } else {\n\n // top face\n if(u_topsurface < 1.0) {\n discard;\n }\n\n gl_FragColor = texture2D(u_texture, vec2(topU, topV));\n }\n \n\n gl_FragColor.a *= opacity;\n gl_FragColor = filterColor(gl_FragColor);\n}\n";
41
41
  var polygonExtrudeTexVert = "precision highp float;\n\n#define ambientRatio 0.5\n#define diffuseRatio 0.3\n#define specularRatio 0.2\n\nattribute vec4 a_Color;\nattribute vec3 a_Position;\nattribute vec3 a_Normal;\nattribute float a_Size;\nattribute vec3 a_uvs;\nuniform mat4 u_ModelMatrix;\nuniform mat4 u_Mvp;\n\nvarying vec4 v_Color;\nuniform float u_heightfixed: 0.0; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\nuniform float u_raisingHeight: 0.0;\nuniform float u_opacity: 1.0;\nvarying mat4 styleMappingMat; // \u7528\u4E8E\u5C06\u5728\u9876\u70B9\u7740\u8272\u5668\u4E2D\u8BA1\u7B97\u597D\u7684\u6837\u5F0F\u503C\u4F20\u9012\u7ED9\u7247\u5143\n\n#pragma include \"styleMapping\"\n#pragma include \"styleMappingCalOpacity\"\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nvoid main() {\n v_Color = a_Color;\n\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n styleMappingMat = mat4(\n 0.0, 0.0, 0.0, 0.0, // opacity - strokeOpacity - strokeWidth - a_Position.z(judge side by a_Position.z)\n 0.0, 0.0, 0.0, 0.0, // strokeR - strokeG - strokeB - strokeA\n 0.0, 0.0, 0.0, 0.0, // offsets[0] - offsets[1] - u - v\n 0.0, 0.0, 0.0, 0.0 // sidey\n );\n \n styleMappingMat[0][3] = a_Position.z;\n styleMappingMat[2][2] = a_uvs[0];\n styleMappingMat[2][3] = 1.0 - a_uvs[1];\n styleMappingMat[3][0] = a_uvs[2];\n\n\n float rowCount = u_cellTypeLayout[0][0]; // \u5F53\u524D\u7684\u6570\u636E\u7EB9\u7406\u6709\u51E0\u884C\n float columnCount = u_cellTypeLayout[0][1]; // \u5F53\u770B\u5230\u6570\u636E\u7EB9\u7406\u6709\u51E0\u5217\n float columnWidth = 1.0/columnCount; // \u5217\u5BBD\n float rowHeight = 1.0/rowCount; // \u884C\u9AD8\n float cellCount = calCellCount(); // opacity - strokeOpacity - strokeWidth - stroke - offsets\n float id = a_vertexId; // \u7B2Cn\u4E2A\u9876\u70B9\n float cellCurrentRow = floor(id * cellCount / columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u884C\n float cellCurrentColumn = mod(id * cellCount, columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u5217\n \n // cell \u56FA\u5B9A\u987A\u5E8F opacity -> strokeOpacity -> strokeWidth -> stroke ... \n // \u6309\u987A\u5E8F\u4ECE cell \u4E2D\u53D6\u503C\u3001\u82E5\u6CA1\u6709\u5219\u81EA\u52A8\u5F80\u4E0B\u53D6\u503C\n float textureOffset = 0.0; // \u5728 cell \u4E2D\u53D6\u503C\u7684\u504F\u79FB\u91CF\n\n vec2 opacityAndOffset = calOpacityAndOffset(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset, columnWidth, rowHeight);\n styleMappingMat[0][0] = opacityAndOffset.r;\n textureOffset = opacityAndOffset.g;\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n\n vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size, 1.0);\n vec4 project_pos = project_position(pos);\n\n if(u_heightfixed > 0.0) { // \u5224\u65AD\u51E0\u4F55\u4F53\u662F\u5426\u56FA\u5B9A\u9AD8\u5EA6\n project_pos.z = a_Position.z * a_Size;\n project_pos.z += u_raisingHeight;\n\n if(u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {\n float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);\n project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n }\n\n // project_pos.z += 500000.0; // amap1\n\n // project_pos.z += (500000.0 * 4.0)/pow(2.0, 21.0 - u_Zoom); // mapbox\n // gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x\n // gl_Position = u_Mvp * (vec4(project_pos.xyz * vec3(1.0, 1.0, -1.0), 1.0));\n gl_Position = u_Mvp * (vec4(project_pos.xyz, 1.0));\n } else {\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n }\n\n float lightWeight = calc_lighting(pos);\n styleMappingMat[3][1] = lightWeight;\n\n setPickingColor(a_PickingColor);\n}\n";
42
42
  var polygonExtrudePickLightFrag = "uniform float u_opacity: 1.0;\nuniform vec4 u_sourceColor;\nuniform vec4 u_targetColor;\nuniform float u_linearColor: 0;\n\nuniform float u_topsurface: 1.0;\nuniform float u_sidesurface: 1.0;\n\nvarying vec4 v_Color;\nvarying mat4 styleMappingMat; // \u4F20\u9012\u4ECE\u7247\u5143\u4E2D\u4F20\u9012\u7684\u6620\u5C04\u6570\u636E\n#pragma include \"picking\"\n\nvoid main() {\n float opacity = styleMappingMat[0][0];\n float isSide = styleMappingMat[0][3];\n float sidey = styleMappingMat[3][0];\n float lightWeight = styleMappingMat[3][1];\n\n if(isSide < 1.0) {\n // side face\n if(u_sidesurface < 1.0) {\n discard;\n }\n \n if( u_linearColor == 1.0) {\n // side use linear\n vec4 linearColor = mix(u_targetColor, u_sourceColor, sidey);\n linearColor.rgb *= lightWeight;\n gl_FragColor = linearColor;\n } else {\n // side notuse linear\n gl_FragColor = v_Color;\n }\n } else {\n // top face\n if(u_topsurface < 1.0) {\n discard;\n }\n gl_FragColor = v_Color;\n }\n\n gl_FragColor.a *= opacity;\n gl_FragColor = filterColorAlpha(gl_FragColor, lightWeight);\n}\n";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/l7-layers",
3
- "version": "2.8.36",
3
+ "version": "2.8.39",
4
4
  "description": "L7's collection of built-in layers",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -23,14 +23,15 @@
23
23
  "author": "xiaoiver",
24
24
  "license": "ISC",
25
25
  "dependencies": {
26
- "@antv/l7-core": "^2.8.36",
27
- "@antv/l7-source": "^2.8.36",
28
- "@antv/l7-utils": "^2.8.36",
26
+ "@antv/l7-core": "^2.8.39",
27
+ "@antv/l7-source": "^2.8.39",
28
+ "@antv/l7-utils": "^2.8.39",
29
29
  "@babel/runtime": "^7.7.7",
30
30
  "@mapbox/martini": "^0.2.0",
31
31
  "@turf/meta": "^6.0.2",
32
32
  "d3-array": "1",
33
33
  "d3-color": "^1.4.0",
34
+ "d3-interpolate": "2",
34
35
  "d3-scale": "2",
35
36
  "earcut": "^2.2.1",
36
37
  "eventemitter3": "^4.0.0",
@@ -46,12 +47,13 @@
46
47
  "devDependencies": {
47
48
  "@types/d3-array": "^2.0.0",
48
49
  "@types/d3-color": "^1.2.2",
50
+ "@types/d3-interpolate": "2.0.2",
49
51
  "@types/d3-scale": "^2.1.1",
50
52
  "@types/earcut": "^2.1.0",
51
53
  "@types/gl-matrix": "^2.4.5",
52
54
  "@types/lodash": "^4.14.138"
53
55
  },
54
- "gitHead": "2d065929ec1c6896fc41a4d11477023cbbc01104",
56
+ "gitHead": "b6f52c65cb133ecb82c8c2d984532cb2fbf89a84",
55
57
  "publishConfig": {
56
58
  "access": "public"
57
59
  }