MCPcopy
hub / github.com/apache/echarts / _buildGeoJSON

Method _buildGeoJSON

src/component/helper/MapDraw.ts:249–397  ·  view source on GitHub ↗
(
        viewCoordSys: View,
        api: ExtensionAPI,
        geo: Geo,
        mapOrGeoModel: MapOrGeoModel,
        data: SeriesData | NullUndefined,
        isVisualEncodedByVisualMap: boolean
    )

Source from the content-addressed store, hash-verified

247 }
248
249 private _buildGeoJSON(
250 viewCoordSys: View,
251 api: ExtensionAPI,
252 geo: Geo,
253 mapOrGeoModel: MapOrGeoModel,
254 data: SeriesData | NullUndefined,
255 isVisualEncodedByVisualMap: boolean
256 ): void {
257 const regionsGroupByName = this._regionsGroupByName = zrUtil.createHashMap<RegionsGroup, string>();
258 const regionsInfoByName = zrUtil.createHashMap<{
259 dataIdx: number;
260 regionModel: Model<RegionOption> | Model<MapDataItemOption>;
261 }, string>();
262 const regionsGroup = this._regionsGroup;
263 const projection = geo.projection;
264 const projectionStream = projection && projection.stream;
265
266 const transMt = transformableGetLocalTransform(
267 viewCoordSysCopyTrans(null, viewCoordSys, VIEW_COORD_SYS_TRANS_RAW)
268 );
269
270 function transformPoint(point: number[], project: GeoProjection['project']): number[] {
271 if (project) {
272 // projection may return null point.
273 point = project(point);
274 }
275 return point && applyTransform([], point, transMt);
276 };
277
278 function transformPolygonPoints(inPoints: number[][]): number[][] {
279 const outPoints = [];
280 // If projectionStream is provided. Use it instead of single point project.
281 const project = !projectionStream && projection && projection.project;
282 for (let i = 0; i < inPoints.length; ++i) {
283 const newPt = transformPoint(inPoints[i], project);
284 newPt && outPoints.push(newPt);
285 }
286 return outPoints;
287 }
288
289 function getPolyShape(points: number[][]) {
290 return {
291 shape: {
292 points: transformPolygonPoints(points)
293 }
294 };
295 }
296
297 regionsGroup.removeAll();
298
299 // Only when the resource is GeoJSON, there is `geo.regions`.
300 zrUtil.each(geo.regions, function (region: GeoJSONRegion) {
301 const regionName = region.name;
302
303 // Consider in GeoJson properties.name may be duplicated, for example,
304 // there is multiple region named "United Kindom" or "France" (so many
305 // colonies). And it is not appropriate to merge them in geo, which
306 // will make them share the same label and bring trouble in label

Callers 1

drawMethod · 0.95

Calls 13

viewCoordSysCopyTransFunction · 0.90
isGeoModelFunction · 0.85
projectPolysFunction · 0.85
resetTooltipForRegionFunction · 0.85
getItemModelMethod · 0.80
getCenterMethod · 0.80
eachMethod · 0.45
getMethod · 0.45
addMethod · 0.45
indexOfNameMethod · 0.45

Tested by

no test coverage detected