MapillaryJS Documentation

website·Indexed 30 days ago

https://mapillary.github.io/mapillary-js/

A JavaScript library for rendering and interacting with street-level imagery. The documentation covers core concepts, API references for the Viewer and components, extension guides for WebGL and Three.js custom renderers, and migration guides for versions v2.x, v3.x, and v4.x.

Tokens
58.7K
Snippets
387
Records
578
Agent score
73%

What's inside MapillaryJS

  1. Overview of MapillaryJS Visualization Component

    MapillaryJS is a client-side JavaScript library used to build street imagery map experiences on the web. It renders spatial, semantic, and texture data using WebGL, allowing users to navigate imagery at street level or from a bird's eye view within an undistorted virtual 3D world.
  2. Overview of MapillaryJS

    MapillaryJS is a client-side JavaScript library used to build interactive street imagery map experiences in web browsers. It acts as a 3D counterpart to traditional 2D maps, allowing users to navigate street-level imagery (captured at eye-height) in an undistorted virtual 3D world. It can be used as a standalone component or paired with a 2D map in a web application.
  3. Handle mouse events in mapillary-js using ViewerMouseEvent

    The ViewerMouseEvent interface is used for mouse-related viewer events (such as click, dblclick, mousemove, etc.). It extends ViewerEvent and provides spatial data about where the event occurred, including geographic coordinates, pixel positions, and image-relative coordinates.
    // Set up an event listener on the viewer
    viewer.on('click', function(e) {
      // e is a ViewerMouseEvent
      console.log('A click event has occurred at ' + e.lngLat);
    });
  4. Implement a custom data provider using IDataProvider

    The IDataProvider interface is a specification for implementers to model data provider behavior. It extends EventEmitter and is typically implemented by classes that extend DataProviderBase. It provides a standardized way to fetch image buffers, tiles, and cluster data.
  5. Handle camera pose and viewpoint events

    Viewpoint events provide information about the camera's orientation. The bearing event is fired when the viewing direction changes. The event object contains a bearing property. For more detailed camera pose data, use viewer.getPointOfView() to access the PointOfView object, which includes bearing and tilt properties.
    const viewer = new Viewer({accessToken, container});
    
    // Listen to bearing changes directly via event property
    viewer.on('bearing', (event) => {
      console.log(`'${event.type}' - bearing: ${event.bearing}`);
    });
    
    // Listen to POV changes and use getPointOfView()
    viewer.on('pov', async () => {
      const pov = await viewer.getPointOfView();
      console.log(`Bearing: ${pov.bearing}, Tilt: ${pov.tilt}`);
    });
  6. Use the BearingComponent to indicate bearing and field of view

    The BearingComponent is a UI component used to display the current bearing and field of view. It can be retrieved from the Viewer instance using the component name bearing.
    var viewer = new Viewer({ ... });
    var bearingComponent = viewer.getComponent("bearing");
    bearingComponent.configure({ size: ComponentSize.Small });
  7. Use TouchZoomHandler to manage pinch-to-zoom

    The TouchZoomHandler allows users to zoom the viewer image by pinching on a touchscreen. It is typically accessed via the pointer component of the viewer.
    var pointerComponent = viewer.getComponent("pointer");
    // Access the touchZoom handler
    pointerComponent.touchZoom.enable();
    pointerComponent.touchZoom.disable();
  8. Use KeySequenceNavigationHandler for image sequence navigation

    The KeySequenceNavigationHandler provides keyboard shortcuts to navigate through an image sequence. The supported key commands are:

    • ALT + Up Arrow: Navigate to the next image in the sequence.
    • ALT + Down Arrow: Navigate to the previous image in the sequence.
    var keyboardComponent = viewer.getComponent("keyboard");
    // Access the handler via keyboardComponent.keySequenceNavigation
  9. Control keyboard zooming with KeyZoomHandler

    The KeyZoomHandler allows users to zoom in and out of the viewer using the + (zoom in) and - (zoom out) keys. It is accessed via the keyboard component of the viewer.
    var keyboardComponent = viewer.getComponent("keyboard");
    // Enable or disable the zoom handler
    keyboardComponent.keyZoom.enable();
    keyboardComponent.keyZoom.disable();
    
    // Check if zooming is currently enabled
    var isEnabled = keyboardComponent.keyZoom.isEnabled;
  10. Use DragPanHandler to control image panning

    The DragPanHandler allows users to pan the viewer image by clicking and dragging the cursor. It is typically accessed via the pointer component of the viewer.
    var pointerComponent = viewer.getComponent("pointer");
    // Access the dragPan handler
    var dragPan = pointerComponent.dragPan;