zoomTo PrimitiveCollection

Hello,

Is it possible to zoom to a primitive or a primitive collection?

Greetings

Hello,

There isn’t a built-in way to zoom to a primitive the way you can zoom to an entity. I would recommend using the Entity API for creating your primtiives.

However, if you have a reason you don’t want to use entities, you can use the Camera.flyTo method to fly the camera to a certain position or a rectangle. If you have the positions for a polyline or polygon on the globe, you can use Rectangle.fromCartesianArray to create a rectangle that encloses these points.

Depending on what your data is, you may also want to consider finding a BoundingSphere for the primitive and using Camera.flyToBoundingSphere to zoom to it.

Best,

Hannah

I am trying to zoom to a gltf model which is loaded dynamically. No success so far.

Can you paste a code example showing what you’re trying to do?

-Hannah

Sure.

for (var i = 0; i < building_names.length; i++) {
  geoloc=buildings.getJsonByBuildingName(building_names[i]);
  // add to cesium
  var gltf_json = JSON.parse(gltfs[i]);
  var origin = Cesium.Cartesian3.fromDegrees(geoloc.longitude,geoloc.latitude,0);
  var matrix = Cesium.Transforms.eastNorthUpToFixedFrame(origin);
  var model = scene.primitives.add(new Cesium.Model({
    gltf : gltf_json,
    modelMatrix : matrix
  }));
}