Skip to content

Commit

Permalink
Merge 2733770 into 62eccb7
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed Apr 26, 2022
2 parents 62eccb7 + 2733770 commit a967780
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 27 deletions.
3 changes: 2 additions & 1 deletion packages/l7plot/src/plots/choropleth/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const CHINA_BOUNDARY_STYLE = {
color: 'red',
width: 1,
opacity: 0.8,
dashArray: [1, 6],
dashArray: [2, 4],
},
// 海洋
coast: {
Expand All @@ -65,5 +65,6 @@ export const CHINA_BOUNDARY_STYLE = {
color: 'gray',
width: 0.7,
opacity: 0.8,
dashArray: [2, 4],
},
};
37 changes: 19 additions & 18 deletions packages/l7plot/src/plots/choropleth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export class Choropleth extends Plot<ChoroplethOptions> {
* 国界图层
*/
public chinaBoundaryLayer: PathLayer | undefined;
/**
* 港澳界图层
*/
public chinaHkmBoundaryLayer: PathLayer | undefined;
/**
* 国界争议图层
*/
Expand Down Expand Up @@ -223,14 +227,9 @@ export class Choropleth extends Plot<ChoroplethOptions> {
const layerGroup = new LayerGroup([this.fillAreaLayer]);

if (this.options.chinaBorder) {
const { chinaBoundaryLayer, chinaDisputeBoundaryLayer } = this.createCountryBoundaryLayer(
this.chinaBoundaryData,
this.options
);
this.chinaBoundaryLayer = chinaBoundaryLayer;
this.chinaDisputeBoundaryLayer = chinaDisputeBoundaryLayer;
layerGroup.addLayer(this.chinaBoundaryLayer);
layerGroup.addLayer(this.chinaDisputeBoundaryLayer);
const layers = this.createCountryBoundaryLayer(this.chinaBoundaryData, this.options);

layers.forEach((layer) => layerGroup.addLayer(layer));
}

if (this.options.label) {
Expand All @@ -245,8 +244,14 @@ export class Choropleth extends Plot<ChoroplethOptions> {
* 创建中国国界线图层
*/
private createCountryBoundaryLayer(data: FeatureCollection, plotConfig?: ChoroplethOptions) {
const { chinaBoundaryLayer, chinaDisputeBoundaryLayer } = createCountryBoundaryLayer(data, plotConfig);
return { chinaBoundaryLayer, chinaDisputeBoundaryLayer };
const { chinaBoundaryLayer, chinaHkmBoundaryLayer, chinaDisputeBoundaryLayer } = createCountryBoundaryLayer(
data,
plotConfig
);
this.chinaBoundaryLayer = chinaBoundaryLayer;
this.chinaHkmBoundaryLayer = chinaHkmBoundaryLayer;
this.chinaDisputeBoundaryLayer = chinaDisputeBoundaryLayer;
return [chinaBoundaryLayer, chinaHkmBoundaryLayer, chinaDisputeBoundaryLayer];
}

/**
Expand Down Expand Up @@ -296,17 +301,13 @@ export class Choropleth extends Plot<ChoroplethOptions> {
this.fillAreaLayer.update(fillAreaLayerConfig);

const createCountryBoundaryLayer = () => {
const { chinaBoundaryLayer, chinaDisputeBoundaryLayer } = this.createCountryBoundaryLayer(
this.chinaBoundaryData,
this.options
);
this.chinaBoundaryLayer = chinaBoundaryLayer;
this.chinaDisputeBoundaryLayer = chinaDisputeBoundaryLayer;
this.layerGroup.addLayer(this.chinaBoundaryLayer);
this.layerGroup.addLayer(this.chinaDisputeBoundaryLayer);
const layers = this.createCountryBoundaryLayer(this.chinaBoundaryData, this.options);

layers.forEach((layer) => this.layerGroup.addLayer(layer));
};
const removeCountryBoundaryLayer = () => {
this.chinaBoundaryLayer && this.layerGroup.removeLayer(this.chinaBoundaryLayer);
this.chinaHkmBoundaryLayer && this.layerGroup.removeLayer(this.chinaHkmBoundaryLayer);
this.chinaDisputeBoundaryLayer && this.layerGroup.removeLayer(this.chinaDisputeBoundaryLayer);
};

Expand Down
23 changes: 21 additions & 2 deletions packages/l7plot/src/plots/choropleth/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ export const createCountryBoundaryLayer = (data: FeatureCollection, plotConfig?:
const borderStyle: Required<ChinaBoundaryStyle> =
typeof chinaBorder === 'object' ? deepAssign({}, CHINA_BOUNDARY_STYLE, chinaBorder) : CHINA_BOUNDARY_STYLE;
const chinaBoundaryFeatures = data.features.filter(({ properties }) =>
['coast', 'hkm', 'national'].includes(properties?.['type'])
['coast', 'national'].includes(properties?.['type'])
);
const disputeBoundaryFeatures = data.features.filter(({ properties }) => properties?.['type'] === 'dispute');
const hkmBoundaryFeatures = data.features.filter(({ properties }) => properties?.['type'] === 'hkm');

const chinaBoundaryLayer = new PathLayer({
name: 'chinaBoundaryLayer',
Expand Down Expand Up @@ -41,6 +42,24 @@ export const createCountryBoundaryLayer = (data: FeatureCollection, plotConfig?:
opacity: ['type', (type) => borderStyle[type].opacity],
},
});
const chinaHkmBoundaryLayer = new PathLayer({
name: 'chinaHkmBoundaryLayer',
visible,
minZoom,
maxZoom,
zIndex: zIndex + 0.1,
source: {
data: { type: 'FeatureCollection', features: hkmBoundaryFeatures },
parser: { type: 'geojson' },
},
color: borderStyle.hkm.color,
size: borderStyle.hkm.width,
style: {
opacity: borderStyle.hkm.opacity,
lineType: 'dash',
dashArray: borderStyle.hkm.dashArray as [number, number],
},
});
const chinaDisputeBoundaryLayer = new PathLayer({
name: 'chinaDisputeBoundaryLayer',
visible,
Expand All @@ -60,5 +79,5 @@ export const createCountryBoundaryLayer = (data: FeatureCollection, plotConfig?:
},
});

return { chinaBoundaryLayer, chinaDisputeBoundaryLayer };
return { chinaBoundaryLayer, chinaHkmBoundaryLayer, chinaDisputeBoundaryLayer };
};
12 changes: 6 additions & 6 deletions website/docs/api/plots/choropleth.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ const choropleth = new Choropleth(container, options);

是否显示中国国界线,国界线样式 ChinaBoundaryStyle 配置如下:

| 属性 | 描述 | 类型 | 默认值 | 是否必填 |
| -------- | ---- | ------------------------ | ----------------------------------------------------------- | -------- |
| national | 国界 | `LinesLayerStyleOptions` | `{ color: 'red', width: 1, opacity: 1 }` | optional |
| dispute | 争议 | `LinesLayerStyleOptions` | `{ color: 'red', width: 1, opacity: 1, dashArray: [1, 6] }` | optional |
| coast | 海洋 | `LinesLayerStyleOptions` | `{ color: 'blue', width: 1, opacity: 1 }` | optional |
| hkm | 港澳 | `LinesLayerStyleOptions` | `{ color: 'gray', width: 1, opacity: 1 }` | optional |
| 属性 | 描述 | 类型 | 默认值 | 是否必填 |
| -------- | ---- | ------------------------ | ---------------------------------------------------------------- | -------- |
| national | 国界 | `LinesLayerStyleOptions` | `{ color: 'red', width: 1, opacity: 1 }` | optional |
| dispute | 争议 | `LinesLayerStyleOptions` | `{ color: 'red', width: 1, opacity: 1, dashArray: [2, 4] }` | optional |
| coast | 海洋 | `LinesLayerStyleOptions` | `{ color: 'blue', width: 0.7, opacity: 0.8 }` | optional |
| hkm | 港澳 | `LinesLayerStyleOptions` | `{ color: 'gray', width: 0.7, opacity: 0.8, dashArray: [2, 4] }` | optional |

### `options.`drill

Expand Down

0 comments on commit a967780

Please sign in to comment.