Skip to content

Unable to toggle between 2d and 3d #1309

@dayercher005

Description

@dayercher005

I'm using the open layers for a 2d map whilst using olcs library to toggle between the 3d map with google's photorealistic tiles and back to the 2d map. In the initial render, I'm able to get the 2d map and 3d map depending on the initial boolean used in the setEnabled function in the docs. However, upon subsequent changes to the setEnabled function by changing the enabled Prop, I'm able to switch to the 3d version but not back to the 2d map.
Code shown below:

const Map3DViewer = ({ enabled }: Props) => {
  const mapElement = useRef<HTMLDivElement | undefined>(undefined);
  useEffect(() => {
    window.Cesium = Cesium;
    const map = Map.getInstance();  // open layers 2d map
    if (mapElement.current) {
      const newMap = new OLCesium({ map: map }); // getting 3d map using ol-cesium library
      const scene = newMap.getCesiumScene();
      if (enabled) {
        newMap.setEnabled(enabled);
        async function addPhotorealisticTiles() {
          try {
            const tileset = await Cesium.Cesium3DTileset.fromUrl(
              APIKey,
              { showCreditsOnScreen: true }
            );
            scene.primitives.add(tileset);
          } catch (error) {
            console.error(`Error loading tileset: ${error}`);
          }
        }
        addPhotorealisticTiles();
      } else {
        newMap.setEnabled(false);
      }
    }
    // cleanup so OL detaches listeners when this component unmounts
    return () => {
      map.setTarget(undefined);
    };
  });

In the console, there is a type error that saysUncaught TypeError: CesiumWorkers.incrementallyBuildTerrainPicker is not a function. Anyone encountered this issue before and knows how to address it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions