Skip to content

Commit

Permalink
Update examples (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
abstractalgo authored Nov 2, 2023
1 parent afc56ec commit b3e1b3a
Show file tree
Hide file tree
Showing 22 changed files with 3,444 additions and 29 deletions.
16 changes: 16 additions & 0 deletions typescript-examples/annotations-example/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @type import('eslint').Linter.Config */
module.exports = {
root: true,
env: {browser: true, es2020: true},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended'
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': ['warn', {allowConstantExport: true}]
}
};
24 changes: 24 additions & 0 deletions typescript-examples/annotations-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
.yarn
1 change: 1 addition & 0 deletions typescript-examples/annotations-example/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
35 changes: 35 additions & 0 deletions typescript-examples/annotations-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Map SDK annotations example

This example demonstrates how to manipulate annotations on the map and rich-text editing capabilities.

This is an example for Foursquare's [Map SDK](https://location.foursquare.com/developer/docs/studio-map-sdk-introduction) that allows you to programmatically render [Foursquare Studio](https://studio.foursquare.com/) maps within your website and with your own data.

The project was bootstrapped with [Vite](https://vitejs.dev/guide/).

## Available Scripts

In the project directory, you can run:

### `yarn dev`

Runs the app in the development mode.\
By default, the app is available at [http://localhost:5173](http://localhost:5173/) in your browser.

The page will reload when you make edits.\
You will also see any lint errors in the console.

### `yarn build`

Builds and bundles the app for production into the `dist` folder.

### `yarn preview`

Runs a server to locally preview the production build.

If you don't use `yarn dev`, you likely would want to use `yarn build` and `yarn preview` together.

## Learn More

You can learn more about [setting up a React app with Vite](https://react.dev/learn/add-react-to-an-existing-project) and on the official [Vite webiste](https://vitejs.dev/guide/).

To learn React, check out the [React documentation](https://react.dev/).
12 changes: 12 additions & 0 deletions typescript-examples/annotations-example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="/fsq-favicon.png" />
<title>Annotations Example</title>
</head>
<body>
<script type="module" src="/src/index.tsx"></script>
<div id="root"></div>
</body>
</html>
30 changes: 30 additions & 0 deletions typescript-examples/annotations-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "annotations-example",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@unfolded/map-sdk": "^1.13.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/eslint": "^8.44.2",
"@types/react": "^18.2.18",
"@types/react-dom": "^18.2.7",
"@typescript-eslint/eslint-plugin": "^6.2.1",
"@typescript-eslint/parser": "^6.2.1",
"@vitejs/plugin-react": "^4.0.4",
"eslint": "^8.46.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"typescript": "^5.2.2",
"vite": "^4.4.9"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions typescript-examples/annotations-example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { FC, useEffect, useRef } from "react";
import { createMap } from "@unfolded/map-sdk";
import { editorContent } from "./editor-content";

export const App: FC = () => {
const containerRef = useRef<HTMLDivElement>(null);

useEffect(() => {
const initMap = async () => {
const map = await createMap({
container: containerRef.current!,
});

map.addAnnotation({
id: "my-annotation",
kind: "POINT",
isVisible: true,
autoSize: true,
autoSizeY: true,
anchorPoint: [-122.4194, 37.7749],
label: "Richtext annotation",
editorState: editorContent,
lineColor: "#C32899",
lineWidth: 5,
textWidth: 167.2265625,
textHeight: 75,
textVerticalAlign: "bottom",
armLength: 50,
angle: -45,
});
};

initMap();
}, []);

return <div id="map-container" ref={containerRef}></div>;
};
164 changes: 164 additions & 0 deletions typescript-examples/annotations-example/src/editor-content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
// this is a serialized content of Lexical editor (https://lexical.dev/)
// it supports various font and style customizations
export const editorContent = {
root: {
children: [
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "This is ",
type: "text",
version: 1,
},
{
detail: 0,
format: 1,
mode: "normal",
style: "",
text: "bold, ",
type: "text",
version: 1,
},
{
detail: 0,
format: 2,
mode: "normal",
style: "",
text: "italic",
type: "text",
version: 1,
},
{
detail: 0,
format: 1,
mode: "normal",
style: "",
text: ", ",
type: "text",
version: 1,
},
{
detail: 0,
format: 8,
mode: "normal",
style: "",
text: "underline",
type: "text",
version: 1,
},
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: ".",
type: "text",
version: 1,
},
{
type: "linebreak",
version: 1,
},
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: "Link",
type: "text",
version: 1,
},
],
direction: "ltr",
format: "",
indent: 0,
type: "link",
version: 1,
rel: "noopener noreferrer",
target: "_blank",
url: "https://studio.foursquare.com",
},
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: ", ",
type: "text",
version: 1,
},
{
detail: 0,
format: 0,
mode: "normal",
style: "color: #C90000;",
text: "red text",
type: "text",
version: 1,
},
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: ", ",
type: "text",
version: 1,
},
{
detail: 0,
format: 0,
mode: "normal",
style: "background-color: #52A353;",
text: "green bg",
type: "text",
version: 1,
},
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: ".",
type: "text",
version: 1,
},
],
direction: "ltr",
format: "",
indent: 0,
type: "paragraph",
version: 1,
},
{
children: [
{
detail: 0,
format: 11,
mode: "normal",
style: "color: #C90000;background-color: #52A353;",
text: "All styles",
type: "text",
version: 1,
},
],
direction: "ltr",
format: "",
indent: 0,
type: "paragraph",
version: 1,
},
],
direction: "ltr",
format: "",
indent: 0,
type: "root",
version: 1,
},
};
10 changes: 10 additions & 0 deletions typescript-examples/annotations-example/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
body {
margin: 0;
padding: 0;
}

#map-container {
width: 100vw;
height: 100vh;
overflow: hidden;
}
5 changes: 5 additions & 0 deletions typescript-examples/annotations-example/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {createRoot} from 'react-dom/client';
import './index.css';
import {App} from './App';

createRoot(document.getElementById('root')!).render(<App />);
25 changes: 25 additions & 0 deletions typescript-examples/annotations-example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src/**/*"],
"references": [{ "path": "./tsconfig.node.json" }]
}
10 changes: 10 additions & 0 deletions typescript-examples/annotations-example/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
7 changes: 7 additions & 0 deletions typescript-examples/annotations-example/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {defineConfig} from 'vite';
import react from '@vitejs/plugin-react';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()]
});
Loading

0 comments on commit b3e1b3a

Please sign in to comment.