This Code demonstrates how to find a specific layer in a Re-Earth project and temporarily update one of its properties.

const markerThatTitleIsReearth = reearth.layers.find(
    layer => layer.type === "marker" && layer.title === "Re:Earth"
);

if (markerThatTitleIsReearth) {
    // temporally update marker location
    reearth.layers.overrideProperty(markerThatTitleIsReearth.id, {
        default: {
            location: { lat: 100, lng: 0, height: 0 }
    }
    });
}

Using this code users can programmatically manipulate the properties of specific layers in the Re-Earth application.

Breakdown of the provided code:

  1. Finding a Layer:
  2. Checking if the Layer is Found:
  3. Updating the Layer's Property:
  4. Temporary Update:
  5. Persistence of Changes:
  6. Property Object Details:

Overall, this code snippet demonstrates a way to interact with and modify specific layers within a Re-Earth project dynamically. It provides a means to update a layer's properties temporarily based on certain conditions or user interactions.

Note that:

The result of reearth.layers.overrideProperty will not be saved permanently. This means that if you close or reload the page, the changes will be undone, and the properties of the layer will revert to the original values.

The details of the property object are not yet documented. To find out what properties can be overridden, you can inspect the current layer object by running reearth.layers.layers in the console of the developer tools. This will provide you with an object representing the current state of the layer, and you can explore its properties to determine which ones can be overridden.

const html = `
  <style>
    html, body {
      margin: 0;
      width: 350px;
      background: white;
    }
    #wrapper {
      height: 100%;
      padding: 12px;
      box-sizing: border-box;
    }
    input {
      width: 60px;
    }
  </style>

  <div id="wrapper">
    <p>Longitude: <input type="number" id="lng" value="139.78" />°</p>
    <p>Latitude: <input type="number" id="lat" value="35.68" />°</p>
    <p>Height: <input type="number" id="height" value="10000" /> m</p>
    <p>Heading: <input type="number" id="heading" value="0" step="0.1" /></p>
    <p>Pitch: <input type="number" id="pitch" value="-1.5" step="0.1" /></p>
    <p>Roll (for fly to): <input type="number" id="roll" value="0" step="0.1" /></p>
    <p>Range (for look at): <input type="number" id="range" value="10000" /> m</p>
    <p>Duration: <input type="number" id="duration" value="2" /> s</p>
    <p>
      <button id="fly">Fly to</button>
      <button id="look">Look at</button>
    </p>
  </div>

  <script>
    // Function to get input values
    const getValues = () => ({
      lng: parseFloat(document.getElementById("lng").value || 0),
      lat: parseFloat(document.getElementById("lat").value || 0),
      height: parseFloat(document.getElementById("height").value || 0),
      heading: parseFloat(document.getElementById("heading").value || 0),
      pitch: parseFloat(document.getElementById("pitch").value || 0),
      roll: parseFloat(document.getElementById("roll").value || 0),
      range: parseFloat(document.getElementById("range").value || 0),
      duration: parseFloat(document.getElementById("duration").value || 0),
    });

    // Event listener for "Fly to" button
    document.getElementById("fly").addEventListener("click", () => {
      parent.postMessage({ fly: getValues() }, "*");
    });

    // Event listener for "Look at" button
    document.getElementById("look").addEventListener("click", () => {
      parent.postMessage({ look: getValues() }, "*");
    });

    // Listen for messages from Re:Earth
    reearth.on("message", msg => {
      if (msg.fly) {
        // Perform camera flyTo
        reearth.camera.flyTo(
          {
            lat: msg.fly.lat,      
            lng: msg.fly.lng,      
            height: msg.fly.height,  
            heading: msg.fly.heading,
            pitch: msg.fly.pitch,    
            roll: msg.fly.roll,      
          },
          {
            duration: msg.fly.duration, 
          }
        );
      } else if (msg.look) {
        // Perform camera lookAt
        reearth.camera.lookAt(
          {
            lat: msg.look.lat,        
            lng: msg.look.lng,        
            height: msg.look.height,  
            heading: msg.look.heading,
            pitch: msg.look.pitch,    
            range: msg.look.range,    
          },
          {
            duration: msg.look.duration,
          }
        );
      }
    });
  </script>
`;

// Display the UI
reearth.ui.show(html);

The breakdown of the provided code