Skip to content

Commit cdb0ebc

Browse files
committed
feat(geo): support styling region in original GeoJSON data
1 parent 2009644 commit cdb0ebc

File tree

3 files changed

+482
-428
lines changed

3 files changed

+482
-428
lines changed

src/component/helper/MapDraw.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,14 @@ class MapDraw {
302302
? mapOrGeoModel.getRegionModel(regionName)
303303
: (data ? data.getItemModel(dataIdx) as Model<MapDataItemOption> : null);
304304

305+
// allow specified itemStyle in GeoJSON data
306+
const regionItemStyle = region.properties && region.properties.itemStyle;
307+
if (regionItemStyle) {
308+
const regionModelOption = regionModel.option;
309+
const modelItemStyle = regionModelOption.itemStyle || (regionModelOption.itemStyle = {});
310+
modelItemStyle && zrUtil.defaults(modelItemStyle, regionItemStyle);
311+
}
312+
305313
regionsInfoByName.set(regionName, { dataIdx, regionModel });
306314
}
307315

src/coord/geo/Region.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ import * as vec2 from 'zrender/src/core/vector';
2323
import * as polygonContain from 'zrender/src/contain/polygon';
2424
import { GeoJSON, GeoProjection, GeoSVGGraphicRoot } from './geoTypes';
2525
import * as matrix from 'zrender/src/core/matrix';
26-
import Element from 'zrender/src/Element';
26+
import type Element from 'zrender/src/Element';
2727
import { each } from 'zrender/src/core/util';
28+
import type { GeoItemStyleOption } from './GeoModel';
2829

2930
const TMP_TRANSFORM = [] as number[];
3031

@@ -135,7 +136,9 @@ export class GeoJSONRegion extends Region {
135136
readonly geometries: (GeoJSONPolygonGeometry | GeoJSONLineStringGeometry)[];
136137

137138
// Injected outside.
138-
properties: GeoJSON['features'][0]['properties'];
139+
properties: GeoJSON['features'][0]['properties'] & {
140+
itemStyle?: GeoItemStyleOption
141+
};
139142

140143
constructor(
141144
name: string,

0 commit comments

Comments
 (0)