MMapFeature

The MMapFeature class is an object component on the map. It can be displayed as a polyline or a polygon depending on the geometry type.

Usage example

Polyline

Type: LineString.

Usage example:

const lineStringFeature = new MMapFeature({
  id: 'line',
  source: 'featureSource',
  geometry: {
    type: 'LineString',
    coordinates: [
      [25.1229762, 55.189311],
      [25.329762, 55.389311]
    ]
  },
  style: {
    stroke: [{width: 12, color: 'rgb(14, 194, 219)'}]
  }
});

map.addChild(lineStringFeature);

Polygon

Type: Polygon.

Usage example:

const polygonFeature = new MMapFeature({
  id: 'polygon',
  source: 'featureSource',
  geometry: {
    type: 'Polygon',
    coordinates: [
      [
        [25.029762, 55.189311],
        [25.229762, 55.289311],
        [25.329762, 55.389311]
      ]
    ]
  },
  style: {
    stroke: [{width: 6, color: 'rgb(14, 194, 219)'}],
    fill: 'rgba(56, 56, 219, 0.5)'
  }
});

map.addChild(polygonFeature);

Circle

To create a circle in GeoJSON, you can use the Turf library.

Usage example:

<!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>

    <script crossorigin src="https://cdn.jsdelivr.net/npm/@turf/turf@7"></script>

    <!-- For the map to appear, you need to add your API key -->
    <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">
      import {
        CIRCLE_CENTER,
        CIRCLE_DASHED_CENTER,
        CIRCLE_DASHED_STYLE,
        CIRCLE_RADIUS,
        CIRCLE_STYLE,
        CIRCLE_WITHOUT_STROKE_CENTER,
        CIRCLE_WITHOUT_STROKE_STYLE,
        LOCATION,
        getCircleGeoJSON
      } from '../variables';

      window.map = null;

      main();
      async function main() {
        // Waiting for all API elements to load
        await mappable.ready;
        const {MMap, MMapDefaultSchemeLayer, MMapDefaultFeaturesLayer, MMapFeature} = mappable;

        // Initialize the map
        map = new MMap(
          // Pass a link to the HTML element of the container
          document.getElementById('app'),
          // Pass the map initialization parameters
          {location: LOCATION, showScaleInCopyrights: true},
          // Add a map scheme layer
          [new MMapDefaultSchemeLayer({}), new MMapDefaultFeaturesLayer({})]
        );

        // Create a default circle
        const circle = new MMapFeature({
          geometry: getCircleGeoJSON(CIRCLE_CENTER, CIRCLE_RADIUS),
          style: CIRCLE_STYLE
        });
        map.addChild(circle);

        // Create a circle using custom styles
        const circleDashed = new MMapFeature({
          geometry: getCircleGeoJSON(CIRCLE_DASHED_CENTER, CIRCLE_RADIUS),
          style: CIRCLE_DASHED_STYLE
        });
        map.addChild(circleDashed);

        // Create a circle without a stroke
        const circleWithoutStroke = new MMapFeature({
          geometry: getCircleGeoJSON(CIRCLE_WITHOUT_STROKE_CENTER, CIRCLE_RADIUS),
          style: CIRCLE_WITHOUT_STROKE_STYLE
        });

        map.addChild(circleWithoutStroke);
      }
    </script>

    <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>
  </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>

    <script crossorigin src="https://cdn.jsdelivr.net/npm/@turf/turf@7"></script>

    <!-- For the map to appear, you need to add your API key -->
    <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="react, typescript"
      type="text/babel"
      src="../variables.ts"
    ></script>
    <script data-plugins="transform-modules-umd" data-presets="react, typescript" type="text/babel">
      import {
        CIRCLE_CENTER,
        CIRCLE_DASHED_CENTER,
        CIRCLE_DASHED_STYLE,
        CIRCLE_RADIUS,
        CIRCLE_STYLE,
        CIRCLE_WITHOUT_STROKE_CENTER,
        CIRCLE_WITHOUT_STROKE_STYLE,
        LOCATION,
        getCircleGeoJSON
      } from '../variables';

      window.map = null;

      main();
      async function main() {
        // For every object in the JS API, there is a React analog
        // To use the React version of the API, enable the @mappable-world/mappable-reactify module
        const [mappableReact] = await Promise.all([mappable.import('@mappable-world/mappable-reactify'), mappable.ready]);
        const reactify = mappableReact.reactify.bindTo(React, ReactDOM);
        const {MMap, MMapDefaultSchemeLayer, MMapDefaultFeaturesLayer, MMapFeature} = reactify.module(mappable);
        const {useMemo} = React;

        function App() {
          const circleGeometry = useMemo(() => getCircleGeoJSON(CIRCLE_CENTER, CIRCLE_RADIUS), []);
          const circleDashedGeometry = useMemo(() => getCircleGeoJSON(CIRCLE_DASHED_CENTER, CIRCLE_RADIUS), []);
          const circleWithoutStrokeGeometry = useMemo(
            () => getCircleGeoJSON(CIRCLE_WITHOUT_STROKE_CENTER, CIRCLE_RADIUS),
            []
          );
          return (
            // Initialize the map and pass the initialization parameters
            <MMap location={LOCATION} showScaleInCopyrights={true} ref={(x) => (map = x)}>
              {/* Add a map scheme layer */}
              <MMapDefaultSchemeLayer />
              <MMapDefaultFeaturesLayer />
              <MMapFeature geometry={circleGeometry} style={CIRCLE_STYLE} />
              <MMapFeature geometry={circleDashedGeometry} style={CIRCLE_DASHED_STYLE} />
              <MMapFeature geometry={circleWithoutStrokeGeometry} style={CIRCLE_WITHOUT_STROKE_STYLE} />
            </MMap>
          );
        }

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

    <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>
  </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 crossorigin src="https://cdn.jsdelivr.net/npm/@turf/turf@7"></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">
      import {
        CIRCLE_CENTER,
        CIRCLE_DASHED_CENTER,
        CIRCLE_DASHED_STYLE,
        CIRCLE_RADIUS,
        CIRCLE_STYLE,
        CIRCLE_WITHOUT_STROKE_CENTER,
        CIRCLE_WITHOUT_STROKE_STYLE,
        LOCATION,
        getCircleGeoJSON
      } from '../variables';

      window.map = null;

      async function main() {
        // For every object in the JS API, there is a Vue analog
        // To use the Vue API version, enable the @mappable-world/mappable-vuefy module
        const [mappableVue] = await Promise.all([mappable.import('@mappable-world/mappable-vuefy'), mappable.ready]);
        const vuefy = mappableVue.vuefy.bindTo(Vue);
        const {MMap, MMapDefaultSchemeLayer, MMapDefaultFeaturesLayer, MMapFeature} = vuefy.module(mappable);

        const app = Vue.createApp({
          components: {MMap, MMapDefaultSchemeLayer, MMapDefaultFeaturesLayer, MMapFeature},
          setup() {
            const refMap = (ref) => {
              window.map = ref?.entity;
            };
            const circleGeometry = Vue.ref(getCircleGeoJSON(CIRCLE_CENTER, CIRCLE_RADIUS));
            const circleDashedGeometry = Vue.ref(getCircleGeoJSON(CIRCLE_DASHED_CENTER, CIRCLE_RADIUS));
            const circleWithoutStrokeGeometry = Vue.ref(
              getCircleGeoJSON(CIRCLE_WITHOUT_STROKE_CENTER, CIRCLE_RADIUS)
            );
            return {
              LOCATION,
              CIRCLE_CENTER,
              CIRCLE_DASHED_CENTER,
              CIRCLE_DASHED_STYLE,
              CIRCLE_WITHOUT_STROKE_STYLE,
              CIRCLE_WITHOUT_STROKE_CENTER,
              CIRCLE_STYLE,
              circleGeometry,
              circleDashedGeometry,
              circleWithoutStrokeGeometry,
              refMap
            };
          },
          template: `
            <MMap :location="LOCATION" :showScaleInCopyrights="true" :ref="refMap">
                <MMapDefaultSchemeLayer />
                <MMapDefaultFeaturesLayer />
                <MMapFeature :geometry="circleGeometry" :style="CIRCLE_STYLE" />
                <MMapFeature :geometry="circleDashedGeometry" :style="CIRCLE_DASHED_STYLE" />
                <MMapFeature :geometry="circleWithoutStrokeGeometry" :style="CIRCLE_WITHOUT_STROKE_STYLE" />
            </MMap>`
        });
        app.mount('#app');
      }
      main();
    </script>

    <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>
  </head>
  <body>
    <div id="app"></div>
  </body>
</html>
import type {DrawingStyle, LngLat, PolygonGeometry, MMapLocationRequest} from '@mappable-world/mappable-types';

declare global {
  const turf: typeof import('@turf/turf');
}

export const LOCATION: MMapLocationRequest = {
  center: [37.623082, 55.75254], // initial position [lng, lat]
  zoom: 12 // initial scale
};

export const CIRCLE_CENTER: LngLat = [37.618536, 55.760257];
export const CIRCLE_RADIUS = 1500;
export const CIRCLE_STYLE: DrawingStyle = {simplificationRate: 0};

export const CIRCLE_DASHED_CENTER: LngLat = [37.608301, 55.738633];
export const CIRCLE_DASHED_STYLE: DrawingStyle = {
  simplificationRate: 0,
  stroke: [{color: '#006efc', width: 4, dash: [5, 10]}],
  fill: 'rgba(56, 56, 219, 0.5)'
};

export const CIRCLE_WITHOUT_STROKE_CENTER: LngLat = [37.660536, 55.730257];
export const CIRCLE_WITHOUT_STROKE_STYLE: DrawingStyle = {simplificationRate: 0, stroke: []};

export const getCircleGeoJSON = (center: LngLat, radiusMeters: number): PolygonGeometry => {
  const {geometry} = turf.circle(center, radiusMeters, {units: 'meters'});
  return geometry as PolygonGeometry;
};

Constructor

new MMapFeature(props)

Constructor parameters

Parameter

Type

props

MMapFeatureProps

Redefines

MMapEntity.constructor

Props

MMapFeatureProps: {
	disableRoundCoordinates?: boolean;
	geometry: Geometry;
	hideOutsideViewport?: HideOutsideRule;
	id?: string;
	properties?: Record<string, unknown>;
	source?: string;
	style?: DrawingStyle
} & DraggableProps<MMapFeatureEventHandler> & BlockingProps & FeatureClickEvents

Methods

update

update(changedProps): void

Parameters

Parameter

Type

Description

changedProps

Partial<MMapFeatureProps>

New props values.

Returns

void

Inherited from

MMapEntity.update