Search code examples
kmlcesiumjs

KML and altitude


I have the following KML file which is a cube =>

</Placemark>
<Style id="3Dobject">
    <PolyStyle>
        <color>7fff5500</color>
        <outline>1</outline>
        <fill>1</fill>
    </PolyStyle>
</Style>
<Placemark>
    <name>Warehouse01</name>
    <description>Warehouse Center:106.97777777 -6.19758333</description>
    <styleUrl>#3Dobject</styleUrl>
    <Polygon>
        <extrude>1</extrude>
        <tessellate>1</tessellate>
        <altitudeMode>absolute</altitudeMode>
        <outerBoundaryIs>
            <LinearRing>
                <coordinates>
                    106.9772778,-6.19808333,100
                    106.9782778,-6.19808333,100
                    106.9782778,-6.19708333,100
                    106.9772778,-6.19708333,100
                    106.9772778,-6.19808333,100
                </coordinates>
            </LinearRing>
        </outerBoundaryIs>
    </Polygon>
</Placemark>

I am trying to make this cube to be drawn 100meters above the ground. (

so basically =>

enter image description here

I tried adding an 100 but it always display from the botom.

I am using CESIUM.


Solution

  • Option 1: MultiGeometry with 6 polygons

    By definition extrude makes a geometry in KML connect to the ground. To create a 3-D cube above the ground then you must turn off extude and represent a polygon for each of the 6 faces of the cube.

    Example:

    <?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2">
    
    <Placemark>
      <name>Altitude PolyCube Example</name>
      <Style>
        <PolyStyle>
            <color>7fffffff</color>
        </PolyStyle>
      </Style>
      <MultiGeometry>
        <Polygon>
          <!-- bottom panel -->
          <altitudeMode>absolute</altitudeMode>
          <outerBoundaryIs>
            <LinearRing>
              <coordinates>
         106.9772778,-6.19808333,100
         106.9782778,-6.19808333,100
         106.9782778,-6.19708333,100
         106.9772778,-6.19708333,100
         106.9772778,-6.19808333,100
              </coordinates>
            </LinearRing>
          </outerBoundaryIs>
        </Polygon>
    
        <Polygon>
          <!-- top panel -->
          <altitudeMode>absolute</altitudeMode>
          <outerBoundaryIs>
            <LinearRing>
              <coordinates>
         106.9772778,-6.19808333,200
         106.9782778,-6.19808333,200
         106.9782778,-6.19708333,200
         106.9772778,-6.19708333,200
         106.9772778,-6.19808333,200
              </coordinates>
            </LinearRing>
          </outerBoundaryIs>
        </Polygon>
    
        <Polygon>
          <!-- left panel -->
          <altitudeMode>absolute</altitudeMode>
          <outerBoundaryIs>
            <LinearRing>
              <coordinates>
         106.9772778,-6.19808333,100
         106.9772778,-6.19808333,200
         106.9772778,-6.19708333,200
         106.9772778,-6.19708333,100
         106.9772778,-6.19808333,100
              </coordinates>
            </LinearRing>
          </outerBoundaryIs>
        </Polygon>
    
        <Polygon>
          <!-- right panel -->
          <altitudeMode>absolute</altitudeMode>
          <outerBoundaryIs>
            <LinearRing>
              <coordinates>
        106.9782778,-6.19808333,100
        106.9782778,-6.19808333,200
        106.9782778,-6.19708333,200
        106.9782778,-6.19708333,100
        106.9782778,-6.19808333,100
              </coordinates>
            </LinearRing>
          </outerBoundaryIs>
        </Polygon>
    
        <Polygon>
          <!-- front panel -->
          <altitudeMode>absolute</altitudeMode>
          <outerBoundaryIs>
            <LinearRing>
              <coordinates>
         106.9772778,-6.19808333,100
         106.9782778,-6.19808333,100
         106.9782778,-6.19808333,200
         106.9772778,-6.19808333,200
         106.9772778,-6.19808333,100
              </coordinates>
            </LinearRing>
          </outerBoundaryIs>
        </Polygon>
    
        <Polygon>
          <!-- back panel -->
          <altitudeMode>absolute</altitudeMode>
          <outerBoundaryIs>
            <LinearRing>
              <coordinates>
         106.9772778,-6.19708333,100
         106.9782778,-6.19708333,100
         106.9782778,-6.19708333,200
         106.9772778,-6.19708333,200
         106.9772778,-6.19708333,100
              </coordinates>
            </LinearRing>
          </outerBoundaryIs>
        </Polygon>
    
      </MultiGeometry>
    </Placemark>
    
    </kml>
    

    Option 2: KML and COLLADA Cube Model

    Given a generic cube model (which you can download at the 3D Warehouse), the KML can place a cube at a given location including at an altitude above ground.

    Option 3: Cesium

    Cesium using a Box geometry so can simply place a Box at a given altitude of 100 meters. For example see Cesium Sandcastle Box Demo.