Measurements by the ruler of the package with the default UI theme
vanilla.html
react.html
vue.html
common.ts
variables.ts
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<script crossorigin src="https://cdn.jsdelivr.net/npm/@babel/standalone@7/babel.min.js"></script>
<!-- To make the map appear, you must add your apikey -->
<script src="https://js.api.mappable.world/v3/?apikey=<YOUR_APIKEY>&lang=en_US" type="text/javascript"></script>
<script
data-plugins="transform-modules-umd"
data-presets="typescript"
type="text/babel"
src="../variables.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">
import {RulerType} from '@mappable-world/mappable-types/modules/ruler';
import {LOCATION, RULER_COORDINATES} from '../variables';
window.map = null;
main();
async function main() {
// Waiting for all api elements to be loaded
await mappable.ready;
const {MMap, MMapDefaultSchemeLayer, MMapControlButton, MMapControls} = mappable;
const {MMapDefaultRuler} = await mappable.import('@mappable-world/mappable-default-ui-theme');
// Initialize the map
map = new MMap(
// Pass the link to the HTMLElement of the container
document.getElementById('app'),
// Pass the map initialization parameters
{location: LOCATION, showScaleInCopyrights: true},
// Add a map scheme layer
[new MMapDefaultSchemeLayer({})]
);
let editable = true;
let rulerType: RulerType = 'ruler';
const ruler = new MMapDefaultRuler({
type: rulerType,
editable,
points: RULER_COORDINATES,
onFinish: () => {
editable = false;
}
});
map.addChild(ruler);
map.addChild(
new MMapControls({position: 'top right'}, [
new MMapControlButton({
text: 'Switch edit ruler',
onClick: () => {
editable = !editable;
ruler.update({editable});
}
})
])
);
map.addChild(
new MMapControls({position: 'top left'}, [
new MMapControlButton({
text: 'Switch ruler type',
onClick: () => {
rulerType = rulerType === 'ruler' ? 'planimeter' : 'ruler';
ruler.update({type: rulerType});
}
})
])
);
}
</script>
<!-- prettier-ignore -->
<style> html, body, #app { width: 100%; height: 100%; margin: 0; padding: 0; font-family: Arial, Helvetica, sans-serif; } .toolbar { position: absolute; z-index: 1000; top: 0; left: 0; display: flex; align-items: center; padding: 16px; } .toolbar a { padding: 16px; } </style>
<link rel="stylesheet" href="./common.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<script crossorigin src="https://cdn.jsdelivr.net/npm/react@17/umd/react.production.min.js"></script>
<script crossorigin src="https://cdn.jsdelivr.net/npm/react-dom@17/umd/react-dom.production.min.js"></script>
<script crossorigin src="https://cdn.jsdelivr.net/npm/@babel/standalone@7/babel.min.js"></script>
<!-- To make the map appear, you must add your apikey -->
<script src="https://js.api.mappable.world/v3/?apikey=<YOUR_APIKEY>&lang=en_US" type="text/javascript"></script>
<script
data-plugins="transform-modules-umd"
data-presets="typescript"
type="text/babel"
src="../variables.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">
import {RulerType} from '@mappable-world/mappable-types/modules/ruler';
import {LOCATION, RULER_COORDINATES} from '../variables';
window.map = null;
main();
async function main() {
// For each object in the JS API, there is a React counterpart
// To use the React version of the API, include the module @mappable-world/mappable-reactify
const [mappableReact] = await Promise.all([
mappable.import('@mappable-world/mappable-reactify'),
mappable.ready
]);
const reactify = mappableReact.reactify.bindTo(React, ReactDOM);
const {MMap, MMapDefaultSchemeLayer, MMapControls, MMapControlButton} = reactify.module(mappable);
const {MMapDefaultRuler} = reactify.module(
await mappable.import('@mappable-world/mappable-default-ui-theme')
);
const {useState, useCallback} = React;
function App() {
const [location] = useState(LOCATION);
const [rulerCoordinates] = useState(RULER_COORDINATES);
const [rulerType, setRulerType] = useState < RulerType > 'ruler';
const [editable, setEditable] = useState(true);
const switchEditable = useCallback(() => setEditable((editable) => !editable), []);
const switchType = useCallback(
() => setRulerType((rulerType) => (rulerType === 'ruler' ? 'planimeter' : 'ruler')),
[]
);
const onFinish = useCallback(() => setEditable(false), []);
return (
// Initialize the map and pass initialization parameters
<MMap location={location} showScaleInCopyrights={true} ref={(x) => (map = x)}>
{/* Add a map scheme layer */}
<MMapDefaultSchemeLayer />
<MMapDefaultRuler type={rulerType} points={rulerCoordinates} editable={editable} onFinish={onFinish} />
<MMapControls position="top right">
<MMapControlButton onClick={switchEditable} text="Switch edit ruler" />
</MMapControls>
<MMapControls position="top left">
<MMapControlButton onClick={switchType} text="Switch ruler type" />
</MMapControls>
</MMap>
);
}
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('app')
);
}
</script>
<!-- prettier-ignore -->
<style> html, body, #app { width: 100%; height: 100%; margin: 0; padding: 0; font-family: Arial, Helvetica, sans-serif; } .toolbar { position: absolute; z-index: 1000; top: 0; left: 0; display: flex; align-items: center; padding: 16px; } .toolbar a { padding: 16px; } </style>
<link rel="stylesheet" href="./common.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<script crossorigin src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.js"></script>
<script crossorigin src="https://cdn.jsdelivr.net/npm/@babel/standalone@7/babel.min.js"></script>
<script src="https://js.api.mappable.world/v3/?apikey=<YOUR_APIKEY>&lang=en_US" type="text/javascript"></script>
<script
data-plugins="transform-modules-umd"
data-presets="typescript"
type="text/babel"
src="../variables.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">
import {RulerType} from '@mappable-world/mappable-types/modules/ruler';
import {LOCATION, RULER_COORDINATES} from '../variables';
window.map = null;
async function main() {
// For each object in the JS API, there is a Vue counterpart
// To use the Vue version of the API, include the module @mappable-world/mappable-vuefy
const [mappableVue] = await Promise.all([mappable.import('@mappable-world/mappable-vuefy'), mappable.ready]);
const vuefy = mappableVue.vuefy.bindTo(Vue);
const {MMap, MMapDefaultSchemeLayer, MMapControls, MMapControlButton} = vuefy.module(mappable);
const {MMapDefaultRuler} = vuefy.module(await mappable.import('@mappable-world/mappable-default-ui-theme'));
const app = Vue.createApp({
components: {MMap, MMapDefaultSchemeLayer, MMapControls, MMapControlButton, MMapDefaultRuler},
setup() {
const refMap = (ref) => {
window.map = ref?.entity;
};
const editable = Vue.ref(true);
const rulerType = Vue.ref < RulerType > 'ruler';
const switchEditable = () => {
editable.value = !editable.value;
};
const switchType = () => {
rulerType.value = rulerType.value === 'ruler' ? 'planimeter' : 'ruler';
};
const onFinish = () => {
editable.value = false;
};
return {LOCATION, RULER_COORDINATES, refMap, editable, rulerType, switchEditable, switchType, onFinish};
},
template: `
<MMap :location="LOCATION" :showScaleInCopyrights="true" :ref="refMap">
<MMapDefaultSchemeLayer />
<MMapDefaultRuler :type="rulerType" :points="RULER_COORDINATES" :editable="editable" :onFinish="onFinish" />
<MMapControls position="top right">
<MMapControlButton @click="switchEditable" text="Switch edit ruler" />
</MMapControls>
<MMapControls position="top left">
<MMapControlButton @click="switchType" text="Switch ruler type" />
</MMapControls>
</MMap>`
});
app.mount('#app');
}
main();
</script>
<!-- prettier-ignore -->
<style> html, body, #app { width: 100%; height: 100%; margin: 0; padding: 0; font-family: Arial, Helvetica, sans-serif; } .toolbar { position: absolute; z-index: 1000; top: 0; left: 0; display: flex; align-items: center; padding: 16px; } .toolbar a { padding: 16px; } </style>
<link rel="stylesheet" href="./common.css" />
</head>
<body>
<div id="app"></div>
</body>
</html>
mappable.ready.then(() => {
mappable.import.registerCdn('https://cdn.jsdelivr.net/npm/{package}', [
'@mappable-world/mappable-default-ui-theme@0.0'
]);
});
import type {LngLat, MMapLocationRequest} from '@mappable-world/mappable-types';
export const LOCATION: MMapLocationRequest = {
center: [31.245384, 30.051434], // starting position [lng, lat]
zoom: 3 // starting zoom
};
export const RULER_COORDINATES: LngLat[] = [
[-0.128407, 51.506807], // London
[31.245384, 30.051434], // Cairo
[77.201224, 28.614653] // New Delhi
];