Polygon Geometry

viewer.entities.add({

                    polygon: {

                        hierarchy: Cesium.Cartesian3.fromDegreesArray(`[${newStr}]`

                        ),

                        material: Cesium.Color.RED,

                    },

                });

It’s not work but when i change [${newStr}] to [105.49979221347314, 20.994954320132283, 105.49955269297402, 20.99498788234124, 105.4994677940948, 20.99493045303432, 105.49942320801233, 20.994716751005587, 105.49937204716026, 20.994504336884123, 105.49931435465778, 20.9942933859599] it work, actually [${newStr}] is geometry from geocode features

Remember that what you add is a JSON blob of configuration data, there’s no inherit parser for any internal variables you might think of. Not sure where your ${newStr} comes from, nor what’s in it? Nor what you’re trying to achieve as such?

Cheers,

Alex

`var resource = new Cesium.Resource({

            url: endpoint,

            queryParameters: {

                where: `UPPER(qh_tenda) LIKE UPPER('%${input}%')`,

                outFields: "*",

                returnGeometry: true,

                resultRecordCount: 10,

                f: "geojson",

            },

        });


        return resource.fetchJson().then(function (results) {

            return results.features.map(function (resultObject) {
                var bboxDegrees = resultObject.geometry.coordinates[0];
                var newStr = JSON.stringify(results.features[0].geometry.coordinates[0]).replaceAll("[", "").replaceAll("]", "");`

I’m trying to change geojson to string to put into
`viewer.entities.add({

                    polygon: {

                        hierarchy: {

                            positions: Cesium.Cartesian3.fromDegreesArray(`[${newStr}]`),

                        },

                        material: Cesium.Color.BLUE.withAlpha(0.5),

                        height: 0,

                        outline: true, // height is required for outline to display

                    },`

i want to hightlight features

i’m want geometry results change to polygon

I’m sorry, but I’m having a hard time understanding what you’re after and doing. You got a GeoJSON, you pull out some coordinates, and then convert it to a string to inject into a JSON blob for entity creation?

A quick look at your code, I think you’ve got a few misconceptions about what is a string and what is JS. You pull out the coordinates into bboxDegrees, and as long as you’re happy they are WGS84 in degrees, all you have to do is;

    positions: Cesium.Cartesian3.fromDegreesArray( bboxDegrees )

But again, I might have misunderstood what you’re trying to do.

Cheers,

Alex

1 Like

thank you so much for your hard support !!

but i have another question, viewer.geocoder.viewModel.destinationFound = function flyToDestination(viewModel, toado) { console.log("He", toado); // copy code zoom to console.log("He", toado[0][0]); viewer.camera.flyTo({ destination: Cesium.Cartesian3.fromDegrees( toado[0][0], toado[0][1], 50, ), }); var redPolygon = viewer.entities.add({ polygon: { hierarchy: Cesium.Cartesian3.fromDegreesArray(toado.flat()), material: Cesium.Color.ORANGE.withAlpha(0.5), }, }); };
i want to remove older polygon when i create a new polygon from toado, can you help me?

Well, it’s fairly easy in the sense that;

  1. Make a global variable for the highlight entity
  2. Check if it exists, and delete if it does

So, in psuedo-code;

   var highlight = null;

   function flyTo( coords ) {
      if ( highlight ) {
         viewer.entities.remove(highlight);
      }
      highlight = viewer.entities.add({ ... });
   }

Cheers,

Alex

1 Like

thank you so much, let me try