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

feat(web): add playground example google 3d tiles #1368

Merged
merged 9 commits into from
Jan 23, 2025

Conversation

ShogoHirasawa
Copy link
Contributor

@ShogoHirasawa ShogoHirasawa commented Jan 23, 2025

Overview

Add a example of Google Photorealistic 3D Tiles in Mange Layer.
To run this script, User need API key. I added comment how to create Google API key in script.
image

What I've done

Add a example of Google Photorealistic 3D Tiles in Mange Layer

What I haven't done

MVT example in Manege Layer.

How I tested

I created Api key by myself and tested in local environment.

Which point I want you to review particularly

  • Whether comment in script is appropriate
  • Whether the script works well

Memo

Summary by CodeRabbit

  • New Features
    • Added a new plugin for integrating Google Photorealistic 3D Tiles into the application.
    • Introduced capability to add and visualize 3D map layers with Google Maps integration.
    • Enhanced the "Manage Layer" category with the new addGooglePhotorealistic3dTiles plugin.

Copy link

coderabbitai bot commented Jan 23, 2025

Walkthrough

This pull request introduces a new plugin for adding Google Photorealistic 3D Tiles to the Plugin Playground feature. The changes involve creating a new TypeScript file that defines the plugin with metadata and widget files, and updating the presets index to import and include the new plugin in the "Manage Layer" category. The implementation allows users to add Google Photorealistic 3D Tiles layers with a sample configuration and camera positioning.

Changes

File Change Summary
web/src/beta/features/PluginPlayground/Plugins/presets/index.ts Added import for addGooglePhotorealistic3dTiles from new layer module, included in "Manage Layer" category.
web/src/beta/features/PluginPlayground/Plugins/presets/layers/add-google-photorealistic-3d-tiles.ts New file creating plugin for Google Photorealistic 3D Tiles with YAML and widget files. Exported as addGooglePhotorealistic3dTiles.

Possibly related PRs

Suggested reviewers

  • mkumbobeaty
  • airslice

Poem

🌍 A Rabbit's Ode to 3D Tiles 🐰
In pixels deep and layers bright,
Google's world springs into sight,
Photorealistic magic unfurled,
A digital landscape, perfectly swirled!
Hop, hop, through dimensions new! 🌐


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 15ab911 and c77a997.

📒 Files selected for processing (1)
  • web/src/beta/features/PluginPlayground/Plugins/presets/index.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/beta/features/PluginPlayground/Plugins/presets/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Redirect rules - reearth-web
  • GitHub Check: Header rules - reearth-web
  • GitHub Check: Pages changed - reearth-web
  • GitHub Check: ci-server / ci-server-lint
  • GitHub Check: ci-web / ci
  • GitHub Check: ci-server / ci-server-test

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot requested a review from m-abe-dev January 23, 2025 05:40
Copy link

netlify bot commented Jan 23, 2025

Deploy Preview for reearth-web ready!

Name Link
🔨 Latest commit 4298aed
🔍 Latest deploy log https://app.netlify.com/sites/reearth-web/deploys/6792d52817d2fc00083c361d
😎 Deploy Preview https://deploy-preview-1368--reearth-web.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
web/src/beta/features/PluginPlayground/Plugins/presets/layers/add-google-photorealistic-3d-tiles.ts (2)

41-56: Improve camera positioning flexibility and documentation.

The current implementation has hardcoded coordinates and timing:

  1. Consider making the location configurable
  2. Add comments explaining the default location
  3. Consider dynamic duration based on distance
 // Move the camera to the position where the Google Photorealistic 3D Tiles data is displayed.
+// Default location: New York City, Manhattan area
+const defaultLocation = {
+  heading: 6.0671039802577384,
+  height: 1128.5794476956557,
+  lat: 40.730278427281455,
+  lng: -73.97291848442529,
+  pitch: -0.31010069674839325,
+  roll: 0.00004250447889830866,
+};
+
+// Helper to calculate optimal duration based on distance
+const calculateDuration = (currentPosition, targetPosition) => {
+  // Implementation to calculate duration based on distance
+  return 2.0; // Default fallback
+};
+
 reearth.camera.flyTo(
-  // Define the camera position to be moved to
-  {
-    heading: 6.0671039802577384,
-    height: 1128.5794476956557,
-    lat: 40.730278427281455,
-    lng: -73.97291848442529,
-    pitch: -0.31010069674839325,
-    roll: 0.00004250447889830866,
-  },
+  defaultLocation,
   // Define camera movement time
   {
-    duration: 2.0,
+    duration: calculateDuration(reearth.camera.position, defaultLocation),
   }
 );

1-63: Overall implementation feedback.

The implementation provides a good starting point for Google Photorealistic 3D Tiles integration. Based on your specific requests for feedback:

  1. Comments:

    • Current comments provide basic guidance
    • Enhanced documentation has been suggested for API key handling and location settings
  2. Performance:

    • Basic implementation is efficient
    • Suggested improvements for error handling and loading states will enhance reliability
    • Dynamic camera duration calculation will improve user experience

Consider these additional architectural improvements:

  1. Add TypeScript types for better type safety
  2. Implement a configuration system for customization
  3. Add event handlers for load/error states
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3290d0d and 322b03e.

📒 Files selected for processing (2)
  • web/src/beta/features/PluginPlayground/Plugins/presets/index.ts (2 hunks)
  • web/src/beta/features/PluginPlayground/Plugins/presets/layers/add-google-photorealistic-3d-tiles.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - reearth-web
  • GitHub Check: Header rules - reearth-web
  • GitHub Check: Pages changed - reearth-web
🔇 Additional comments (2)
web/src/beta/features/PluginPlayground/Plugins/presets/index.ts (1)

10-10: LGTM!

The new plugin is correctly imported and added to the layers category.

Also applies to: 57-57

web/src/beta/features/PluginPlayground/Plugins/presets/layers/add-google-photorealistic-3d-tiles.ts (1)

3-17: LGTM!

The YAML configuration is well-structured and contains all necessary metadata.

Comment on lines +30 to +34
googleMapApiKey: "put_your_api_key",
// This document explains how to create Photorealistic 3D Tiles API key.
// For more information on obtaining an API key, visit:
// https://developers.google.com/maps/documentation/tile/get-api-key
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance API key handling and documentation.

While the documentation link is helpful, consider these improvements:

  1. Use environment variables or a secure configuration system instead of hardcoding the API key
  2. Add comments about:
    • API key usage restrictions and quotas
    • Security best practices for key management
    • Local development setup instructions
   serviceTokens: {
-    googleMapApiKey: "put_your_api_key", 
+    googleMapApiKey: process.env.GOOGLE_MAPS_API_KEY || "YOUR_API_KEY_HERE",
     // This document explains how to create Photorealistic 3D Tiles API key. 
     // For more information on obtaining an API key, visit:
     // https://developers.google.com/maps/documentation/tile/get-api-key
+    // 
+    // Security Best Practices:
+    // 1. Never commit API keys to version control
+    // 2. Set appropriate API key restrictions in Google Cloud Console
+    // 3. Use environment variables for local development
+    // 
+    // Local Development:
+    // 1. Create a .env file in the project root
+    // 2. Add: GOOGLE_MAPS_API_KEY=your_actual_key
+    // 3. Ensure .env is in .gitignore
   },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
googleMapApiKey: "put_your_api_key",
// This document explains how to create Photorealistic 3D Tiles API key.
// For more information on obtaining an API key, visit:
// https://developers.google.com/maps/documentation/tile/get-api-key
},
googleMapApiKey: process.env.GOOGLE_MAPS_API_KEY || "YOUR_API_KEY_HERE",
// This document explains how to create Photorealistic 3D Tiles API key.
// For more information on obtaining an API key, visit:
// https://developers.google.com/maps/documentation/tile/get-api-key
//
// Security Best Practices:
// 1. Never commit API keys to version control
// 2. Set appropriate API key restrictions in Google Cloud Console
// 3. Use environment variables for local development
//
// Local Development:
// 1. Create a .env file in the project root
// 2. Add: GOOGLE_MAPS_API_KEY=your_actual_key
// 3. Ensure .env is in .gitignore
},

Comment on lines +25 to +39
const layerPhotorealistic3dTiles = {
type: "simple", // Required
data: {
type: "google-photorealistic", // Data type
serviceTokens: {
googleMapApiKey: "put_your_api_key",
// This document explains how to create Photorealistic 3D Tiles API key.
// For more information on obtaining an API key, visit:
// https://developers.google.com/maps/documentation/tile/get-api-key
},
},
};

// Add the Google Photorealistic 3D Tiles layer to Re:Earth
reearth.layers.add(layerPhotorealistic3dTiles);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling and loading state management.

The current implementation could benefit from improved robustness:

  1. Add error handling for API key validation
  2. Implement loading state management
  3. Add cleanup logic
 // Define Google Photorealistic 3D Tiles
+let layerId = null;
+
 const layerPhotorealistic3dTiles = {
   type: "simple", // Required
   data: {
     type: "google-photorealistic", // Data type
     serviceTokens: {
       googleMapApiKey: process.env.GOOGLE_MAPS_API_KEY || "YOUR_API_KEY_HERE",
     },
   },
+  // Add loading state visibility
+  visible: false,
 };

+// Validate API key
+const validateApiKey = (key) => {
+  if (!key || key === "YOUR_API_KEY_HERE") {
+    throw new Error("Invalid API key. Please configure a valid Google Maps API key.");
+  }
+};
+
+try {
+  validateApiKey(layerPhotorealistic3dTiles.data.serviceTokens.googleMapApiKey);
+
-// Add the Google Photorealistic 3D Tiles layer to Re:Earth
-reearth.layers.add(layerPhotorealistic3dTiles);
+  // Add the Google Photorealistic 3D Tiles layer to Re:Earth
+  layerId = reearth.layers.add(layerPhotorealistic3dTiles);
+
+  // Show layer after successful load
+  reearth.layers.overrideProperty(layerId, {
+    visible: true,
+  });
+} catch (error) {
+  console.error("Failed to initialize Google Photorealistic 3D Tiles:", error);
+}
+
+// Cleanup on unmount
+return () => {
+  if (layerId) {
+    reearth.layers.remove(layerId);
+  }
+};

Committable suggestion skipped: line range outside the PR's diff.

import { FileType, PluginType } from "../../constants";

const yamlFile: FileType = {
id: "layers-add-googlePhotorealistic3dTiles-reearth-yml",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id can be layers-add-google-photorealistic-3d-tiles-reearth-yml. Since we are using kebab case, we can change uppercase to lowercase.

Copy link
Contributor

@mulengawilfred mulengawilfred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Small comment on the id. Approved

@ShogoHirasawa ShogoHirasawa merged commit 778cfd7 into main Jan 23, 2025
16 of 17 checks passed
@ShogoHirasawa ShogoHirasawa deleted the feat/add-playground-example-google-3d-tiles branch January 23, 2025 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants