customize label

Hi,

In the following sample code, you can see a handler for the "mouse move" event.

What i want?

This sample code is working only "move" event. I want the same functionality with the click-through (LEFT_CLICK) event.

I get the following error when I change the event as I want.

Error :
ncaught DeveloperError: windowPosition is undefined.
Error
    at new DeveloperError (https://cesiumjs.org/Cesium/Source/Core/DeveloperError.js:43:19)
    at Scene.pick (https://cesiumjs.org/Cesium/Source/Scene/Scene.js:3232:19)
    at <anonymous>:43:38
    at handleMouseUp (https://cesiumjs.org/Cesium/Source/Core/ScreenSpaceEventHandler.js:225:21)
    at handlePointerUp (https://cesiumjs.org/Cesium/Source/Core/ScreenSpaceEventHandler.js:624:13)
    at HTMLCanvasElement.listener (https://cesiumjs.org/Cesium/Source/Core/ScreenSpaceEventHandler.js:67:13) (on line 3232 of https://cesiumjs.org/Cesium/Source/Scene/Scene.js)

finally, how do I set the color and label div size (margin command in css) of the label? so the background is gray. I want to make it red.

Code example :
var viewer = new Cesium.Viewer('cesiumContainer', {
    selectionIndicator : false,
    infoBox : false
});

var scene = viewer.scene;
var handler;
  
Sandcastle.addToolbarButton('Pick position', function() {
    var modelEntity = viewer.entities.add({
        name : 'milktruck',
        position : Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706),
        model : {
            uri : '../../SampleData/models/CesiumMilkTruck/CesiumMilkTruck-kmc.gltf'
        }
    });
    viewer.zoomTo(modelEntity);

    var labelEntity = viewer.entities.add({
        label : {
            show : false,
            showBackground : true,
            font : '14px monospace',
            horizontalOrigin : Cesium.HorizontalOrigin.LEFT,
            verticalOrigin : Cesium.VerticalOrigin.TOP,
            pixelOffset : new Cesium.Cartesian2(25, 0),
                scaleByDistance : new Cesium.NearFarScalar(1.2e2, 1.5, 1.5e7, 0.5)

        }
    });

    // Mouse over the globe to see the cartographic position
    handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
    handler.setInputAction(function(movement) {

        var foundPosition = false;

        var scene = viewer.scene;
        if (scene.mode !== Cesium.SceneMode.MORPHING) {
            var pickedObject = scene.pick(movement.endPosition);
            if (scene.pickPositionSupported && Cesium.defined(pickedObject) && pickedObject.id === modelEntity) {
                var cartesian = viewer.scene.pickPosition(movement.endPosition);

                if (Cesium.defined(cartesian)) {
                    var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
                    var longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(2);
                    var latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(2);
                    var heightString = cartographic.height.toFixed(2);

                    labelEntity.position = cartesian;
                    labelEntity.label.show = true;
                    labelEntity.label.text =
                        'Lon: ' + (' ' + longitudeString).slice(-7) + '\u00B0' +
                        '\nLat: ' + (' ' + latitudeString).slice(-7) + '\u00B0' +
                        '\nAlt: ' + (' ' + heightString).slice(-7) + 'm';
                  labelEntity.label.eyeOffset = new Cesium.Cartesian3(0.0, 0.0, -cartographic.height * (scene.mode === Cesium.SceneMode.SCENE2D ? 1.5 : 1.0));

                    foundPosition = true;
                }
            }
        }

        if (!foundPosition) {
            labelEntity.label.show = false;
        }
    }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
});

Sandcastle.reset = function() {
    viewer.entities.removeAll();
    handler = handler && handler.destroy();
};

The handler function for the LEFT_CLICK event has a different object passed to it than the MOUSE_MOVE event: Use movement.position instead of movement.endPosition.

handler.setInputAction(function(movement) {

   var position = movement.position;

}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

``

Thanks,

Gabby