-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert example from vanilla to typescript
- Loading branch information
1 parent
b391715
commit 8acdca5
Showing
17 changed files
with
549 additions
and
148 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type {MMapLocationRequest, LngLatBounds} from '@mappable-world/mappable-types'; | ||
|
||
mappable.import.loaders.unshift(async (pkg) => { | ||
if (!pkg.startsWith('mappable-default-ui-theme')) { | ||
return; | ||
} | ||
|
||
if (location.href.includes('localhost')) { | ||
await mappable.import.script(`/dist/index.js`); | ||
} else { | ||
await mappable.import.script(`https://unpkg.com/${pkg}/dist/index.js`); | ||
} | ||
// @ts-ignore | ||
return window['mappable-default-ui-theme']; | ||
}); | ||
|
||
const BOUNDS: LngLatBounds = [ | ||
[54.58311, 25.9985], | ||
[56.30248, 24.47889] | ||
]; | ||
|
||
export const LOCATION: MMapLocationRequest = {bounds: BOUNDS}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>React example mappable-default-ui-theme</title> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||
<script crossorigin src="https://unpkg.com/react@17/umd/react.production.min.js"></script> | ||
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script> | ||
<script crossorigin src="https://unpkg.com/@babel/standalone@7/babel.min.js"></script> | ||
<script src="https://js.api.mappable.world/3.0/?apikey=%APIKEY%&lang=en_US"></script> | ||
|
||
<script | ||
data-plugins="transform-modules-umd" | ||
data-presets="react, typescript" | ||
type="text/babel" | ||
src="../common.ts" | ||
></script> | ||
<script | ||
data-plugins="transform-modules-umd" | ||
data-presets="react, typescript" | ||
type="text/babel" | ||
src="./index.tsx" | ||
></script> | ||
|
||
<link rel="stylesheet" href="../common.css" /> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {LOCATION} from '../common'; | ||
|
||
window.map = null; | ||
|
||
main(); | ||
async function main() { | ||
const [mappableReact] = await Promise.all([mappable.import('@mappable-world/mappable-reactify'), mappable.ready]); | ||
const reactify = mappableReact.reactify.bindTo(React, ReactDOM); | ||
|
||
const {MMap, MMapDefaultSchemeLayer, MMapDefaultFeaturesLayer, MMapControls} = reactify.module(mappable); | ||
|
||
const {useState, useCallback} = React; | ||
|
||
const {MMapZoomControl} = reactify.module(await mappable.import('@mappable-world/[email protected]')); | ||
|
||
const {MMapButtonExample} = reactify.module(await mappable.import('mappable-default-ui-theme')); | ||
|
||
ReactDOM.render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode>, | ||
document.getElementById('app') | ||
); | ||
|
||
function App() { | ||
const [location, setLocation] = useState(LOCATION); | ||
const onClick = useCallback(() => alert('Click!'), []); | ||
|
||
return ( | ||
<MMap location={location} ref={(x) => (map = x)}> | ||
<MMapDefaultSchemeLayer /> | ||
<MMapDefaultFeaturesLayer /> | ||
<MMapControls position="right"> | ||
<MMapZoomControl /> | ||
<MMapButtonExample text={'My button'} onClick={onClick} /> | ||
</MMapControls> | ||
</MMap> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"strict": false, | ||
"rootDirs": ["./", "../"], | ||
"types": ["./types.d.ts", "../types/index.d.ts"] | ||
}, | ||
"include": ["./**/*.ts", "./**/*.tsx"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {MMap} from '@mappable-world/mappable-types'; | ||
|
||
declare global { | ||
const React: typeof import('react'); | ||
const ReactDOM: typeof import('react-dom'); | ||
const Vue: typeof import('@vue/runtime-dom'); | ||
let map: MMap; | ||
|
||
interface Window { | ||
map: MMap; | ||
} | ||
} | ||
|
||
export {}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Vanilla example mappable-default-ui-theme</title> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||
<script crossorigin src="https://unpkg.com/@babel/standalone@7/babel.min.js"></script> | ||
<script src="https://js.api.mappable.world/3.0/?apikey=%APIKEY%&lang=en_US"></script> | ||
|
||
<script | ||
data-plugins="transform-modules-umd" | ||
data-presets="typescript" | ||
type="text/babel" | ||
src="../common.ts" | ||
></script> | ||
<script | ||
data-plugins="transform-modules-umd" | ||
data-presets="typescript" | ||
type="text/babel" | ||
src="./index.ts" | ||
></script> | ||
|
||
<link rel="stylesheet" href="../common.css" /> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {LOCATION} from '../common'; | ||
window.map = null; | ||
|
||
main(); | ||
async function main() { | ||
await mappable.ready; | ||
const {MMap, MMapDefaultSchemeLayer, MMapDefaultFeaturesLayer, MMapControls} = mappable; | ||
|
||
const {MMapZoomControl} = await mappable.import('@mappable-world/[email protected]'); | ||
const {MMapButtonExample} = await mappable.import('mappable-default-ui-theme'); | ||
|
||
map = new MMap(document.getElementById('app'), {location: LOCATION}); | ||
|
||
map.addChild(new MMapDefaultSchemeLayer({})); | ||
map.addChild(new MMapDefaultFeaturesLayer({})); | ||
|
||
map.addChild( | ||
new MMapControls({position: 'right'}) | ||
.addChild(new MMapZoomControl({})) | ||
.addChild(new MMapButtonExample({text: 'My button', onClick: () => alert('Click!')})) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Vue example mappable-default-ui-theme</title> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||
<script crossorigin src="https://unpkg.com/vue@3/dist/vue.global.js"></script> | ||
<script crossorigin src="https://unpkg.com/@babel/standalone@7/babel.min.js"></script> | ||
<script src="https://js.api.mappable.world/3.0/?apikey=%APIKEY%&lang=en_US"></script> | ||
|
||
<script | ||
data-plugins="transform-modules-umd" | ||
data-presets="typescript" | ||
type="text/babel" | ||
src="../common.ts" | ||
></script> | ||
<script | ||
data-plugins="transform-modules-umd" | ||
data-presets="typescript" | ||
type="text/babel" | ||
src="./index.ts" | ||
></script> | ||
|
||
<link rel="stylesheet" href="../common.css" /> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {LOCATION} from '../common'; | ||
|
||
window.map = null; | ||
|
||
main(); | ||
async function main() { | ||
const [mappableVue] = await Promise.all([mappable.import('@mappable-world/mappable-vuefy'), mappable.ready]); | ||
const vuefy = mappableVue.vuefy.bindTo(Vue); | ||
|
||
const {MMap, MMapDefaultSchemeLayer, MMapDefaultFeaturesLayer, MMapControls} = vuefy.module(mappable); | ||
|
||
const {MMapZoomControl} = vuefy.module(await mappable.import('@mappable-world/[email protected]')); | ||
|
||
const {MMapButtonExample} = vuefy.module(await mappable.import('mappable-default-ui-theme')); | ||
|
||
const app = Vue.createApp({ | ||
components: { | ||
MMap, | ||
MMapDefaultSchemeLayer, | ||
MMapDefaultFeaturesLayer, | ||
MMapControls, | ||
MMapZoomControl, | ||
MMapButtonExample | ||
}, | ||
setup() { | ||
const refMap = (ref) => { | ||
window.map = ref?.entity; | ||
}; | ||
const onClick = () => alert('Click!'); | ||
return {LOCATION, refMap, onClick}; | ||
}, | ||
template: ` | ||
<MMap :location="LOCATION" :ref="refMap"> | ||
<MMapDefaultSchemeLayer /> | ||
<MMapDefaultFeaturesLayer /> | ||
<MMapControls position="right"> | ||
<MMapZoomControl /> | ||
<MMapButtonExample text="My button" :onClick="onClick" /> | ||
</MMapControls> | ||
</MMap>` | ||
}); | ||
app.mount('#app'); | ||
} |
Oops, something went wrong.