Skip to content

Commit

Permalink
feat(geo): support styling region in original GeoJSON data
Browse files Browse the repository at this point in the history
  • Loading branch information
plainheart committed Dec 5, 2024
1 parent 2009644 commit cdb0ebc
Show file tree
Hide file tree
Showing 3 changed files with 482 additions and 428 deletions.
8 changes: 8 additions & 0 deletions src/component/helper/MapDraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ class MapDraw {
? mapOrGeoModel.getRegionModel(regionName)
: (data ? data.getItemModel(dataIdx) as Model<MapDataItemOption> : null);

// allow specified itemStyle in GeoJSON data
const regionItemStyle = region.properties && region.properties.itemStyle;
if (regionItemStyle) {
const regionModelOption = regionModel.option;
const modelItemStyle = regionModelOption.itemStyle || (regionModelOption.itemStyle = {});
modelItemStyle && zrUtil.defaults(modelItemStyle, regionItemStyle);
}

regionsInfoByName.set(regionName, { dataIdx, regionModel });
}

Expand Down
7 changes: 5 additions & 2 deletions src/coord/geo/Region.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import * as vec2 from 'zrender/src/core/vector';
import * as polygonContain from 'zrender/src/contain/polygon';
import { GeoJSON, GeoProjection, GeoSVGGraphicRoot } from './geoTypes';
import * as matrix from 'zrender/src/core/matrix';
import Element from 'zrender/src/Element';
import type Element from 'zrender/src/Element';
import { each } from 'zrender/src/core/util';
import type { GeoItemStyleOption } from './GeoModel';

const TMP_TRANSFORM = [] as number[];

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

// Injected outside.
properties: GeoJSON['features'][0]['properties'];
properties: GeoJSON['features'][0]['properties'] & {
itemStyle?: GeoItemStyleOption
};

constructor(
name: string,
Expand Down
Loading

0 comments on commit cdb0ebc

Please sign in to comment.