Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add IonResource in resium ? #437

Closed
anotherhale opened this issue Sep 25, 2020 · 1 comment
Closed

How to add IonResource in resium ? #437

anotherhale opened this issue Sep 25, 2020 · 1 comment
Labels

Comments

@anotherhale
Copy link

I am trying to access a Cesium Ion Resource with my access token.

I have looked at this issue but could not get it to work:
#414

This JS code works in Cesium SandCastle:

// Grant CesiumJS access to your ion assets
Cesium.Ion.accessToken = "MY_ACCESS_TOKEN";

var viewer = new Cesium.Viewer("cesiumContainer", {
  terrainProvider: new Cesium.CesiumTerrainProvider({
    url: Cesium.IonResource.fromAssetId(1),
  }),
});
viewer.scene.globe.depthTestAgainstTerrain = true;

var tileset = viewer.scene.primitives.add(
  new Cesium.Cesium3DTileset({
    url: Cesium.IonResource.fromAssetId(96188),
  })
);

This is what I have:

import React from "react";
import { Viewer, Scene, Primitive, Cesium3DTileset, Globe } from "resium";
import { IonResource, CesiumTerrainProvider} from 'cesium';
const options = {defaultAccessToken: "MY_ACCESS_TOKEN"}
const ionTerrainProvider = IonResource.fromAssetId(1, options)
const terrainProvider = new CesiumTerrainProvider({url: ionTerrainProvider});
const MapView = () => {

  return (
    <Viewer full terrainProvider={terrainProvider} >
      <Scene>
        <Globe depthTestAgainstTerrain={true}></Globe>
        <Primitive>
          <Cesium3DTileset url={ IonResource.fromAssetId(96188, options) }/>    
        </Primitive>
      </Scene>
      
    </Viewer>
  );
};

export default MapView;

I am getting the following Error:
Uncaught Error: ForwardRef(Globe)(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.

@rot1024
Copy link
Member

rot1024 commented Sep 25, 2020

Please set access token outside a component with the normal JS way.

import { Ion } from 'cesium';

Ion.defaultAccessToken = "accesstoken";

export default function Component() {
  // ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants