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): plugin playground preset plugin add geojson #1344

Merged
merged 20 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PluginType } from "../constants";
import { myPlugin } from "./custom/myPlugin";
import { responsivePanel } from "./ui/responsivePanel";
import { sidebar } from "./ui/sidebar";
import { addGeojson } from "./layers/add-geojson";

type PresetPluginCategory = {
id: string;
Expand All @@ -22,5 +23,10 @@ export const presetPlugins: PresetPlugins = [
id: "ui",
title: "UI",
plugins: [responsivePanel, sidebar]
},
{
id: "layers",
title: "layers",
plugins: [addGeojson]
}
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { FileType, PluginType } from "../../constants";

const yamlFile: FileType = {
id: "layers-add-geojson",
title: "reearth.yml",
sourceCode: `id: layers-add-geojson
name: Add GeoJSON
version: 1.0.0
extensions:
- id: add geojson
type: widget
name: Add Geojson
description: Add Geojson
widgetLayout:
defaultLocation:
zone: outer
section: left
area: top
`,
disableEdit: true,
disableDelete: true
};

const widgetFile: FileType = {
id: "layers-add-geojson",
title: "layers-add-geojson.js",
sourceCode: `// Example of adding a layer with GeoJSON data

// Difine the polygon with inline
const layerGeojsonInline = {
id:"feature001", // A unique identifier for the layer
type: "simple", // Must be written
data: {
type: "geojson", // Write the data format
value: {
// Ensure that "value" contains GeoJSON
type: "FeatureCollection",
features: [
{
type: "Feature",
properties: {},
geometry: {
type: "Polygon",
coordinates: [
[
[-97.52842673316115, 28.604966534790364],
[-97.52842673316115, 10.990084521105842],
[-82.13620852840572, 10.990084521105842],
[-82.13620852840572, 28.604966534790364],
[-97.52842673316115, 28.604966534790364],
],
],
},
},
],
},
},
polygon: {}, // Settings for the feature style. This statement is required even if no style is set.
};

// Difine the polygon with URL
const layerGeojsonFromUrl = {
id:"feature002",
type: "simple",
data: {
type: "geojson",
url: "https://reearth.github.io/visualizer-plugin-sample-data/public/geojson/square.geojson", // URL of GeoJSON file
},
polygon: {},
};

// Add the inline GeoJSON layer to Re:Earth
reearth.layers.add(layerGeojsonInline);

// Add the GeoJSON layer from the URL to Re:Earth
reearth.layers.add(layerGeojsonFromUrl);
`
};

export const addGeojson: PluginType = {
id: "add-geojson",
title: "Add GeoJSON",
files: [widgetFile, yamlFile]
};