Skip to content

Commit 5c870a4

Browse files
committed
Tweak geoJSON example api.
1 parent 19fdd60 commit 5c870a4

2 files changed

Lines changed: 143 additions & 66 deletions

File tree

en/api/echarts.md

Lines changed: 71 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -159,49 +159,86 @@ Registers available maps. This can only be used after including [geo](option.htm
159159

160160
Please refer to [option.geo](option.html#geo.map) for usage.
161161

162-
**Parameters**
163-
+ `mapName`
162+
**Parameters:**
163+
+ **@param `mapName`:**
164164

165165
Map name, referring to `map` value set in [geo](option.html#geo) component or [map](option.html#series-map).
166166

167-
+ `opt`
167+
+ **@param `opt.geoJSON`:**
168168

169-
+ `geoJSON` Optional. Data in GeoJson format. See [https://geojson.org/](https://geojson.org/) for more format information. Can be a JSON string or a parsed object. This key can also be `geoJson`.
169+
Optional. Data in GeoJSON format. See [https://geojson.org/](https://geojson.org/) for more format information. Can be a JSON string or a parsed object. This key can also be `geoJson`.
170170

171-
+ `svg` Optional. Data in SVG format. Can be a SVG string or a parsed SVG DOM object. See more info in [SVG Base Map](tutorial.html#SVG%20Base%20Map%20in%20Geo%20Coords%20and%20Map%20SeriesSVG%20Base%20Map). Introduced in v5.1.0
171+
For example, A minimal geoJSON:
172+
```ts
173+
const geoJSONSample = {
174+
"type": "FeatureCollection",
175+
"features": [
176+
{
177+
"type": "Feature",
178+
"geometry": {
179+
"type": "Polygon",
180+
"coordinates": [
181+
[[200, 3000], [500, 3000], [500, 5000], [200, 5000]]
182+
]
183+
},
184+
"properties": {
185+
"name": "Some Place",
186+
"cp": [220, 2100]
187+
}
188+
}
189+
]
190+
};
191+
echarts.registerMap('my_geo_sample', {geoJSON: geoJSONSample});
192+
```
193+
Note:
194+
+ `features[i].properties.name` in GeoJSON is required by ECharts to query the corresponding region, or display the label. Property `name` is used by default, but can also be other properties, see [geo.nameProperty](option.html#geo.nameProperty).
195+
+ `features[i].properties.cp` is an optional property that ECharts can recoganize. It provides coordinates on which the label can be displayed. If not provided, the label will be displayed at the center of the region.
172196

173-
+ `specialAreas` Optional. zoomed part of a specific area in the map for better visual effect. Only work for `geoJSON`.
197+
+ **@param `opt.svg`:**
174198

175-
**For example [USA Population Estimates](${galleryEditorPath}map-usa): **
176-
```ts
177-
echarts.registerMap('USA', usaJson, {
178-
// Move Alaska to the bottom left of United States
179-
Alaska: {
180-
// Upper left longitude
181-
left: -131,
182-
// Upper left latitude
183-
top: 25,
184-
// Range of longitude
185-
width: 15
186-
},
187-
// Hawaii
188-
Hawaii: {
189-
left: -110,
190-
top: 28,
191-
width: 5
192-
},
193-
// Puerto Rico
194-
'Puerto Rico': {
195-
left: -76,
196-
top: 26,
197-
width: 2
198-
}
199-
});
200-
```
199+
Optional. Data in SVG format. Can be a SVG string or a parsed SVG DOM object. See more info in [SVG Base Map](tutorial.html#SVG%20Base%20Map%20in%20Geo%20Coords%20and%20Map%20SeriesSVG%20Base%20Map). Introduced in `v5.1.0`.
201200

202-
Note:
201+
For example, A minimal SVG:
202+
```ts
203+
const mySVG = `<?xml version="1.0" encoding="utf-8"?>
204+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:ooo="http://xml.openoffice.org/svg/export" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" fill-rule="evenodd" xml:space="preserve">
205+
<path name="left_rect" d="M 0,0 L 0,100 100,100 100,0 Z" fill="#765" stroke="rgb(56,93,138)" stroke-width="0" stroke-linecap="square" stroke-linejoin="miter"/>
206+
</svg>`;
207+
echarts.registerMap('my_geo_sample', {svg: mySVG});
208+
```
209+
210+
+ **@param `opt.specialAreas`:**
211+
212+
Optional. zoomed part of a specific area in the map for better visual effect. Only work for `geoJSON`.
213+
214+
**[An example of specialAreas](${galleryEditorPath}map-usa): **
215+
```ts
216+
echarts.registerMap('USA', usaJson, {
217+
// Move Alaska to the bottom left of United States
218+
Alaska: {
219+
// Upper left longitude
220+
left: -131,
221+
// Upper left latitude
222+
top: 25,
223+
// Range of longitude
224+
width: 15
225+
},
226+
// Hawaii
227+
Hawaii: {
228+
left: -110,
229+
top: 28,
230+
width: 5
231+
},
232+
// Puerto Rico
233+
'Puerto Rico': {
234+
left: -76,
235+
top: 26,
236+
width: 2
237+
}
238+
});
239+
```
203240

204-
If you only import the required components in your project, starting from v5.3.0 `registerMap` has to be used after the `MapChart` or `GeoComponent` is imported.
241+
Note: If you only import the required components in your project, starting from v5.3.0 `registerMap` cannot be called unless `MapChart` or `GeoComponent` is imported (ES module import).
205242

206243
## getMap(Function)
207244
```ts

zh/api/echarts.md

Lines changed: 72 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -158,47 +158,87 @@ echarts.use(
158158
使用方法见 [option.geo](option.html#geo.map)。
159159

160160
**参数:**
161-
+ `mapName`
161+
+ **@param `mapName`:**
162162

163163
地图名称,在 [geo](option.html#geo) 组件或者 [map](option.html#series-map) 图表类型中设置的 `map` 对应的就是该值。
164164

165-
+ `opt`
166165

167-
+ `geoJSON` 可选。GeoJson 格式的数据,具体格式见 [https://geojson.org/](https://geojson.org/)。可以是 JSON 字符串,也可以是解析得到的对象。这个参数也可以写为 `geoJson`,效果相同。
166+
+ **@param `opt.geoJSON`:**
168167

169-
+ `svg` 可选。`v5.1.0` 开始支持SVG 格式的数据。可以是字符串,也可以是解析得到的 SVG DOM 对象。更多信息参见 [SVG 底图](tutorial.html#%E5%9C%B0%E7%90%86%E5%9D%90%E6%A0%87%E7%B3%BB%E5%92%8C%E5%9C%B0%E5%9B%BE%E7%B3%BB%E5%88%97%E7%9A%84%20SVG%20%E5%BA%95%E5%9B%BE)
168+
可选。GeoJSON 格式的数据,具体格式见 [https://geojson.org/](https://geojson.org/)。可以是 JSON 字符串,也可以是解析得到的对象。这个参数也可以写为 `geoJson`,效果相同
170169

171-
+ `specialAreas` 可选。将地图中的部分区域缩放到合适的位置,可以使得整个地图的显示更加好看。只在 `geoJSON` 中生效,`svg` 中不生效。
170+
例如,一个极小的 GeoJSON
171+
```ts
172+
const geoJSONSample = {
173+
"type": "FeatureCollection",
174+
"features": [
175+
{
176+
"type": "Feature",
177+
"geometry": {
178+
"type": "Polygon",
179+
"coordinates": [
180+
[[2000, 2000], [5000, 2000], [5000, 5000], [2000, 5000]]
181+
]
182+
},
183+
"properties": {
184+
"name": "Some Place",
185+
"cp": [220, 2100]
186+
}
187+
}
188+
]
189+
};
190+
echarts.registerMap('my_geo_sample', geoJSONSample);
191+
```
192+
注:
193+
+ GeoJSON 中的 `features[i].properties.name`ECharts 默认使用来索引这个区域,或者显示图标文字。也可以使用其他属性名,参见 [geo.nameProperty](option.html#geo.nameProperty)。
194+
Note:
195+
+ GeoJSON 中的 `features[i].properties.cp` 是个 ECharts 可识别的可选属性。它提供了标签的位置坐标。如果没有提供,标签自动放置在相应区域的中心。
172196

173-
示例 [USA Population Estimates](${galleryEditorPath}map-usa):
197+
+ **@param `opt.svg`:**
174198

175-
```ts
176-
echarts.registerMap('USA', usaJson, {
177-
// 把阿拉斯加移到美国主大陆左下方
178-
Alaska: {
179-
// 左上角经度
180-
left: -131,
181-
// 左上角纬度
182-
top: 25,
183-
// 经度横跨的范围
184-
width: 15
185-
},
186-
// 夏威夷
187-
Hawaii: {
188-
left: -110,
189-
top: 28,
190-
width: 5
191-
},
192-
// 波多黎各
193-
'Puerto Rico': {
194-
left: -76,
195-
top: 26,
196-
width: 2
197-
}
198-
});
199-
```
199+
可选。从 `v5.1.0` 开始支持SVG 格式的数据。可以是字符串,也可以是解析得到的 SVG DOM 对象。更多信息参见 [SVG 底图](tutorial.html#%E5%9C%B0%E7%90%86%E5%9D%90%E6%A0%87%E7%B3%BB%E5%92%8C%E5%9C%B0%E5%9B%BE%E7%B3%BB%E5%88%97%E7%9A%84%20SVG%20%E5%BA%95%E5%9B%BE)。
200+
201+
例如,一个极小的 SVG
202+
```ts
203+
const mySVG = `<?xml version="1.0" encoding="utf-8"?>
204+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:ooo="http://xml.openoffice.org/svg/export" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2" fill-rule="evenodd" xml:space="preserve">
205+
<path name="left_rect" d="M 0,0 L 0,100 100,100 100,0 Z" fill="#765" stroke="rgb(56,93,138)" stroke-width="0" stroke-linecap="square" stroke-linejoin="miter"/>
206+
</svg>`;
207+
echarts.registerMap('my_geo_sample', {svg: mySVG});
208+
```
209+
210+
+ **@param `opt.specialAreas`:**
211+
212+
可选。将地图中的部分区域缩放到合适的位置,可以使得整个地图的显示更加好看。只在 `geoJSON` 中生效,`svg` 中不生效。
213+
214+
[specialAreas 示例](${galleryEditorPath}map-usa):
215+
```ts
216+
echarts.registerMap('USA', usaJson, {
217+
// 把阿拉斯加移到美国主大陆左下方
218+
Alaska: {
219+
// 左上角经度
220+
left: -131,
221+
// 左上角纬度
222+
top: 25,
223+
// 经度横跨的范围
224+
width: 15
225+
},
226+
// 夏威夷
227+
Hawaii: {
228+
left: -110,
229+
top: 28,
230+
width: 5
231+
},
232+
// 波多黎各
233+
'Puerto Rico': {
234+
left: -76,
235+
top: 26,
236+
width: 2
237+
}
238+
});
239+
```
200240

201-
注:如果你在项目中使用了按需引入,从 v5.3.0 开始`registerMap`必须要在引入地图组件后才能使用
241+
注:如果你在项目中使用了按需引入,从 v5.3.0 开始 `registerMap` 必须要在`MapChart``GeoComponent``import`ES module import)后才能使用
202242

203243
## getMap(Function)
204244
```ts

0 commit comments

Comments
 (0)