logo

G2

  • Docs
  • Chart Introduction
  • API
  • Examples
  • Theme
  • Ecosystem
  • Productsantv logo arrow
  • 5.3.3
  • Get Started
  • Introduction
    • What is G2
    • Use In Framework
    • Experimental Spec API
  • Core Concepts
    • Chart
      • Components of G2 Charts
      • How to Use Charts
    • Mark
      • overview
      • area
      • box
      • boxplot
      • cell
      • chord
      • density
      • gauge
      • heatmap
      • image
      • interval
      • line
      • lineX
      • lineY
      • link
      • liquid
      • sunburst
      • point
      • polygon
      • range
      • rangeX
      • rangeY
      • rect
      • shape
      • text
      • vector
      • wordCloud
    • View
    • Data
      • overview
      • custom
      • ema
      • fetch
      • filter
      • fold
      • inline
      • join
      • kde
      • log
      • map
      • pick
      • rename
      • slice
      • sort
      • sortBy
    • Encode
    • Scale
      • overview
      • band
      • linear
      • log
      • ordinal
      • point
      • pow
      • quantile
      • quantize
      • sqrt
      • threshold
      • time
    • Transform
      • overview
      • bin
      • binX
      • diffY
      • dodgeX
      • flexX
      • group
      • groupColor
      • groupX
      • groupY
      • jitter
      • jitterX
      • jitterY
      • normalizeY
      • pack
      • sample
      • select
      • selectX
      • selectX
      • sortColor
      • sortX
      • sortY
      • stackEnter
      • stackY
      • symmetryY
    • Coordinate
      • overview
      • fisheye
      • parallel
      • polar
      • radial
      • theta
      • transpose
      • cartesian3D
      • helix
    • Style
    • Animate
      • overview
      • fadeIn
      • fadeOut
      • growInX
      • growInY
      • morphing
      • pathIn
      • scaleInX
      • scaleInY
      • scaleOutX
      • scaleOutY
      • waveIn
      • zoomIn
      • zoomOut
    • State
    • Interaction
      • Overview
      • brushAxisHighlight
      • brushHighlight
      • brushXHighlight
      • brushYHighlight
      • brushFilter
      • brushXFilter
      • brushYFilter
      • chartIndex
      • elementHighlight
      • elementHighlightByColor
      • elementHighlightByX
      • elementSelect
      • elementSelectByColor
      • elementSelectByX
      • fisheye
      • legendFilter
      • legendHighlight
      • poptip
      • scrollbarFilter
      • sliderFilter
    • Composition
      • overview
      • facetCircle
      • facetRect
      • repeatMatrix
      • spaceFlex
      • spaceLayer
      • timingKeyframe
    • Theme
      • overview
      • Academy
      • classic
      • classicDark
    • event
    • Color
  • Chart API
  • Chart Component
    • 标题(Title)
    • Axis
    • Legend
    • Scrollbar
    • Slider
    • Tooltip
    • Label
  • Extra Topics
    • Graph
      • forceGraph
      • pack
      • sankey
      • tree
      • treemap
    • Geo
      • geoPath
      • geoView
    • 3D
      • Draw 3D Chart
      • point3D
      • line3D
      • interval3D
      • surface3D
    • Plugin
      • renderer
      • rough
      • lottie
      • a11y
    • Package on demand
    • Set pattern
    • Server-side rendering(SSR)
    • Spec Function Expression Support (Available in 5.3.0)
  • Whats New
    • New Version Features
    • Migration from v4 to v5
  • Frequently Asked Questions (FAQ)

geoView

Previous
geoPath
Next
Draw 3D Chart

Resources

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference

Help

GitHub
StackOverflow

more productsMore Productions

Ant DesignAnt Design-Enterprise UI design language
yuqueYuque-Knowledge creation and Sharing tool
EggEgg-Enterprise-class Node development framework
kitchenKitchen-Sketch Tool set
GalaceanGalacean-互动图形解决方案
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

geoView 是绘制地图的容器,用于多 geoPath 图层叠加。

开始使用

geoView
/**
* A recreation of this demo: https://vega.github.io/vega-lite/examples/geo_layer_line_london.html
*/
import { Chart } from '@antv/g2';
import { feature } from 'topojson';
Promise.all([
fetch('https://assets.antv.antgroup.com/g2/londonBoroughs.json').then((res) =>
res.json(),
),
fetch('https://assets.antv.antgroup.com/g2/londonCentroids.json').then(
(res) => res.json(),
),
fetch('https://assets.antv.antgroup.com/g2/londonTubeLines.json').then(
(res) => res.json(),
),
]).then((values) => {
const [londonBoroughs, londonCentroids, londonTubeLines] = values;
const london = feature(
londonBoroughs,
londonBoroughs.objects.boroughs,
).features;
const line = feature(londonTubeLines, londonTubeLines.objects.line).features;
const chart = new Chart({
container: 'container',
autoFit: true,
});
const geoView = chart.geoView();
geoView
.geoPath()
.data(london)
.style('fill', 'lightgray')
.style('stroke', 'white')
.style('strokeWidth', 2);
geoView
.text()
.data(londonCentroids)
.encode('x', 'cx')
.encode('y', 'cy')
.encode('text', (d) => d.name.split(/\W/)[0])
.style('fontSize', 8)
.style('opacity', 0.6);
geoView
.geoPath()
.data(line)
.encode('color', 'id')
.encode('shape', 'hollow')
.scale('color', {
domain: [
'Bakerloo',
'Central',
'Circle',
'District',
'DLR',
'Hammersmith & City',
'Jubilee',
'Metropolitan',
'Northern',
'Piccadilly',
'Victoria',
'Waterloo & City',
],
range: [
'rgb(137,78,36)',
'rgb(220,36,30)',
'rgb(255,206,0)',
'rgb(1,114,41)',
'rgb(0,175,173)',
'rgb(215,153,175)',
'rgb(106,114,120)',
'rgb(114,17,84)',
'rgb(0,0,0)',
'rgb(0,24,168)',
'rgb(0,160,226)',
'rgb(106,187,170)',
],
});
chart.render();
});

选项

目前 geoView 容器具备 geoPath 全部的属性,除了 geoPath 作为 mark 独有的 encode 方法。

同样,对于 projection 映射,当前 G2 内置了 d3-geo 的所有映射。