Skip to content

Commit

Permalink
add zoom and geolocation controls (#4)
Browse files Browse the repository at this point in the history
Add new controls:
* Zoom control
* Geolocation control
  • Loading branch information
matthew44-mappable authored Apr 10, 2024
1 parent f961dd5 commit 488f91d
Show file tree
Hide file tree
Showing 44 changed files with 1,241 additions and 206 deletions.
2 changes: 1 addition & 1 deletion example/case-template/vue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function main() {
MMapButtonExample
},
setup() {
const refMap = (ref) => {
const refMap = (ref: any) => {
window.map = ref?.entity;
};
const onClick = () => alert('Click!');
Expand Down
26 changes: 0 additions & 26 deletions example/common.css

This file was deleted.

Empty file.
8 changes: 8 additions & 0 deletions example/geolocation-control/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type {MMapLocationRequest, LngLatBounds} from '@mappable-world/mappable-types';

const BOUNDS: LngLatBounds = [
[54.58311, 25.9985],
[56.30248, 24.47889]
];

export const LOCATION: MMapLocationRequest = {bounds: BOUNDS};
37 changes: 37 additions & 0 deletions example/geolocation-control/react/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!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="../../index.ts"
></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="../../index.css" />
<link rel="stylesheet" href="../common.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
38 changes: 38 additions & 0 deletions example/geolocation-control/react/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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} = React;

const {MMapGeolocationControl} = reactify.module(
await mappable.import('@mappable-world/mappable-default-ui-theme')
);

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('app')
);

function App() {
const [location] = useState(LOCATION);

return (
<MMap location={location} ref={(x) => (map = x)}>
<MMapDefaultSchemeLayer />
<MMapDefaultFeaturesLayer />
<MMapControls position="right">
<MMapGeolocationControl />
</MMapControls>
</MMap>
);
}
}
35 changes: 35 additions & 0 deletions example/geolocation-control/vanilla/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!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="react, typescript"
type="text/babel"
src="../../index.ts"
></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="../../index.css" />
<link rel="stylesheet" href="../common.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
17 changes: 17 additions & 0 deletions example/geolocation-control/vanilla/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {LOCATION} from '../common';
window.map = null;

main();
async function main() {
await mappable.ready;
const {MMap, MMapDefaultSchemeLayer, MMapDefaultFeaturesLayer, MMapControls} = mappable;

const {MMapGeolocationControl} = await mappable.import('@mappable-world/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 MMapGeolocationControl({})));
}
36 changes: 36 additions & 0 deletions example/geolocation-control/vue/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!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="react, typescript"
type="text/babel"
src="../../index.ts"
></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="../../index.css" />
<link rel="stylesheet" href="../common.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
39 changes: 39 additions & 0 deletions example/geolocation-control/vue/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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 {MMapGeolocationControl} = vuefy.module(await mappable.import('@mappable-world/mappable-default-ui-theme'));

const app = Vue.createApp({
components: {
MMap,
MMapDefaultSchemeLayer,
MMapDefaultFeaturesLayer,
MMapControls,
MMapGeolocationControl
},
setup() {
const refMap = (ref: any) => {
window.map = ref?.entity;
};
const onClick = () => alert('Click!');
return {LOCATION, refMap, onClick};
},
template: `
<MMap :location="LOCATION" :ref="refMap">
<MMapDefaultSchemeLayer />
<MMapDefaultFeaturesLayer />
<MMapControls position="right">
<MMapGeolocationControl />
</MMapControls>
</MMap>`
});
app.mount('#app');
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {BehaviorType, LngLatBounds, MMapBoundsLocation} from '@mappable-world/mappable-types';

mappable.import.loaders.unshift(async (pkg) => {
if (!pkg.startsWith('@mappable-world/mappable-default-ui-theme')) {
return;
Expand All @@ -12,12 +14,10 @@ mappable.import.loaders.unshift(async (pkg) => {
return window['@mappable-world/mappable-default-ui-theme'];
});

const BOUNDS = [
const BOUNDS: LngLatBounds = [
[54.58311, 25.9985],
[56.30248, 24.47889]
];

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const LOCATION = {bounds: BOUNDS};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const ENABLED_BEHAVIORS = ['drag', 'scrollZoom', 'dblClick', 'mouseTilt', 'mouseRotate'];
export const LOCATION: MMapBoundsLocation = {bounds: BOUNDS};
export const ENABLED_BEHAVIORS: BehaviorType[] = ['drag', 'scrollZoom', 'dblClick', 'mouseTilt', 'mouseRotate'];
67 changes: 0 additions & 67 deletions example/rotate-tilt-controls/react.html

This file was deleted.

36 changes: 36 additions & 0 deletions example/rotate-tilt-controls/react/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!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="../../index.ts"
></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="../../index.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
Loading

0 comments on commit 488f91d

Please sign in to comment.