MapConductor React SDK Samples

Store Map | MapKit | MapConductor React SDK

MapConductor React SDK Store Map sample using MapKit.

This interactive example demonstrates the Store Map feature through the MapConductor abstraction on MapKit.

Code example

import { useMemo, useState } from 'react';
import {
  createGeoPoint,
  createMapCameraPosition,
  createMarkerState,
  type MarkerState,
} from '@mapconductor/js-sdk-core';
import { InfoBubble, Markers } from '@mapconductor/js-sdk-react';
import { MapKitMapDesign, MapKitMapView, useMapKitViewState } from '@mapconductor/react-for-mapkit';


function StoreInfoView({ store }: { store: { name: string; address: string } }) {
  return <article><h3>{store.name}</h3><p>{store.address}</p></article>;
}


export default function App() {
  // (1) Create the map


  const initialCamera = createMapCameraPosition({
    position: createGeoPoint({ latitude: 35.6812, longitude: 139.7671 }),
    zoom: 12,
  });


  const mapViewState = useMapKitViewState({
    token: 'YOUR_MAPKIT_TOKEN',
    mapDesignType: MapKitMapDesign.Standard,
    cameraPosition: initialCamera,
  });


  // (2) Prepare the data and interaction state
  const stores = useMemo(() => [
    { id: 'tokyo', name: 'Tokyo Store', address: 'Tokyo Station', lat: 35.6812, lng: 139.7671 },
    { id: 'ginza', name: 'Ginza Store', address: 'Ginza, Tokyo', lat: 35.6717, lng: 139.7650 },
  ], []);
  const [selectedMarker, setSelectedMarker] = useState<MarkerState | null>(null);
  const storeMarkers = useMemo(() => stores.map(store => createMarkerState({
    id: store.id,
    position: createGeoPoint({ latitude: store.lat, longitude: store.lng }),
    extra: store,
    onClick: markerState => setSelectedMarker(markerState),
  })), [stores]);
  const clearSelection = () => setSelectedMarker(null);


  // (3) Render the map and its overlays


  return (
    <div style={{ height: 500, position: 'relative', display: 'flex', flexDirection: 'column' }}>
      <MapKitMapView state={mapViewState} onMapClick={clearSelection}>
        <Markers states={storeMarkers} />
        {selectedMarker && (
          <InfoBubble marker={selectedMarker}>
            <StoreInfoView store={selectedMarker.extra as (typeof stores)[number]} />
          </InfoBubble>
        )}
      </MapKitMapView>
    </div>
  );
}

How the code works

Render a collection of store markers in one composition and show an information bubble for the selected store.

The storeMarkers array is built once with useMemo: each createMarkerState keeps its store record in the extra field and an onClick handler that saves the tapped MarkerState, while onMapClick clears the selection.

The batched <Markers> component draws every store in a single pass, and the InfoBubble is anchored to the selected marker so StoreInfoView appears only while a store is chosen.