zoukankan      html  css  js  c++  java
  • cesium 获取 多边形 polygon 中心点,给 polygon 加label

    先获取多边形的 中线点

    var viewer = new Cesium.Viewer("cesiumContainer");
    var polygon = viewer.entities.add({
      name: "Red polygon on surface",
      polygon: {
        hierarchy: Cesium.Cartesian3.fromDegreesArray([-115.0,37.0,-115.0,32.0,-107.0,33.0,-102.0,31.0,-102.0,35.0, ]),
        material: Cesium.Color.RED.withAlpha(0.5),
      },
    });
    var polyPositions = polygon.hierarchy.getValue(Cesium.JulianDate.now()).positions;
    var polyCenter = Cesium.BoundingSphere.fromPoints(polyPositions).center;//中心点
    polyCenter = Cesium.Ellipsoid.WGS84.scaleToGeodeticSurface(polyCenter);
    // 添加label
    redPolygon.label={
        position: polyCenter,
        text:'polygon title',
        color : Cesium.Color.fromCssColorString('#fff'),
        font:'normal 32px MicroSoft YaHei',
        showBackground : true,
        scale : 0.5,
        color: Cesium.Color.fromCssColorString('#fff'),
        font: 'normal 32px MicroSoft YaHei',
        showBackground: true,
        scale: 0.5,
        verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
        horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
        heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
    };
    viewer.zoomTo(viewer.entities);

    这里的中心点是世界坐标,如果要经纬度坐标还需要转换,如下:

    let cartographic = Cesium.Cartographic.fromCartesian(polyCenter, viewer.scene.globe.ellipsoid, new Cesium.Cartographic());
    let lat = Cesium.Math.toDegrees(cartographic.latitude);
    let lng = Cesium.Math.toDegrees(cartographic.longitude);
    let height = cartographic.height;
  • 相关阅读:
    SOJ 2785_Binary Partitions
    Codeforces Round #328 (Div. 2)
    C++ fill 和memset
    SOJ 2749_The Fewest Coins
    Codeforces Round #327 (Div. 2)
    TYVJ P1013 找啊找啊找GF Label:动态规划
    TYVJ 1014 乘法游戏
    TYVJ 1011 NOIP 2008&&NOIP 2000 传纸条&&方格取数 Label:多线程dp
    错误集合
    TYVJ P1038/P1039 忠诚 标签:线段树
  • 原文地址:https://www.cnblogs.com/bruce-gou/p/14314575.html
Copyright © 2011-2022 走看看