Skip to content
On this page

Runtime API Examples

This page demonstrates usage of some of the runtime APIs provided by VitePress.

The main useData() API can be used to access site, theme, and page data for the current page. It works in both .md and .vue files:

md
<script setup>
import { useData } from 'vitepress'

const { theme, page, frontmatter } = useData()
</script>

## Results

### Theme Data
<pre>{{ theme }}</pre>

### Page Data
<pre>{{ page }}</pre>

### Page Frontmatter
<pre>{{ frontmatter }}</pre>

Results

Theme Data

{
  "nav": [
    {
      "text": "Home",
      "link": "/"
    },
    {
      "text": "文档",
      "link": "/guide/started.md"
    }
  ],
  "sidebar": [
    {
      "text": "快速开始",
      "link": "/guide/started.md"
    },
    {
      "text": "测量",
      "items": [
        {
          "text": "在线上查找指定距离处的点",
          "link": "/guide/along.md"
        },
        {
          "text": "计算多边形的面积",
          "link": "/guide/area.md"
        },
        {
          "text": "计算边界",
          "link": "/guide/bbox.md"
        },
        {
          "text": "计算边界转换为多边形",
          "link": "/guide/bboxPolygon.md"
        },
        {
          "text": "计算两点之间的方位角",
          "link": "/guide/bearing.md"
        },
        {
          "text": "计算中心坐标",
          "link": "/guide/center.md"
        },
        {
          "text": "计算质心坐标",
          "link": "/guide/centerOfMass.md"
        },
        {
          "text": "计算多边形的中心点",
          "link": "/guide/centroid.md"
        },
        {
          "text": "根据距离和角度,返回一个点的坐标",
          "link": "/guide/destination.md"
        },
        {
          "text": "计算两个点之间的距离",
          "link": "/guide/distance.md"
        },
        {
          "text": "计算外包矩形的边界",
          "link": "/guide/envelope.md"
        },
        {
          "text": "计算线段的长度",
          "link": "/guide/length.md"
        },
        {
          "text": "计算线段的中心坐标",
          "link": "/guide/midpoint.md"
        },
        {
          "text": "获取多边形上的一个点",
          "link": "/guide/pointOnFeature.md"
        },
        {
          "text": "计算多边形边缘的相切向量",
          "link": "/guide/polygonTangents.md"
        },
        {
          "text": "计算点到线段的距离",
          "link": "/guide/pointToLineDistance.md"
        },
        {
          "text": "计算两个点之间的方向角度",
          "link": "/guide/rhumbBearing.md"
        },
        {
          "text": "根据点、距离和角度计算目标点",
          "link": "/guide/rhumbDestination.md"
        },
        {
          "text": "沿着等角导线计算两个点之间的距离",
          "link": "/guide/rhumbDistance.md"
        },
        {
          "text": "根据边界计算最小正方形边界",
          "link": "/guide/square.md"
        },
        {
          "text": "计算两点之间的弧线",
          "link": "/guide/greatCircle.md"
        }
      ]
    },
    {
      "text": "坐标转换",
      "items": [
        {
          "text": "删除重复坐标点",
          "link": "/guide/cleanCoords.md"
        },
        {
          "text": "翻转坐标顺序",
          "link": "/guide/flip.md"
        },
        {
          "text": "反转方向",
          "link": "/guide/rewind.md"
        },
        {
          "text": "四舍五入",
          "link": "/guide/round.md"
        },
        {
          "text": "截断小数位",
          "link": "/guide/truncate.md"
        }
      ]
    },
    {
      "text": "变换",
      "items": [
        {
          "text": "矩形裁剪",
          "link": "/guide/bboxClip.md"
        },
        {
          "text": "贝塞尔曲线",
          "link": "/guide/bezierSpline.md"
        },
        {
          "text": "计算缓冲区",
          "link": "/guide/buffer.md"
        },
        {
          "text": "创建圆",
          "link": "/guide/circle.md"
        },
        {
          "text": "克隆",
          "link": "/guide/clone.md"
        },
        {
          "text": "转换凹多边形",
          "link": "/guide/concave.md"
        },
        {
          "text": "转换凸多边形",
          "link": "/guide/convex.md"
        },
        {
          "text": "计算几何差异",
          "link": "/guide/difference.md"
        },
        {
          "text": "分解多边形",
          "link": "/guide/dissolve.md"
        },
        {
          "text": "计算交集",
          "link": "/guide/intersect.md"
        },
        {
          "text": "线偏移",
          "link": "/guide/lineOffset.md"
        },
        {
          "text": "多边形平滑化",
          "link": "/guide/polygonSmooth.md"
        },
        {
          "text": "简化多边形",
          "link": "/guide/simplify.md"
        },
        {
          "text": "生成三角形网格或多边形网格",
          "link": "/guide/tesselate.md"
        },
        {
          "text": "旋转变换",
          "link": "/guide/transformRotate.md"
        },
        {
          "text": "平移变换",
          "link": "/guide/transformTranslate.md"
        },
        {
          "text": "缩放变换",
          "link": "/guide/transformScale.md"
        },
        {
          "text": "联合",
          "link": "/guide/union.md"
        },
        {
          "text": "泰森多边形",
          "link": "/guide/voronoi.md"
        }
      ]
    },
    {
      "text": "要素转换",
      "items": [
        {
          "text": "合并",
          "link": "/guide/combine.md"
        },
        {
          "text": "将多边形拆分为点",
          "link": "/guide/explode.md"
        },
        {
          "text": "扁平化",
          "link": "/guide/flatten.md"
        },
        {
          "text": "线转面",
          "link": "/guide/lineToPolygon.md"
        },
        {
          "text": "多边形化",
          "link": "/guide/polygonize.md"
        },
        {
          "text": "面转线",
          "link": "/guide/polygonToLine.md"
        }
      ]
    },
    {
      "text": "其他",
      "items": [
        {
          "text": "生成椭圆",
          "link": "/guide/ellipse.md"
        },
        {
          "text": "返回相交点",
          "link": "/guide/kinks.md"
        },
        {
          "text": "线段圆弧化",
          "link": "/guide/lineArc.md"
        },
        {
          "text": "切割线段",
          "link": "/guide/lineChunk.md"
        },
        {
          "text": "计算线段相交",
          "link": "/guide/lineIntersect.md"
        },
        {
          "text": "计算线段重叠",
          "link": "/guide/lineOverlap.md"
        },
        {
          "text": "点集转化为线段",
          "link": "/guide/lineSegment.md"
        },
        {
          "text": "线段截取",
          "link": "/guide/lineSlice.md"
        },
        {
          "text": "沿线段切割",
          "link": "/guide/lineSliceAlong.md"
        },
        {
          "text": "线段分割",
          "link": "/guide/lineSplit.md"
        },
        {
          "text": "掩膜",
          "link": "/guide/mask.md"
        },
        {
          "text": "线上最近点",
          "link": "/guide/nearestPointOnLine.md"
        },
        {
          "text": "创建扇形",
          "link": "/guide/sector.md"
        },
        {
          "text": "最短路径",
          "link": "/guide/shortestPath.md"
        },
        {
          "text": "消除环形多边形",
          "link": "/guide/unkinkPolygon.md"
        }
      ]
    },
    {
      "text": "辅助函数",
      "items": [
        {
          "text": "要素集合",
          "link": "/guide/featureCollection.md"
        },
        {
          "text": "要素",
          "link": "/guide/feature.md"
        },
        {
          "text": "几何对象集合",
          "link": "/guide/geometryCollection.md"
        },
        {
          "text": "线段",
          "link": "/guide/lineString.md"
        },
        {
          "text": "多线段",
          "link": "/guide/multiLineString.md"
        },
        {
          "text": "多点",
          "link": "/guide/multiPoint.md"
        },
        {
          "text": "多边形集合",
          "link": "/guide/multiPolygon.md"
        },
        {
          "text": "点",
          "link": "/guide/point.md"
        },
        {
          "text": "多边形",
          "link": "/guide/polygon.md"
        }
      ]
    },
    {
      "text": "随机生成",
      "items": [
        {
          "text": "在指定的范围内生成随机坐标",
          "link": "/guide/randomPosition.md"
        },
        {
          "text": "在指定的范围内生成随机点位",
          "link": "/guide/randomPoint.md"
        },
        {
          "text": "在指定的范围内生成随机线",
          "link": "/guide/randomLineString.md"
        },
        {
          "text": "在指定的范围内生成随机多边形",
          "link": "/guide/randomPolygon.md"
        }
      ]
    },
    {
      "text": "数据处理",
      "items": [
        {
          "text": "返回指定数量的点",
          "link": "/guide/sample.md"
        }
      ]
    },
    {
      "text": "插值",
      "items": [
        {
          "text": "一组点之间进行插值计算",
          "link": "/guide/interpolate.md"
        },
        {
          "text": "等压线",
          "link": "/guide/isobands.md"
        },
        {
          "text": "等值线",
          "link": "/guide/isolines.md"
        },
        {
          "text": "平面上的点",
          "link": "/guide/planepoint.md"
        },
        {
          "text": "三角网格",
          "link": "/guide/tin.md"
        }
      ]
    },
    {
      "text": "连接",
      "items": [
        {
          "text": "多边形内的点",
          "link": "/guide/pointsWithinPolygon.md"
        },
        {
          "text": "标记",
          "link": "/guide/tag.md"
        }
      ]
    },
    {
      "text": "网格",
      "items": [
        {
          "text": "六边形网格",
          "link": "/guide/hexGrid.md"
        },
        {
          "text": "点网格",
          "link": "/guide/pointGrid.md"
        },
        {
          "text": "正方形网格",
          "link": "/guide/squareGrid.md"
        },
        {
          "text": "三角形网格",
          "link": "/guide/triangleGrid.md"
        }
      ]
    },
    {
      "text": "分类",
      "items": [
        {
          "text": "最近点",
          "link": "/guide/nearestPoint.md"
        }
      ]
    },
    {
      "text": "聚合",
      "items": [
        {
          "text": "收集",
          "link": "/guide/collect.md"
        },
        {
          "text": "基于DBSCAN算法的聚类",
          "link": "/guide/clustersDbscan.md"
        },
        {
          "text": "基于K-Means算法的聚类",
          "link": "/guide/clustersKmeans.md"
        }
      ]
    },
    {
      "text": "元数据",
      "items": [
        {
          "text": "获取几何对象的所有坐标",
          "link": "/guide/coordAll.md"
        },
        {
          "text": "遍历几何对象的所有坐标",
          "link": "/guide/coordEach.md"
        },
        {
          "text": "几何对象坐标缩减",
          "link": "/guide/coordReduce.md"
        },
        {
          "text": "遍历feature",
          "link": "/guide/featureEach.md"
        },
        {
          "text": "feature缩减",
          "link": "/guide/featureReduce.md"
        },
        {
          "text": "Flatten遍历",
          "link": "/guide/flattenEach.md"
        },
        {
          "text": "Flatten几何对象缩减",
          "link": "/guide/flattenReduce.md"
        },
        {
          "text": "获取给定几何对象的第n个坐标",
          "link": "/guide/getCoord.md"
        },
        {
          "text": "获取给定几何对象的所有坐标",
          "link": "/guide/getCoords.md"
        },
        {
          "text": "检索特定geometry的几何信息",
          "link": "/guide/getGeom.md"
        },
        {
          "text": "获取geometry的类型",
          "link": "/guide/getType.md"
        },
        {
          "text": "对几何对象迭代遍历",
          "link": "/guide/geomEach.md"
        },
        {
          "text": "几何对象归约",
          "link": "/guide/geomReduce.md"
        },
        {
          "text": "遍历属性值",
          "link": "/guide/propEach.md"
        },
        {
          "text": "属性归约",
          "link": "/guide/propReduce.md"
        },
        {
          "text": "遍历路径",
          "link": "/guide/segmentEach.md"
        },
        {
          "text": "路径归约",
          "link": "/guide/segmentReduce.md"
        },
        {
          "text": "遍历聚类簇",
          "link": "/guide/getCluster.md"
        },
        {
          "text": "遍历聚类簇",
          "link": "/guide/clusterEach.md"
        },
        {
          "text": "聚类簇对象归约",
          "link": "/guide/clusterReduce.md"
        }
      ]
    },
    {
      "text": "声明",
      "items": [
        {
          "text": "集合类型",
          "link": "/guide/collectionOf.md"
        },
        {
          "text": "坐标是否包含数字",
          "link": "/guide/containsNumber.md"
        },
        {
          "text": "检测geojson类型",
          "link": "/guide/geojsonType.md"
        },
        {
          "text": "feature对象类型判断",
          "link": "/guide/featureOf.md"
        }
      ]
    },
    {
      "text": "布尔函数",
      "items": [
        {
          "text": "判断坐标数组是否是顺时针方向",
          "link": "/guide/booleanClockwise.md"
        },
        {
          "text": "判断多边形是否是凹多边形",
          "link": "/guide/booleanConcave.md"
        },
        {
          "text": "判断是否包含",
          "link": "/guide/booleanContains.md"
        },
        {
          "text": "判断是否交叉",
          "link": "/guide/booleanCrosses.md"
        },
        {
          "text": "判断是否相离",
          "link": "/guide/booleanDisjoint.md"
        },
        {
          "text": "判断是否相等",
          "link": "/guide/booleanEqual.md"
        },
        {
          "text": "判断是否相交",
          "link": "/guide/booleanIntersects.md"
        },
        {
          "text": "判断是否重叠",
          "link": "/guide/booleanOverlap.md"
        },
        {
          "text": "判断是否平行",
          "link": "/guide/booleanParallel.md"
        },
        {
          "text": "判断点是否在多边形内",
          "link": "/guide/booleanPointInPolygon.md"
        },
        {
          "text": "判断点是否在线上",
          "link": "/guide/booleanPointOnLine.md"
        },
        {
          "text": "判断几何对象是否被另一个几何对象完全包含",
          "link": "/guide/booleanWithin.md"
        }
      ]
    },
    {
      "text": "单位转换",
      "items": [
        {
          "text": "方位角转换",
          "link": "/guide/bearingToAzimuth.md"
        },
        {
          "text": "面积单位转换",
          "link": "/guide/convertArea.md"
        },
        {
          "text": "长度单位转换",
          "link": "/guide/convertLength.md"
        },
        {
          "text": "将角度转换为弧度",
          "link": "/guide/degreesToRadians.md"
        },
        {
          "text": "将长度转换为弧度",
          "link": "/guide/lengthToRadians.md"
        },
        {
          "text": "将弧度转换为长度",
          "link": "/guide/radiansToLength.md"
        },
        {
          "text": "将弧度转换为角度",
          "link": "/guide/radiansToDegrees.md"
        },
        {
          "text": "转换为墨卡托投影",
          "link": "/guide/toMercator.md"
        },
        {
          "text": "转换为WGS84坐标系",
          "link": "/guide/toWgs84.md"
        }
      ]
    },
    {
      "text": "Examples",
      "items": [
        {
          "text": "Markdown Examples",
          "link": "/markdown-examples"
        },
        {
          "text": "Runtime API Examples",
          "link": "/api-examples"
        }
      ]
    }
  ],
  "socialLinks": [
    {
      "icon": "github",
      "link": "https://github.com/beerui/Luzhou-turf-cn"
    }
  ]
}

Page Data

{
  "title": "Runtime API Examples",
  "description": "",
  "frontmatter": {
    "outline": "deep"
  },
  "headers": [],
  "relativePath": "api-examples.md",
  "filePath": "api-examples.md",
  "lastUpdated": 1685266267000
}

Page Frontmatter

{
  "outline": "deep"
}

More

Check out the documentation for the full list of runtime APIs.