Adding rotation and tilt controls to the map

Open in CodeSandbox

<!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="./common.ts"
    ></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">
      import {MMapControl} from '@mappable-world/mappable-types';
      import {ENABLED_BEHAVIORS} from './common';
      import {LOCATION} from '../variables';

      window.map = null;

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

          const {MMapRotateControl, MMapRotateTiltControl, MMapTiltControl} = await mappable.import(
              '@mappable-world/mappable-default-ui-theme'
          );

          class Tooltip extends mappable.MMapComplexEntity<{}> {
              private _element: HTMLDivElement;
              private _control: MMapControl;

              constructor() {
                  super({});
              }

              // Method for create a DOM control element
              _createElement() {
                  const tooltipElement = document.createElement('div');
                  tooltipElement.innerText = 'Click on the buttons on the right side';
                  tooltipElement.classList.add('tooltip');
                  return tooltipElement;
              }

              // Method for attaching the control to the map
              _onAttach() {
                  this._element = this._createElement();
                  this._control = new MMapControl({transparent: true}, this._element);
                  this.addChild(this._control);
              }
          }

          map = new MMap(document.getElementById('app'), {location: LOCATION, behaviors: ENABLED_BEHAVIORS}, [
              new MMapDefaultSchemeLayer({}),
              new MMapDefaultFeaturesLayer({})
          ]);

          map.addChild(new MMapControls({position: 'top left'}, [new Tooltip()]));

          map.addChild(
              new MMapControls({position: 'right'}, [
                  new MMapRotateTiltControl({}),
                  new MMapRotateControl({}),
                  new MMapTiltControl({})
              ])
          );
      }
    </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="./common.ts"
    ></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">
      import {ENABLED_BEHAVIORS} from './common';
      import {LOCATION} from '../variables';

      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, MMapControl} =
          reactify.module(mappable);

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

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

        function App() {
          return (
            <MMap
              location={reactify.useDefault(LOCATION)}
              behaviors={reactify.useDefault(ENABLED_BEHAVIORS)}
              ref={(x) => (map = x)}
            >
              <MMapDefaultSchemeLayer />
              <MMapDefaultFeaturesLayer />

              <MMapControls position="top left">
                <MMapControl transparent={true}>
                  <div className="tooltip">Click on the buttons on the right side</div>
                </MMapControl>
              </MMapControls>

              <MMapControls position="right">
                <MMapRotateTiltControl />
                <MMapRotateControl />
                <MMapTiltControl />
              </MMapControls>
            </MMap>
          );
        }
      }
    </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="./common.ts"
    ></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">
      import {ENABLED_BEHAVIORS} from './common';
      import {LOCATION} from '../variables';

      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, MMapControl} =
          vuefy.module(mappable);

        const {MMapRotateControl, MMapRotateTiltControl, MMapTiltControl} = vuefy.module(
          await mappable.import('@mappable-world/mappable-default-ui-theme')
        );

        const app = Vue.createApp({
          components: {
            MMap,
            MMapDefaultSchemeLayer,
            MMapDefaultFeaturesLayer,
            MMapControls,
            MMapControl,
            MMapRotateControl,
            MMapRotateTiltControl,
            MMapTiltControl
          },
          setup() {
            const refMap = (ref: any) => {
              window.map = ref?.entity;
            };
            return {LOCATION, ENABLED_BEHAVIORS, refMap};
          },
          template: `
            <MMap :location="LOCATION" :behaviors="ENABLED_BEHAVIORS" :ref="refMap">
                <MMapDefaultSchemeLayer />
                <MMapDefaultFeaturesLayer />

                <MMapControls position="top left">
                    <MMapControl :transparent="true">
                        <div class="tooltip">Click on the buttons on the right side</div>
                    </MMapControl>
                </MMapControls>
                <MMapControls position="right">
                    <MMapRotateTiltControl />
                    <MMapRotateControl />
                    <MMapTiltControl />
                </MMapControls>
            </MMap>`
        });
        app.mount('#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>
.tooltip {
  padding: 8px 12px 8px 32px;

  font-size: 14px;
  line-height: 20px;

  color: #f2f5fa;
  border-radius: 8px;
  background-color: #313133;
  background-image: url('./info-icon.svg');
  background-repeat: no-repeat;
  background-position: 3% 50%;
  gap: 8px;
}
import type {MMapLocationRequest, LngLatBounds, BehaviorType} from '@mappable-world/mappable-types';

mappable.ready.then(() => {
  mappable.import.registerCdn('https://cdn.jsdelivr.net/npm/{package}', [
    '@mappable-world/mappable-default-ui-theme@0.0'
  ]);
});

export const ENABLED_BEHAVIORS: BehaviorType[] = ['drag', 'scrollZoom', 'dblClick', 'mouseTilt', 'mouseRotate'];
import type {MMapLocationRequest} from '@mappable-world/mappable-types';

export const LOCATION: MMapLocationRequest = {
  center: [55.2744, 25.1972], // starting position [lng, lat]
  zoom: 9 // starting zoom
};