geometry

AMD: require(["geoscene/geometry"], (geometry) => { /* 代码 */ });
ESM: import * as geometry from "@geoscene/core/geometry";
对象: geoscene/geometry
起始版本: GeoScene API for JavaScript 4.22

一个方便的模块,用于在使用 TypeScript 进行开发时导入 Geometry 类。例如,而不是像这样一次导入一个几何图形:

import Point from "geoscene/geometry/Point";
import Polygon from "geoscene/geometry/Polygon";
import Polyline from "geoscene/geometry/Polyline";

您可以使用此模块在一行上导入它们:

import { Point, Polygon, Polyline } from "geoscene/geometry";

此模块还允许您在几何图形上实现类型保护,从而使代码更智能。

import { Geometry } from "geoscene/geometry";

function logGeometry(geometry: Geometry): void {
  if (geometry.type === "point") {
    //4.6 的新功能,编译器知道几何是一个 Point 实例
    console.log("point coords: ", geometry.x, geometry.y, geometry.z);
  }
  else {
    // 编译器知道几何必须是 `Extent | Polygon | Multipoint | Polyline`
    console.log("The value is a geometry, but isn't a point.")
  }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.