pickedPosition give me bad results of undefined

Hi all, I’m trying to follow after a map coordinates I’ve imported from geoServer to Cesium on the general globe,
I’ve found the pickedPostion method but seems it doesn’t work for me very well…
so far I’m getting by the console this message:

here is the code example:

import * as Cesium from "cesium";

import "cesium/Source/Widgets/widgets.css";

import "./DrawHelper.css";

import "./moreStyle.css";

import DrawHelper from "./DrawHelper";

const {

  defaultAccessToken,

  layersFromGeoServer,

  baseLayersFromGeoServer,

  tilesetFromGeoServer,

} = window["runConfig"];

class MapManager {

  constructor() {

    this._Viewer;

    this._drawHelper;

    this._scene;

    this.ellipsoid;

    this._homeLocation;

    this._contaner;

    this._entities;

    this._initializeCesium();

  }

  _initializeCesium() {

    Cesium.Ion.defaultAccessToken = defaultAccessToken;

    var layer = this.createWebMapServiceImageryProvider({

      url: baseLayersFromGeoServer.url,

      layers: baseLayersFromGeoServer.name,

    });

    this._Viewer = new Cesium.Viewer("cesiumContaner", {

      //sceneMode: Cesium.SceneMode.COLUMBUS_VIEW, // Make the worldmap 2D

      terrainProvider: Cesium.createWorldTerrain(),

      scene3DOnly: false, //new

      imageryProvider: layer, //

      baseLayerPicker: false,

      geocoder: true,

      timeline: true,

      infoBox: true,

      navigationHelpButton: false,

      shouldAnimate: false,

      animation: false,

    });

    this._drawHelper = new DrawHelper(this._Viewer);

    this._scene = this._Viewer.scene;

    this._entities = this._Viewer.entities;

    var handler = new Cesium.ScreenSpaceEventHandler(this._Viewer.canvas);

    handler.setInputAction(function (event) {

      console.log(event.position);

      var pickedPosition = this._scene.pickPosition(event.position);

      console.log(Cesium.defined(pickedPosition));

      console.log(pickedPosition);

      // if (Cesium.defined(pickedPosition)) {

      //   console.log(pickedPosition);

      // }

    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

Hi Aviv -

It’s hard to be certain without testing your code in a Sandcastle, but I believe the error happens on this line: var pickedPosition = this._scene.pickPosition(event.position);. I was able to get your code to work in this Sandcastle - on left click the console logs should be printed.

For reference, here is the original Picking Sandcastle that I used to make the one above. Let me know if that helps! Looks like your code is mostly correct but perhaps you are accessing the Scene from the wrong object.

Best,
Eli