逐步完成前后端服务器

This commit is contained in:
2025-09-09 15:00:30 +08:00
parent fcb09432e9
commit c7dfa1e9fc
2937 changed files with 1477567 additions and 0 deletions

209
frontend/node_modules/echarts/lib/coord/geo/Geo.js generated vendored Normal file
View File

@ -0,0 +1,209 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { __extends } from "tslib";
import * as zrUtil from 'zrender/lib/core/util.js';
import BoundingRect from 'zrender/lib/core/BoundingRect.js';
import View from '../View.js';
import geoSourceManager from './geoSourceManager.js';
import { SINGLE_REFERRING } from '../../util/model.js';
import { warn } from '../../util/log.js';
var GEO_DEFAULT_PARAMS = {
'geoJSON': {
aspectScale: 0.75,
invertLongitute: true
},
'geoSVG': {
aspectScale: 1,
invertLongitute: false
}
};
export var geo2DDimensions = ['lng', 'lat'];
var Geo = /** @class */function (_super) {
__extends(Geo, _super);
function Geo(name, map, opt) {
var _this = _super.call(this, name) || this;
_this.dimensions = geo2DDimensions;
_this.type = 'geo';
// Only store specified name coord via `addGeoCoord`.
_this._nameCoordMap = zrUtil.createHashMap();
_this.map = map;
var projection = opt.projection;
var source = geoSourceManager.load(map, opt.nameMap, opt.nameProperty);
var resource = geoSourceManager.getGeoResource(map);
var resourceType = _this.resourceType = resource ? resource.type : null;
var regions = _this.regions = source.regions;
var defaultParams = GEO_DEFAULT_PARAMS[resource.type];
_this._regionsMap = source.regionsMap;
_this.regions = source.regions;
if (process.env.NODE_ENV !== 'production' && projection) {
// Do some check
if (resourceType === 'geoSVG') {
if (process.env.NODE_ENV !== 'production') {
warn("Map " + map + " with SVG source can't use projection. Only GeoJSON source supports projection.");
}
projection = null;
}
if (!(projection.project && projection.unproject)) {
if (process.env.NODE_ENV !== 'production') {
warn('project and unproject must be both provided in the projeciton.');
}
projection = null;
}
}
_this.projection = projection;
var boundingRect;
if (projection) {
// Can't reuse the raw bounding rect
for (var i = 0; i < regions.length; i++) {
var regionRect = regions[i].getBoundingRect(projection);
boundingRect = boundingRect || regionRect.clone();
boundingRect.union(regionRect);
}
} else {
boundingRect = source.boundingRect;
}
_this.setBoundingRect(boundingRect.x, boundingRect.y, boundingRect.width, boundingRect.height);
// aspectScale and invertLongitute actually is the parameters default raw projection.
// So we ignore them if projection is given.
// Ignore default aspect scale if projection exits.
_this.aspectScale = projection ? 1 : zrUtil.retrieve2(opt.aspectScale, defaultParams.aspectScale);
// Not invert longitude if projection exits.
_this._invertLongitute = projection ? false : defaultParams.invertLongitute;
return _this;
}
Geo.prototype._transformTo = function (x, y, width, height) {
var rect = this.getBoundingRect();
var invertLongitute = this._invertLongitute;
rect = rect.clone();
if (invertLongitute) {
// Longitude is inverted.
rect.y = -rect.y - rect.height;
}
var rawTransformable = this._rawTransformable;
rawTransformable.transform = rect.calculateTransform(new BoundingRect(x, y, width, height));
var rawParent = rawTransformable.parent;
rawTransformable.parent = null;
rawTransformable.decomposeTransform();
rawTransformable.parent = rawParent;
if (invertLongitute) {
rawTransformable.scaleY = -rawTransformable.scaleY;
}
this._updateTransform();
};
Geo.prototype.getRegion = function (name) {
return this._regionsMap.get(name);
};
Geo.prototype.getRegionByCoord = function (coord) {
var regions = this.regions;
for (var i = 0; i < regions.length; i++) {
var region = regions[i];
if (region.type === 'geoJSON' && region.contain(coord)) {
return regions[i];
}
}
};
/**
* Add geoCoord for indexing by name
*/
Geo.prototype.addGeoCoord = function (name, geoCoord) {
this._nameCoordMap.set(name, geoCoord);
};
/**
* Get geoCoord by name
*/
Geo.prototype.getGeoCoord = function (name) {
var region = this._regionsMap.get(name);
// Calculate center only on demand.
return this._nameCoordMap.get(name) || region && region.getCenter();
};
Geo.prototype.dataToPoint = function (data, noRoam, out) {
if (zrUtil.isString(data)) {
// Map area name to geoCoord
data = this.getGeoCoord(data);
}
if (data) {
var projection = this.projection;
if (projection) {
// projection may return null point.
data = projection.project(data);
}
return data && this.projectedToPoint(data, noRoam, out);
}
};
Geo.prototype.pointToData = function (point) {
var projection = this.projection;
if (projection) {
// projection may return null point.
point = projection.unproject(point);
}
return point && this.pointToProjected(point);
};
/**
* Point to projected data. Same with pointToData when projection is used.
*/
Geo.prototype.pointToProjected = function (point) {
return _super.prototype.pointToData.call(this, point);
};
Geo.prototype.projectedToPoint = function (projected, noRoam, out) {
return _super.prototype.dataToPoint.call(this, projected, noRoam, out);
};
Geo.prototype.convertToPixel = function (ecModel, finder, value) {
var coordSys = getCoordSys(finder);
return coordSys === this ? coordSys.dataToPoint(value) : null;
};
Geo.prototype.convertFromPixel = function (ecModel, finder, pixel) {
var coordSys = getCoordSys(finder);
return coordSys === this ? coordSys.pointToData(pixel) : null;
};
return Geo;
}(View);
;
zrUtil.mixin(Geo, View);
function getCoordSys(finder) {
var geoModel = finder.geoModel;
var seriesModel = finder.seriesModel;
return geoModel ? geoModel.coordinateSystem : seriesModel ? seriesModel.coordinateSystem // For map series.
|| (seriesModel.getReferringComponents('geo', SINGLE_REFERRING).models[0] || {}).coordinateSystem : null;
}
export default Geo;

View File

@ -0,0 +1,144 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { each, isString, createHashMap, hasOwn } from 'zrender/lib/core/util.js';
import parseGeoJson from './parseGeoJson.js';
// Built-in GEO fixer.
import fixNanhai from './fix/nanhai.js';
import fixTextCoord from './fix/textCoord.js';
import fixDiaoyuIsland from './fix/diaoyuIsland.js';
import BoundingRect from 'zrender/lib/core/BoundingRect.js';
var DEFAULT_NAME_PROPERTY = 'name';
var GeoJSONResource = /** @class */function () {
function GeoJSONResource(mapName, geoJSON, specialAreas) {
this.type = 'geoJSON';
this._parsedMap = createHashMap();
this._mapName = mapName;
this._specialAreas = specialAreas;
// PENDING: delay the parse to the first usage to rapid up the FMP?
this._geoJSON = parseInput(geoJSON);
}
/**
* @param nameMap can be null/undefined
* @param nameProperty can be null/undefined
*/
GeoJSONResource.prototype.load = function (nameMap, nameProperty) {
nameProperty = nameProperty || DEFAULT_NAME_PROPERTY;
var parsed = this._parsedMap.get(nameProperty);
if (!parsed) {
var rawRegions = this._parseToRegions(nameProperty);
parsed = this._parsedMap.set(nameProperty, {
regions: rawRegions,
boundingRect: calculateBoundingRect(rawRegions)
});
}
var regionsMap = createHashMap();
var finalRegions = [];
each(parsed.regions, function (region) {
var regionName = region.name;
// Try use the alias in geoNameMap
if (nameMap && hasOwn(nameMap, regionName)) {
region = region.cloneShallow(regionName = nameMap[regionName]);
}
finalRegions.push(region);
regionsMap.set(regionName, region);
});
return {
regions: finalRegions,
boundingRect: parsed.boundingRect || new BoundingRect(0, 0, 0, 0),
regionsMap: regionsMap
};
};
GeoJSONResource.prototype._parseToRegions = function (nameProperty) {
var mapName = this._mapName;
var geoJSON = this._geoJSON;
var rawRegions;
// https://jsperf.com/try-catch-performance-overhead
try {
rawRegions = geoJSON ? parseGeoJson(geoJSON, nameProperty) : [];
} catch (e) {
throw new Error('Invalid geoJson format\n' + e.message);
}
fixNanhai(mapName, rawRegions);
each(rawRegions, function (region) {
var regionName = region.name;
fixTextCoord(mapName, region);
fixDiaoyuIsland(mapName, region);
// Some area like Alaska in USA map needs to be tansformed
// to look better
var specialArea = this._specialAreas && this._specialAreas[regionName];
if (specialArea) {
region.transformTo(specialArea.left, specialArea.top, specialArea.width, specialArea.height);
}
}, this);
return rawRegions;
};
/**
* Only for exporting to users.
* **MUST NOT** used internally.
*/
GeoJSONResource.prototype.getMapForUser = function () {
return {
// For backward compatibility, use geoJson
// PENDING: it has been returning them without clone.
// do we need to avoid outsite modification?
geoJson: this._geoJSON,
geoJSON: this._geoJSON,
specialAreas: this._specialAreas
};
};
return GeoJSONResource;
}();
export { GeoJSONResource };
function calculateBoundingRect(regions) {
var rect;
for (var i = 0; i < regions.length; i++) {
var regionRect = regions[i].getBoundingRect();
rect = rect || regionRect.clone();
rect.union(regionRect);
}
return rect;
}
function parseInput(source) {
return !isString(source) ? source : typeof JSON !== 'undefined' && JSON.parse ? JSON.parse(source) : new Function('return (' + source + ');')();
}

210
frontend/node_modules/echarts/lib/coord/geo/GeoModel.js generated vendored Normal file
View File

@ -0,0 +1,210 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { __extends } from "tslib";
import * as zrUtil from 'zrender/lib/core/util.js';
import * as modelUtil from '../../util/model.js';
import ComponentModel from '../../model/Component.js';
import Model from '../../model/Model.js';
import geoCreator from './geoCreator.js';
import geoSourceManager from './geoSourceManager.js';
;
var GeoModel = /** @class */function (_super) {
__extends(GeoModel, _super);
function GeoModel() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.type = GeoModel.type;
return _this;
}
GeoModel.prototype.init = function (option, parentModel, ecModel) {
var source = geoSourceManager.getGeoResource(option.map);
if (source && source.type === 'geoJSON') {
var itemStyle = option.itemStyle = option.itemStyle || {};
if (!('color' in itemStyle)) {
itemStyle.color = '#eee';
}
}
this.mergeDefaultAndTheme(option, ecModel);
// Default label emphasis `show`
modelUtil.defaultEmphasis(option, 'label', ['show']);
};
GeoModel.prototype.optionUpdated = function () {
var _this = this;
var option = this.option;
option.regions = geoCreator.getFilledRegions(option.regions, option.map, option.nameMap, option.nameProperty);
var selectedMap = {};
this._optionModelMap = zrUtil.reduce(option.regions || [], function (optionModelMap, regionOpt) {
var regionName = regionOpt.name;
if (regionName) {
optionModelMap.set(regionName, new Model(regionOpt, _this, _this.ecModel));
if (regionOpt.selected) {
selectedMap[regionName] = true;
}
}
return optionModelMap;
}, zrUtil.createHashMap());
if (!option.selectedMap) {
option.selectedMap = selectedMap;
}
};
/**
* Get model of region.
*/
GeoModel.prototype.getRegionModel = function (name) {
return this._optionModelMap.get(name) || new Model(null, this, this.ecModel);
};
/**
* Format label
* @param name Region name
*/
GeoModel.prototype.getFormattedLabel = function (name, status) {
var regionModel = this.getRegionModel(name);
var formatter = status === 'normal' ? regionModel.get(['label', 'formatter']) : regionModel.get(['emphasis', 'label', 'formatter']);
var params = {
name: name
};
if (zrUtil.isFunction(formatter)) {
params.status = status;
return formatter(params);
} else if (zrUtil.isString(formatter)) {
return formatter.replace('{a}', name != null ? name : '');
}
};
GeoModel.prototype.setZoom = function (zoom) {
this.option.zoom = zoom;
};
GeoModel.prototype.setCenter = function (center) {
this.option.center = center;
};
// PENGING If selectedMode is null ?
GeoModel.prototype.select = function (name) {
var option = this.option;
var selectedMode = option.selectedMode;
if (!selectedMode) {
return;
}
if (selectedMode !== 'multiple') {
option.selectedMap = null;
}
var selectedMap = option.selectedMap || (option.selectedMap = {});
selectedMap[name] = true;
};
GeoModel.prototype.unSelect = function (name) {
var selectedMap = this.option.selectedMap;
if (selectedMap) {
selectedMap[name] = false;
}
};
GeoModel.prototype.toggleSelected = function (name) {
this[this.isSelected(name) ? 'unSelect' : 'select'](name);
};
GeoModel.prototype.isSelected = function (name) {
var selectedMap = this.option.selectedMap;
return !!(selectedMap && selectedMap[name]);
};
GeoModel.type = 'geo';
GeoModel.layoutMode = 'box';
GeoModel.defaultOption = {
// zlevel: 0,
z: 0,
show: true,
left: 'center',
top: 'center',
// Default value:
// for geoSVG source: 1,
// for geoJSON source: 0.75.
aspectScale: null,
// /// Layout with center and size
// If you want to put map in a fixed size box with right aspect ratio
// This two properties may be more convenient
// layoutCenter: [50%, 50%]
// layoutSize: 100
silent: false,
// Map type
map: '',
// Define left-top, right-bottom coords to control view
// For example, [ [180, 90], [-180, -90] ]
boundingCoords: null,
// Default on center of map
center: null,
zoom: 1,
scaleLimit: null,
// selectedMode: false
label: {
show: false,
color: '#000'
},
itemStyle: {
borderWidth: 0.5,
borderColor: '#444'
// Default color:
// + geoJSON: #eee
// + geoSVG: null (use SVG original `fill`)
// color: '#eee'
},
emphasis: {
label: {
show: true,
color: 'rgb(100,0,0)'
},
itemStyle: {
color: 'rgba(255,215,0,0.8)'
}
},
select: {
label: {
show: true,
color: 'rgb(100,0,0)'
},
itemStyle: {
color: 'rgba(255,215,0,0.8)'
}
},
regions: []
// tooltip: {
// show: false
// }
};
return GeoModel;
}(ComponentModel);
export default GeoModel;

View File

@ -0,0 +1,333 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { parseSVG, makeViewBoxTransform } from 'zrender/lib/tool/parseSVG.js';
import Group from 'zrender/lib/graphic/Group.js';
import Rect from 'zrender/lib/graphic/shape/Rect.js';
import { assert, createHashMap, each } from 'zrender/lib/core/util.js';
import BoundingRect from 'zrender/lib/core/BoundingRect.js';
import { parseXML } from 'zrender/lib/tool/parseXML.js';
import { GeoSVGRegion } from './Region.js';
/**
* "region available" means that: enable users to set attribute `name="xxx"` on those tags
* to make it be a region.
* 1. region styles and its label styles can be defined in echarts opton:
* ```js
* geo: {
* regions: [{
* name: 'xxx',
* itemStyle: { ... },
* label: { ... }
* }, {
* ...
* },
* ...]
* };
* ```
* 2. name can be duplicated in different SVG tag. All of the tags with the same name share
* a region option. For exampel if there are two <path> representing two lung lobes. They have
* no common parents but both of them need to display label "lung" inside.
*/
var REGION_AVAILABLE_SVG_TAG_MAP = createHashMap(['rect', 'circle', 'line', 'ellipse', 'polygon', 'polyline', 'path',
// <text> <tspan> are also enabled because some SVG might paint text itself,
// but still need to trigger events or tooltip.
'text', 'tspan',
// <g> is also enabled because this case: if multiple tags share one name
// and need label displayed, every tags will display the name, which is not
// expected. So we can put them into a <g name="xxx">. Thereby only one label
// displayed and located based on the bounding rect of the <g>.
'g']);
var GeoSVGResource = /** @class */function () {
function GeoSVGResource(mapName, svg) {
this.type = 'geoSVG';
// All used graphics. key: hostKey, value: root
this._usedGraphicMap = createHashMap();
// All unused graphics.
this._freedGraphics = [];
this._mapName = mapName;
// Only perform parse to XML object here, which might be time
// consiming for large SVG.
// Although convert XML to zrender element is also time consiming,
// if we do it here, the clone of zrender elements has to be
// required. So we do it once for each geo instance, util real
// performance issues call for optimizing it.
this._parsedXML = parseXML(svg);
}
GeoSVGResource.prototype.load = function /* nameMap: NameMap */
() {
// In the "load" stage, graphic need to be built to
// get boundingRect for geo coordinate system.
var firstGraphic = this._firstGraphic;
// Create the return data structure only when first graphic created.
// Because they will be used in geo coordinate system update stage,
// and `regions` will be mounted at `geo` coordinate system,
// in which there is no "view" info, so that it should better not to
// make references to graphic elements.
if (!firstGraphic) {
firstGraphic = this._firstGraphic = this._buildGraphic(this._parsedXML);
this._freedGraphics.push(firstGraphic);
this._boundingRect = this._firstGraphic.boundingRect.clone();
// PENDING: `nameMap` will not be supported until some real requirement come.
// if (nameMap) {
// named = applyNameMap(named, nameMap);
// }
var _a = createRegions(firstGraphic.named),
regions = _a.regions,
regionsMap = _a.regionsMap;
this._regions = regions;
this._regionsMap = regionsMap;
}
return {
boundingRect: this._boundingRect,
regions: this._regions,
regionsMap: this._regionsMap
};
};
GeoSVGResource.prototype._buildGraphic = function (svgXML) {
var result;
var rootFromParse;
try {
result = svgXML && parseSVG(svgXML, {
ignoreViewBox: true,
ignoreRootClip: true
}) || {};
rootFromParse = result.root;
assert(rootFromParse != null);
} catch (e) {
throw new Error('Invalid svg format\n' + e.message);
}
// Note: we keep the covenant that the root has no transform. So always add an extra root.
var root = new Group();
root.add(rootFromParse);
root.isGeoSVGGraphicRoot = true;
// [THE_RULE_OF_VIEWPORT_AND_VIEWBOX]
//
// Consider: `<svg width="..." height="..." viewBox="...">`
// - the `width/height` we call it `svgWidth/svgHeight` for short.
// - `(0, 0, svgWidth, svgHeight)` defines the viewport of the SVG, or say,
// "viewport boundingRect", or `boundingRect` for short.
// - `viewBox` defines the transform from the real content ot the viewport.
// `viewBox` has the same unit as the content of SVG.
// If `viewBox` exists, a transform is defined, so the unit of `svgWidth/svgHeight` become
// different from the content of SVG. Otherwise, they are the same.
//
// If both `svgWidth/svgHeight/viewBox` are specified in a SVG file, the transform rule will be:
// 0. `boundingRect` is `(0, 0, svgWidth, svgHeight)`. Set it to Geo['_rect'] (View['_rect']).
// 1. Make a transform from `viewBox` to `boundingRect`.
// Note: only support `preserveAspectRatio 'xMidYMid'` here. That is, this transform will preserve
// the aspect ratio.
// 2. Make a transform from boundingRect to Geo['_viewRect'] (View['_viewRect'])
// (`Geo`/`View` will do this job).
// Note: this transform might not preserve aspect radio, which depending on how users specify
// viewRect in echarts option (e.g., `geo.left/top/width/height` will not preserve aspect ratio,
// but `geo.layoutCenter/layoutSize` will preserve aspect ratio).
//
// If `svgWidth/svgHeight` not specified, we use `viewBox` as the `boundingRect` to make the SVG
// layout look good.
//
// If neither `svgWidth/svgHeight` nor `viewBox` are not specified, we calculate the boundingRect
// of the SVG content and use them to make SVG layout look good.
var svgWidth = result.width;
var svgHeight = result.height;
var viewBoxRect = result.viewBoxRect;
var boundingRect = this._boundingRect;
if (!boundingRect) {
var bRectX = void 0;
var bRectY = void 0;
var bRectWidth = void 0;
var bRectHeight = void 0;
if (svgWidth != null) {
bRectX = 0;
bRectWidth = svgWidth;
} else if (viewBoxRect) {
bRectX = viewBoxRect.x;
bRectWidth = viewBoxRect.width;
}
if (svgHeight != null) {
bRectY = 0;
bRectHeight = svgHeight;
} else if (viewBoxRect) {
bRectY = viewBoxRect.y;
bRectHeight = viewBoxRect.height;
}
// If both viewBox and svgWidth/svgHeight not specified,
// we have to determine how to layout those element to make them look good.
if (bRectX == null || bRectY == null) {
var calculatedBoundingRect = rootFromParse.getBoundingRect();
if (bRectX == null) {
bRectX = calculatedBoundingRect.x;
bRectWidth = calculatedBoundingRect.width;
}
if (bRectY == null) {
bRectY = calculatedBoundingRect.y;
bRectHeight = calculatedBoundingRect.height;
}
}
boundingRect = this._boundingRect = new BoundingRect(bRectX, bRectY, bRectWidth, bRectHeight);
}
if (viewBoxRect) {
var viewBoxTransform = makeViewBoxTransform(viewBoxRect, boundingRect);
// Only support `preserveAspectRatio 'xMidYMid'`
rootFromParse.scaleX = rootFromParse.scaleY = viewBoxTransform.scale;
rootFromParse.x = viewBoxTransform.x;
rootFromParse.y = viewBoxTransform.y;
}
// SVG needs to clip based on `viewBox`. And some SVG files really rely on this feature.
// They do not strictly confine all of the content inside a display rect, but deliberately
// use a `viewBox` to define a displayable rect.
// PENDING:
// The drawback of the `setClipPath` here is: the region label (genereted by echarts) near the
// edge might also be clipped, because region labels are put as `textContent` of the SVG path.
root.setClipPath(new Rect({
shape: boundingRect.plain()
}));
var named = [];
each(result.named, function (namedItem) {
if (REGION_AVAILABLE_SVG_TAG_MAP.get(namedItem.svgNodeTagLower) != null) {
named.push(namedItem);
setSilent(namedItem.el);
}
});
return {
root: root,
boundingRect: boundingRect,
named: named
};
};
/**
* Consider:
* (1) One graphic element can not be shared by different `geoView` running simultaneously.
* Notice, also need to consider multiple echarts instances share a `mapRecord`.
* (2) Converting SVG to graphic elements is time consuming.
* (3) In the current architecture, `load` should be called frequently to get boundingRect,
* and it is called without view info.
* So we maintain graphic elements in this module, and enables `view` to use/return these
* graphics from/to the pool with it's uid.
*/
GeoSVGResource.prototype.useGraphic = function (hostKey /* , nameMap: NameMap */) {
var usedRootMap = this._usedGraphicMap;
var svgGraphic = usedRootMap.get(hostKey);
if (svgGraphic) {
return svgGraphic;
}
svgGraphic = this._freedGraphics.pop()
// use the first boundingRect to avoid duplicated boundingRect calculation.
|| this._buildGraphic(this._parsedXML);
usedRootMap.set(hostKey, svgGraphic);
// PENDING: `nameMap` will not be supported until some real requirement come.
// `nameMap` can only be obtained from echarts option.
// The original `named` must not be modified.
// if (nameMap) {
// svgGraphic = extend({}, svgGraphic);
// svgGraphic.named = applyNameMap(svgGraphic.named, nameMap);
// }
return svgGraphic;
};
GeoSVGResource.prototype.freeGraphic = function (hostKey) {
var usedRootMap = this._usedGraphicMap;
var svgGraphic = usedRootMap.get(hostKey);
if (svgGraphic) {
usedRootMap.removeKey(hostKey);
this._freedGraphics.push(svgGraphic);
}
};
return GeoSVGResource;
}();
export { GeoSVGResource };
function setSilent(el) {
// Only named element has silent: false, other elements should
// act as background and has no user interaction.
el.silent = false;
// text|tspan will be converted to group.
if (el.isGroup) {
el.traverse(function (child) {
child.silent = false;
});
}
}
function createRegions(named) {
var regions = [];
var regionsMap = createHashMap();
// Create resions only for the first graphic.
each(named, function (namedItem) {
// Region has feature to calculate center for tooltip or other features.
// If there is a <g name="xxx">, the center should be the center of the
// bounding rect of the g.
if (namedItem.namedFrom != null) {
return;
}
var region = new GeoSVGRegion(namedItem.name, namedItem.el);
// PENDING: if `nameMap` supported, this region can not be mounted on
// `this`, but can only be created each time `load()` called.
regions.push(region);
// PENDING: if multiple tag named with the same name, only one will be
// found by `_regionsMap`. `_regionsMap` is used to find a coordinate
// by name. We use `region.getCenter()` as the coordinate.
regionsMap.set(namedItem.name, region);
});
return {
regions: regions,
regionsMap: regionsMap
};
}
// PENDING: `nameMap` will not be supported until some real requirement come.
// /**
// * Use the alias in geoNameMap.
// * The input `named` must not be modified.
// */
// function applyNameMap(
// named: GeoSVGGraphicRecord['named'],
// nameMap: NameMap
// ): GeoSVGGraphicRecord['named'] {
// const result = [] as GeoSVGGraphicRecord['named'];
// for (let i = 0; i < named.length; i++) {
// let regionGraphic = named[i];
// const name = regionGraphic.name;
// if (nameMap && nameMap.hasOwnProperty(name)) {
// regionGraphic = extend({}, regionGraphic);
// regionGraphic.name = name;
// }
// result.push(regionGraphic);
// }
// return result;
// }

286
frontend/node_modules/echarts/lib/coord/geo/Region.js generated vendored Normal file
View File

@ -0,0 +1,286 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { __extends } from "tslib";
import BoundingRect from 'zrender/lib/core/BoundingRect.js';
import * as vec2 from 'zrender/lib/core/vector.js';
import * as polygonContain from 'zrender/lib/contain/polygon.js';
import * as matrix from 'zrender/lib/core/matrix.js';
import { each } from 'zrender/lib/core/util.js';
var TMP_TRANSFORM = [];
function transformPoints(points, transform) {
for (var p = 0; p < points.length; p++) {
vec2.applyTransform(points[p], points[p], transform);
}
}
function updateBBoxFromPoints(points, min, max, projection) {
for (var i = 0; i < points.length; i++) {
var p = points[i];
if (projection) {
// projection may return null point.
p = projection.project(p);
}
if (p && isFinite(p[0]) && isFinite(p[1])) {
vec2.min(min, min, p);
vec2.max(max, max, p);
}
}
}
function centroid(points) {
var signedArea = 0;
var cx = 0;
var cy = 0;
var len = points.length;
var x0 = points[len - 1][0];
var y0 = points[len - 1][1];
// Polygon should been closed.
for (var i = 0; i < len; i++) {
var x1 = points[i][0];
var y1 = points[i][1];
var a = x0 * y1 - x1 * y0;
signedArea += a;
cx += (x0 + x1) * a;
cy += (y0 + y1) * a;
x0 = x1;
y0 = y1;
}
return signedArea ? [cx / signedArea / 3, cy / signedArea / 3, signedArea] : [points[0][0] || 0, points[0][1] || 0];
}
var Region = /** @class */function () {
function Region(name) {
this.name = name;
}
Region.prototype.setCenter = function (center) {
this._center = center;
};
/**
* Get center point in data unit. That is,
* for GeoJSONRegion, the unit is lat/lng,
* for GeoSVGRegion, the unit is SVG local coord.
*/
Region.prototype.getCenter = function () {
var center = this._center;
if (!center) {
// In most cases there are no need to calculate this center.
// So calculate only when called.
center = this._center = this.calcCenter();
}
return center;
};
return Region;
}();
export { Region };
var GeoJSONPolygonGeometry = /** @class */function () {
function GeoJSONPolygonGeometry(exterior, interiors) {
this.type = 'polygon';
this.exterior = exterior;
this.interiors = interiors;
}
return GeoJSONPolygonGeometry;
}();
export { GeoJSONPolygonGeometry };
var GeoJSONLineStringGeometry = /** @class */function () {
function GeoJSONLineStringGeometry(points) {
this.type = 'linestring';
this.points = points;
}
return GeoJSONLineStringGeometry;
}();
export { GeoJSONLineStringGeometry };
var GeoJSONRegion = /** @class */function (_super) {
__extends(GeoJSONRegion, _super);
function GeoJSONRegion(name, geometries, cp) {
var _this = _super.call(this, name) || this;
_this.type = 'geoJSON';
_this.geometries = geometries;
_this._center = cp && [cp[0], cp[1]];
return _this;
}
GeoJSONRegion.prototype.calcCenter = function () {
var geometries = this.geometries;
var largestGeo;
var largestGeoSize = 0;
for (var i = 0; i < geometries.length; i++) {
var geo = geometries[i];
var exterior = geo.exterior;
// Simple trick to use points count instead of polygon area as region size.
// Ignore linestring
var size = exterior && exterior.length;
if (size > largestGeoSize) {
largestGeo = geo;
largestGeoSize = size;
}
}
if (largestGeo) {
return centroid(largestGeo.exterior);
}
// from bounding rect by default.
var rect = this.getBoundingRect();
return [rect.x + rect.width / 2, rect.y + rect.height / 2];
};
GeoJSONRegion.prototype.getBoundingRect = function (projection) {
var rect = this._rect;
// Always recalculate if using projection.
if (rect && !projection) {
return rect;
}
var min = [Infinity, Infinity];
var max = [-Infinity, -Infinity];
var geometries = this.geometries;
each(geometries, function (geo) {
if (geo.type === 'polygon') {
// Doesn't consider hole
updateBBoxFromPoints(geo.exterior, min, max, projection);
} else {
each(geo.points, function (points) {
updateBBoxFromPoints(points, min, max, projection);
});
}
});
// Normalie invalid bounding.
if (!(isFinite(min[0]) && isFinite(min[1]) && isFinite(max[0]) && isFinite(max[1]))) {
min[0] = min[1] = max[0] = max[1] = 0;
}
rect = new BoundingRect(min[0], min[1], max[0] - min[0], max[1] - min[1]);
if (!projection) {
this._rect = rect;
}
return rect;
};
GeoJSONRegion.prototype.contain = function (coord) {
var rect = this.getBoundingRect();
var geometries = this.geometries;
if (!rect.contain(coord[0], coord[1])) {
return false;
}
loopGeo: for (var i = 0, len = geometries.length; i < len; i++) {
var geo = geometries[i];
// Only support polygon.
if (geo.type !== 'polygon') {
continue;
}
var exterior = geo.exterior;
var interiors = geo.interiors;
if (polygonContain.contain(exterior, coord[0], coord[1])) {
// Not in the region if point is in the hole.
for (var k = 0; k < (interiors ? interiors.length : 0); k++) {
if (polygonContain.contain(interiors[k], coord[0], coord[1])) {
continue loopGeo;
}
}
return true;
}
}
return false;
};
/**
* Transform the raw coords to target bounding.
* @param x
* @param y
* @param width
* @param height
*/
GeoJSONRegion.prototype.transformTo = function (x, y, width, height) {
var rect = this.getBoundingRect();
var aspect = rect.width / rect.height;
if (!width) {
width = aspect * height;
} else if (!height) {
height = width / aspect;
}
var target = new BoundingRect(x, y, width, height);
var transform = rect.calculateTransform(target);
var geometries = this.geometries;
for (var i = 0; i < geometries.length; i++) {
var geo = geometries[i];
if (geo.type === 'polygon') {
transformPoints(geo.exterior, transform);
each(geo.interiors, function (interior) {
transformPoints(interior, transform);
});
} else {
each(geo.points, function (points) {
transformPoints(points, transform);
});
}
}
rect = this._rect;
rect.copy(target);
// Update center
this._center = [rect.x + rect.width / 2, rect.y + rect.height / 2];
};
GeoJSONRegion.prototype.cloneShallow = function (name) {
name == null && (name = this.name);
var newRegion = new GeoJSONRegion(name, this.geometries, this._center);
newRegion._rect = this._rect;
newRegion.transformTo = null; // Simply avoid to be called.
return newRegion;
};
return GeoJSONRegion;
}(Region);
export { GeoJSONRegion };
var GeoSVGRegion = /** @class */function (_super) {
__extends(GeoSVGRegion, _super);
function GeoSVGRegion(name, elOnlyForCalculate) {
var _this = _super.call(this, name) || this;
_this.type = 'geoSVG';
_this._elOnlyForCalculate = elOnlyForCalculate;
return _this;
}
GeoSVGRegion.prototype.calcCenter = function () {
var el = this._elOnlyForCalculate;
var rect = el.getBoundingRect();
var center = [rect.x + rect.width / 2, rect.y + rect.height / 2];
var mat = matrix.identity(TMP_TRANSFORM);
var target = el;
while (target && !target.isGeoSVGGraphicRoot) {
matrix.mul(mat, target.getLocalTransform(), mat);
target = target.parent;
}
matrix.invert(mat, mat);
vec2.applyTransform(center, center, mat);
return center;
};
return GeoSVGRegion;
}(Region);
export { GeoSVGRegion };

View File

@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Fix for 钓鱼岛
// let Region = require('../Region');
// let zrUtil = require('zrender/lib/core/util');
// let geoCoord = [126, 25];
var points = [[[123.45165252685547, 25.73527164402261], [123.49731445312499, 25.73527164402261], [123.49731445312499, 25.750734064600884], [123.45165252685547, 25.750734064600884], [123.45165252685547, 25.73527164402261]]];
export default function fixDiaoyuIsland(mapType, region) {
if (mapType === 'china' && region.name === '台湾') {
region.geometries.push({
type: 'polygon',
exterior: points[0]
});
}
}

View File

@ -0,0 +1,57 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var geoCoordMap = {
'Russia': [100, 60],
'United States': [-99, 38],
'United States of America': [-99, 38]
};
export default function fixGeoCoords(mapType, region) {
if (mapType === 'world') {
var geoCoord = geoCoordMap[region.name];
if (geoCoord) {
var cp = [geoCoord[0], geoCoord[1]];
region.setCenter(cp);
}
}
}

View File

@ -0,0 +1,73 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Fix for 南海诸岛
import * as zrUtil from 'zrender/lib/core/util.js';
import { GeoJSONRegion } from '../Region.js';
var geoCoord = [126, 25];
var nanhaiName = '南海诸岛';
var points = [[[0, 3.5], [7, 11.2], [15, 11.9], [30, 7], [42, 0.7], [52, 0.7], [56, 7.7], [59, 0.7], [64, 0.7], [64, 0], [5, 0], [0, 3.5]], [[13, 16.1], [19, 14.7], [16, 21.7], [11, 23.1], [13, 16.1]], [[12, 32.2], [14, 38.5], [15, 38.5], [13, 32.2], [12, 32.2]], [[16, 47.6], [12, 53.2], [13, 53.2], [18, 47.6], [16, 47.6]], [[6, 64.4], [8, 70], [9, 70], [8, 64.4], [6, 64.4]], [[23, 82.6], [29, 79.8], [30, 79.8], [25, 82.6], [23, 82.6]], [[37, 70.7], [43, 62.3], [44, 62.3], [39, 70.7], [37, 70.7]], [[48, 51.1], [51, 45.5], [53, 45.5], [50, 51.1], [48, 51.1]], [[51, 35], [51, 28.7], [53, 28.7], [53, 35], [51, 35]], [[52, 22.4], [55, 17.5], [56, 17.5], [53, 22.4], [52, 22.4]], [[58, 12.6], [62, 7], [63, 7], [60, 12.6], [58, 12.6]], [[0, 3.5], [0, 93.1], [64, 93.1], [64, 0], [63, 0], [63, 92.4], [1, 92.4], [1, 3.5], [0, 3.5]]];
for (var i = 0; i < points.length; i++) {
for (var k = 0; k < points[i].length; k++) {
points[i][k][0] /= 10.5;
points[i][k][1] /= -10.5 / 0.75;
points[i][k][0] += geoCoord[0];
points[i][k][1] += geoCoord[1];
}
}
export default function fixNanhai(mapType, regions) {
if (mapType === 'china') {
for (var i = 0; i < regions.length; i++) {
// Already exists.
if (regions[i].name === nanhaiName) {
return;
}
}
regions.push(new GeoJSONRegion(nanhaiName, zrUtil.map(points, function (exterior) {
return {
type: 'polygon',
exterior: exterior
};
}), geoCoord));
}
}

View File

@ -0,0 +1,63 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var coordsOffsetMap = {
'南海诸岛': [32, 80],
// 全国
'广东': [0, -10],
'香港': [10, 5],
'澳门': [-10, 10],
// '北京': [-10, 0],
'天津': [5, 5]
};
export default function fixTextCoords(mapType, region) {
if (mapType === 'china') {
var coordFix = coordsOffsetMap[region.name];
if (coordFix) {
var cp = region.getCenter();
cp[0] += coordFix[0] / 10.5;
cp[1] += -coordFix[1] / (10.5 / 0.75);
region.setCenter(cp);
}
}
}

View File

@ -0,0 +1,243 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import * as zrUtil from 'zrender/lib/core/util.js';
import Geo, { geo2DDimensions } from './Geo.js';
import * as layout from '../../util/layout.js';
import * as numberUtil from '../../util/number.js';
import geoSourceManager from './geoSourceManager.js';
import * as vector from 'zrender/lib/core/vector.js';
/**
* Resize method bound to the geo
*/
function resizeGeo(geoModel, api) {
var boundingCoords = geoModel.get('boundingCoords');
if (boundingCoords != null) {
var leftTop_1 = boundingCoords[0];
var rightBottom_1 = boundingCoords[1];
if (!(isFinite(leftTop_1[0]) && isFinite(leftTop_1[1]) && isFinite(rightBottom_1[0]) && isFinite(rightBottom_1[1]))) {
if (process.env.NODE_ENV !== 'production') {
console.error('Invalid boundingCoords');
}
} else {
// Sample around the lng/lat rect and use projection to calculate actual bounding rect.
var projection_1 = this.projection;
if (projection_1) {
var xMin = leftTop_1[0];
var yMin = leftTop_1[1];
var xMax = rightBottom_1[0];
var yMax = rightBottom_1[1];
leftTop_1 = [Infinity, Infinity];
rightBottom_1 = [-Infinity, -Infinity];
// TODO better way?
var sampleLine = function (x0, y0, x1, y1) {
var dx = x1 - x0;
var dy = y1 - y0;
for (var i = 0; i <= 100; i++) {
var p = i / 100;
var pt = projection_1.project([x0 + dx * p, y0 + dy * p]);
vector.min(leftTop_1, leftTop_1, pt);
vector.max(rightBottom_1, rightBottom_1, pt);
}
};
// Top
sampleLine(xMin, yMin, xMax, yMin);
// Right
sampleLine(xMax, yMin, xMax, yMax);
// Bottom
sampleLine(xMax, yMax, xMin, yMax);
// Left
sampleLine(xMin, yMax, xMax, yMin);
}
this.setBoundingRect(leftTop_1[0], leftTop_1[1], rightBottom_1[0] - leftTop_1[0], rightBottom_1[1] - leftTop_1[1]);
}
}
var rect = this.getBoundingRect();
var centerOption = geoModel.get('layoutCenter');
var sizeOption = geoModel.get('layoutSize');
var viewWidth = api.getWidth();
var viewHeight = api.getHeight();
var aspect = rect.width / rect.height * this.aspectScale;
var useCenterAndSize = false;
var center;
var size;
if (centerOption && sizeOption) {
center = [numberUtil.parsePercent(centerOption[0], viewWidth), numberUtil.parsePercent(centerOption[1], viewHeight)];
size = numberUtil.parsePercent(sizeOption, Math.min(viewWidth, viewHeight));
if (!isNaN(center[0]) && !isNaN(center[1]) && !isNaN(size)) {
useCenterAndSize = true;
} else {
if (process.env.NODE_ENV !== 'production') {
console.warn('Given layoutCenter or layoutSize data are invalid. Use left/top/width/height instead.');
}
}
}
var viewRect;
if (useCenterAndSize) {
viewRect = {};
if (aspect > 1) {
// Width is same with size
viewRect.width = size;
viewRect.height = size / aspect;
} else {
viewRect.height = size;
viewRect.width = size * aspect;
}
viewRect.y = center[1] - viewRect.height / 2;
viewRect.x = center[0] - viewRect.width / 2;
} else {
// Use left/top/width/height
var boxLayoutOption = geoModel.getBoxLayoutParams();
boxLayoutOption.aspect = aspect;
viewRect = layout.getLayoutRect(boxLayoutOption, {
width: viewWidth,
height: viewHeight
});
}
this.setViewRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
this.setCenter(geoModel.get('center'), api);
this.setZoom(geoModel.get('zoom'));
}
// Back compat for ECharts2, where the coord map is set on map series:
// {type: 'map', geoCoord: {'cityA': [116.46,39.92], 'cityA': [119.12,24.61]}},
function setGeoCoords(geo, model) {
zrUtil.each(model.get('geoCoord'), function (geoCoord, name) {
geo.addGeoCoord(name, geoCoord);
});
}
var GeoCreator = /** @class */function () {
function GeoCreator() {
// For deciding which dimensions to use when creating list data
this.dimensions = geo2DDimensions;
}
GeoCreator.prototype.create = function (ecModel, api) {
var geoList = [];
function getCommonGeoProperties(model) {
return {
nameProperty: model.get('nameProperty'),
aspectScale: model.get('aspectScale'),
projection: model.get('projection')
};
}
// FIXME Create each time may be slow
ecModel.eachComponent('geo', function (geoModel, idx) {
var mapName = geoModel.get('map');
var geo = new Geo(mapName + idx, mapName, zrUtil.extend({
nameMap: geoModel.get('nameMap')
}, getCommonGeoProperties(geoModel)));
geo.zoomLimit = geoModel.get('scaleLimit');
geoList.push(geo);
// setGeoCoords(geo, geoModel);
geoModel.coordinateSystem = geo;
geo.model = geoModel;
// Inject resize method
geo.resize = resizeGeo;
geo.resize(geoModel, api);
});
ecModel.eachSeries(function (seriesModel) {
var coordSys = seriesModel.get('coordinateSystem');
if (coordSys === 'geo') {
var geoIndex = seriesModel.get('geoIndex') || 0;
seriesModel.coordinateSystem = geoList[geoIndex];
}
});
// If has map series
var mapModelGroupBySeries = {};
ecModel.eachSeriesByType('map', function (seriesModel) {
if (!seriesModel.getHostGeoModel()) {
var mapType = seriesModel.getMapType();
mapModelGroupBySeries[mapType] = mapModelGroupBySeries[mapType] || [];
mapModelGroupBySeries[mapType].push(seriesModel);
}
});
zrUtil.each(mapModelGroupBySeries, function (mapSeries, mapType) {
var nameMapList = zrUtil.map(mapSeries, function (singleMapSeries) {
return singleMapSeries.get('nameMap');
});
var geo = new Geo(mapType, mapType, zrUtil.extend({
nameMap: zrUtil.mergeAll(nameMapList)
}, getCommonGeoProperties(mapSeries[0])));
geo.zoomLimit = zrUtil.retrieve.apply(null, zrUtil.map(mapSeries, function (singleMapSeries) {
return singleMapSeries.get('scaleLimit');
}));
geoList.push(geo);
// Inject resize method
geo.resize = resizeGeo;
geo.resize(mapSeries[0], api);
zrUtil.each(mapSeries, function (singleMapSeries) {
singleMapSeries.coordinateSystem = geo;
setGeoCoords(geo, singleMapSeries);
});
});
return geoList;
};
/**
* Fill given regions array
*/
GeoCreator.prototype.getFilledRegions = function (originRegionArr, mapName, nameMap, nameProperty) {
// Not use the original
var regionsArr = (originRegionArr || []).slice();
var dataNameMap = zrUtil.createHashMap();
for (var i = 0; i < regionsArr.length; i++) {
dataNameMap.set(regionsArr[i].name, regionsArr[i]);
}
var source = geoSourceManager.load(mapName, nameMap, nameProperty);
zrUtil.each(source.regions, function (region) {
var name = region.name;
var regionOption = dataNameMap.get(name);
// apply specified echarts style in GeoJSON data
var specifiedGeoJSONRegionStyle = region.properties && region.properties.echartsStyle;
if (!regionOption) {
regionOption = {
name: name
};
regionsArr.push(regionOption);
}
specifiedGeoJSONRegionStyle && zrUtil.merge(regionOption, specifiedGeoJSONRegionStyle);
});
return regionsArr;
};
return GeoCreator;
}();
var geoCreator = new GeoCreator();
export default geoCreator;

View File

@ -0,0 +1,121 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { createHashMap } from 'zrender/lib/core/util.js';
import { GeoSVGResource } from './GeoSVGResource.js';
import { GeoJSONResource } from './GeoJSONResource.js';
var storage = createHashMap();
export default {
/**
* Compatible with previous `echarts.registerMap`.
*
* @usage
* ```js
*
* echarts.registerMap('USA', geoJson, specialAreas);
*
* echarts.registerMap('USA', {
* geoJson: geoJson,
* specialAreas: {...}
* });
* echarts.registerMap('USA', {
* geoJSON: geoJson,
* specialAreas: {...}
* });
*
* echarts.registerMap('airport', {
* svg: svg
* }
* ```
*
* Note:
* Do not support that register multiple geoJSON or SVG
* one map name. Because different geoJSON and SVG have
* different unit. It's not easy to make sure how those
* units are mapping/normalize.
* If intending to use multiple geoJSON or SVG, we can
* use multiple geo coordinate system.
*/
registerMap: function (mapName, rawDef, rawSpecialAreas) {
if (rawDef.svg) {
var resource = new GeoSVGResource(mapName, rawDef.svg);
storage.set(mapName, resource);
} else {
// Recommend:
// echarts.registerMap('eu', { geoJSON: xxx, specialAreas: xxx });
// Backward compatibility:
// echarts.registerMap('eu', geoJSON, specialAreas);
// echarts.registerMap('eu', { geoJson: xxx, specialAreas: xxx });
var geoJSON = rawDef.geoJson || rawDef.geoJSON;
if (geoJSON && !rawDef.features) {
rawSpecialAreas = rawDef.specialAreas;
} else {
geoJSON = rawDef;
}
var resource = new GeoJSONResource(mapName, geoJSON, rawSpecialAreas);
storage.set(mapName, resource);
}
},
getGeoResource: function (mapName) {
return storage.get(mapName);
},
/**
* Only for exporting to users.
* **MUST NOT** used internally.
*/
getMapForUser: function (mapName) {
var resource = storage.get(mapName);
// Do not support return SVG until some real requirement come.
return resource && resource.type === 'geoJSON' && resource.getMapForUser();
},
load: function (mapName, nameMap, nameProperty) {
var resource = storage.get(mapName);
if (!resource) {
if (process.env.NODE_ENV !== 'production') {
console.error('Map ' + mapName + ' not exists. The GeoJSON of the map must be provided.');
}
return;
}
return resource.load(nameMap, nameProperty);
}
};

View File

@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
;
;
;
;
;
;
;
;
;
;
export {};

View File

@ -0,0 +1,146 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Parse and decode geo json
*/
import * as zrUtil from 'zrender/lib/core/util.js';
import { GeoJSONLineStringGeometry, GeoJSONPolygonGeometry, GeoJSONRegion } from './Region.js';
function decode(json) {
if (!json.UTF8Encoding) {
return json;
}
var jsonCompressed = json;
var encodeScale = jsonCompressed.UTF8Scale;
if (encodeScale == null) {
encodeScale = 1024;
}
var features = jsonCompressed.features;
zrUtil.each(features, function (feature) {
var geometry = feature.geometry;
var encodeOffsets = geometry.encodeOffsets;
var coordinates = geometry.coordinates;
// Geometry may be appeded manually in the script after json loaded.
// In this case this geometry is usually not encoded.
if (!encodeOffsets) {
return;
}
switch (geometry.type) {
case 'LineString':
geometry.coordinates = decodeRing(coordinates, encodeOffsets, encodeScale);
break;
case 'Polygon':
decodeRings(coordinates, encodeOffsets, encodeScale);
break;
case 'MultiLineString':
decodeRings(coordinates, encodeOffsets, encodeScale);
break;
case 'MultiPolygon':
zrUtil.each(coordinates, function (rings, idx) {
return decodeRings(rings, encodeOffsets[idx], encodeScale);
});
}
});
// Has been decoded
jsonCompressed.UTF8Encoding = false;
return jsonCompressed;
}
function decodeRings(rings, encodeOffsets, encodeScale) {
for (var c = 0; c < rings.length; c++) {
rings[c] = decodeRing(rings[c], encodeOffsets[c], encodeScale);
}
}
function decodeRing(coordinate, encodeOffsets, encodeScale) {
var result = [];
var prevX = encodeOffsets[0];
var prevY = encodeOffsets[1];
for (var i = 0; i < coordinate.length; i += 2) {
var x = coordinate.charCodeAt(i) - 64;
var y = coordinate.charCodeAt(i + 1) - 64;
// ZigZag decoding
x = x >> 1 ^ -(x & 1);
y = y >> 1 ^ -(y & 1);
// Delta deocding
x += prevX;
y += prevY;
prevX = x;
prevY = y;
// Dequantize
result.push([x / encodeScale, y / encodeScale]);
}
return result;
}
export default function parseGeoJSON(geoJson, nameProperty) {
geoJson = decode(geoJson);
return zrUtil.map(zrUtil.filter(geoJson.features, function (featureObj) {
// Output of mapshaper may have geometry null
return featureObj.geometry && featureObj.properties && featureObj.geometry.coordinates.length > 0;
}), function (featureObj) {
var properties = featureObj.properties;
var geo = featureObj.geometry;
var geometries = [];
switch (geo.type) {
case 'Polygon':
var coordinates = geo.coordinates;
// According to the GeoJSON specification.
// First must be exterior, and the rest are all interior(holes).
geometries.push(new GeoJSONPolygonGeometry(coordinates[0], coordinates.slice(1)));
break;
case 'MultiPolygon':
zrUtil.each(geo.coordinates, function (item) {
if (item[0]) {
geometries.push(new GeoJSONPolygonGeometry(item[0], item.slice(1)));
}
});
break;
case 'LineString':
geometries.push(new GeoJSONLineStringGeometry([geo.coordinates]));
break;
case 'MultiLineString':
geometries.push(new GeoJSONLineStringGeometry(geo.coordinates));
}
var region = new GeoJSONRegion(properties[nameProperty || 'name'], geometries, properties.cp);
region.properties = properties;
return region;
});
}

View File

@ -0,0 +1,79 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import * as zrUtil from 'zrender/lib/core/util.js';
function dataToCoordSize(dataSize, dataItem) {
dataItem = dataItem || [0, 0];
return zrUtil.map([0, 1], function (dimIdx) {
var val = dataItem[dimIdx];
var halfSize = dataSize[dimIdx] / 2;
var p1 = [];
var p2 = [];
p1[dimIdx] = val - halfSize;
p2[dimIdx] = val + halfSize;
p1[1 - dimIdx] = p2[1 - dimIdx] = dataItem[1 - dimIdx];
return Math.abs(this.dataToPoint(p1)[dimIdx] - this.dataToPoint(p2)[dimIdx]);
}, this);
}
export default function geoPrepareCustom(coordSys) {
var rect = coordSys.getBoundingRect();
return {
coordSys: {
type: 'geo',
x: rect.x,
y: rect.y,
width: rect.width,
height: rect.height,
zoom: coordSys.getZoom()
},
api: {
coord: function (data) {
// do not provide "out" and noRoam param,
// Compatible with this usage:
// echarts.util.map(item.points, api.coord)
return coordSys.dataToPoint(data);
},
size: zrUtil.bind(dataToCoordSize, coordSys)
}
};
}