For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt, and this page is available as Markdown at /next/api/elements/built-in/map.md.
Lynx
  • English
  • <map> 4.5 experimental XElement

    The <map> element embeds a native map. Place a <map-marker> directly inside it to anchor Lynx content to a geographic coordinate. Add the map package to each native host and use the same ReactLynx component across platforms.

    A <map-marker> stays at its position as the user pans or zooms. Give the marker a width and height, and use its Lynx children to draw its content. 4.5 experimental

    Add a marker

    Give the map a height. Both center and position take coordinates in degrees. The marker's anchor identifies the point within its bounds that sits on the coordinate. For example, [0.5, 0.5] centers the label there.

    Tap one of the five photo markers to center the map and see the landmark up close. Choose Next stop to continue along the waterfront or All stops to return to the overview. Scan the QR code with a Lynx Explorer build that includes the native map provider.

    <map> attributes

    center

    Android iOS Harmony 4.5
    center?: LatLng;
    
    interface LatLng {
      latitude: number;
      longitude: number;
    }

    Geographic coordinate at the center of the map, in degrees.

    scale

    Android iOS Harmony 4.5
    scale?: number;

    Camera zoom level. A larger value zooms in.

    enable-scale

    Android iOS Harmony 4.5
    'enable-scale'?: boolean;

    Allow pinch-to-zoom gestures.

    enable-drag

    Android iOS Harmony 4.5
    'enable-drag'?: boolean;

    Allow the user to pan the map.

    enable-rotate

    Android iOS Harmony 4.5
    'enable-rotate'?: boolean;

    Allow the user to rotate the map.

    enable-tilt

    Android iOS Harmony 4.5
    'enable-tilt'?: boolean;

    Allow the user to tilt the camera with a gesture.

    <map> events

    bindmapload

    Android iOS Harmony 4.5
    bindmapload?: (e: BaseEvent<'mapload'>) => void;

    Fires when the native map finishes loading.

    <map> methods

    Call these methods using NodesRef.invoke. The examples select a map with id="waterfront".

    setCenter

    Android iOS Harmony 4.5
    lynx
      .createSelectorQuery()
      .select('#waterfront')
      .invoke({
        method: 'setCenter',
        params: {
          center: { latitude: 37.7914, longitude: -122.3904 },
          scale: 16,
          animated: false,
        },
      })
      .exec();

    Move the camera to a geographic coordinate. Pass scale to change the zoom level in the same call.

    FieldTypeOptionalDefaultPlatformsSinceDescription
    centerLatLngNo–Android iOS Harmony 4.54.5New camera center, in degrees.
    scalenumberYes–Android iOS Harmony 4.54.5Zoom level to apply with the new center.
    animatedbooleanYestrueAndroid iOS Harmony 4.54.5Whether to animate the camera movement. Set to false to move immediately.
    durationnumberYes250Android iOS Harmony 4.54.5Animation duration in milliseconds.

    getCenter

    Android iOS Harmony 4.5
    lynx
      .createSelectorQuery()
      .select('#waterfront')
      .invoke({
        method: 'getCenter',
        success({ latitude, longitude }) {
          console.log(latitude, longitude);
        },
      })
      .exec();

    Read the current map center. The success callback receives both coordinates in degrees.

    FieldTypeOptionalDescription
    latitudenumberNoLatitude of the map center, in degrees.
    longitudenumberNoLongitude of the map center, in degrees.

    setScale

    Android iOS Harmony 4.5
    lynx
      .createSelectorQuery()
      .select('#waterfront')
      .invoke({
        method: 'setScale',
        params: { scale: 16, animated: true, duration: 400 },
      })
      .exec();

    Change the zoom level while keeping the current map center.

    FieldTypeOptionalDefaultPlatformsSinceDescription
    scalenumberNo–Android iOS Harmony 4.54.5Target zoom level.
    animatedbooleanYestrueAndroid iOS Harmony 4.54.5Whether to animate the camera movement. Set to false to move immediately.
    durationnumberYes250Android iOS Harmony 4.54.5Animation duration in milliseconds.

    getScale

    Android iOS Harmony 4.5
    lynx
      .createSelectorQuery()
      .select('#waterfront')
      .invoke({
        method: 'getScale',
        success({ scale }) {
          console.log(scale);
        },
      })
      .exec();

    Read the current zoom level in the success callback.

    FieldTypeOptionalDescription
    scalenumberNoCurrent camera zoom level.

    <map-marker> attributes

    position

    Android iOS Harmony 4.5
    position?: LatLng;

    Geographic coordinate at which to place the marker. Supply both latitude and longitude in degrees, as for center.

    anchor

    Android iOS Harmony 4.5
    // @defaultValue: [0.5, 0.5]
    anchor?: [number, number];

    Point on the marker that aligns with its geographic coordinate. The first value runs from left to right and the second from top to bottom, each from 0 to 1. Use [0.5, 1] to align the bottom center of a pin.

    z-index

    Android iOS Harmony 4.5
    'z-index'?: number;

    Stacking order when markers overlap. A larger value places the marker on top. The Google Maps and HarmonyOS providers default to 1, and the MapKit provider defaults to 0.

    alpha

    Android iOS Harmony 4.5
    // @defaultValue: 1
    alpha?: number;

    Marker opacity, from 0 (transparent) to 1 (opaque).

    enable-click

    Android iOS Harmony 4.5
    // @defaultValue: true
    'enable-click'?: boolean;

    Allow taps on this marker to fire clickmarker.

    <map-marker> events

    bindclickmarker

    Android iOS Harmony 4.5
    bindclickmarker?: (e: BaseEvent<'clickmarker'>) => void;

    Fires on the marker the user taps.

    <map-marker> methods

    Call this method using NodesRef.invoke. The example selects a marker with id="ferry-marker".

    refreshMarker

    Android iOS Harmony 4.5
    lynx
      .createSelectorQuery()
      .select('#ferry-marker')
      .invoke({ method: 'refreshMarker' })
      .exec();

    Refresh the native marker image after changing its Lynx child content. For a photo marker, call this method after the image's bindload event so the snapshot includes the photo.

    Host setup

    iOS

    Add XElement/MapImpl for Apple MapKit. Apps that use XElement/Behavior already include it. Register the provider in your app delegate before creating a Lynx view. To use your own provider, depend on XElement/MapInterface and register your implementation.

    pod 'XElement/MapImpl'
    #import <XElement/LynxMapKitProvider.h>
    #import <XElement/LynxXElementMapService.h>
    
    // application:didFinishLaunchingWithOptions:
    [LynxXElementMapService registerProvider:[LynxMapKitProvider new]];

    Android

    Add the XElement behavior bundle and the Google Maps implementation to the app module. Set lynxVersion to the SDK version used by the host.

    dependencies {
        implementation "org.lynxsdk.lynx:xelement:${lynxVersion}"
        implementation "org.lynxsdk.lynx:xelement-map-interface:${lynxVersion}"
        implementation "org.lynxsdk.lynx:xelement-map-impl:${lynxVersion}"
    }

    Register the Google Maps provider in Application.onCreate() before initializing Lynx.

    import com.lynx.xelement.map.LynxXElementMapService;
    import com.lynx.xelement.map.google.GoogleMapProvider;
    
    // Application.onCreate()
    LynxXElementMapService.registerProvider(new GoogleMapProvider());

    Enable Maps SDK for Android in your own Google Cloud project and create an API key for the host app. Restrict it to Maps SDK for Android and to the app's package name and signing certificate SHA-1 fingerprint. Google Maps SDK setup

    In your app module’s build.gradle, pass the key to the manifest at build time. With this setup, set googleMapsApiKey in your user-level ~/.gradle/gradle.properties, or set the GOOGLE_MAPS_API_KEY environment variable before building.

    android {
        defaultConfig {
            manifestPlaceholders.googleMapsApiKey =
                project.findProperty("googleMapsApiKey") ?: System.getenv("GOOGLE_MAPS_API_KEY") ?: ""
        }
    }

    Add the metadata inside <application> in AndroidManifest.xml. Lynx Explorer already declares the placeholder and accepts the same build settings.

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="${googleMapsApiKey}" />

    Register builder.addBehaviors(new XElementBehaviors().create()) on your LynxViewBuilder before creating the view. Import com.lynx.xelement.XElementBehaviors. Run the app on a device or emulator with Google Play services.

    HarmonyOS

    Add @lynx/xelement_map_interface and @lynx/xelement_map_impl to the host module's oh-package.json5 with versions matching @lynx/lynx. Configure Map Kit for your app in AppGallery Connect. Huawei Map Kit configuration

    Choose the system provider during app initialization. Register both behaviors in the behaviors map passed to LynxView, alongside your existing behaviors.

    import { Behavior, BehaviorRegistryMap } from '@lynx/lynx';
    import {
      LynxXElementMapService,
      LynxUIMap,
      LynxUIMapMarker,
    } from '@lynx/xelement_map_interface';
    import { SystemMapProvider } from '@lynx/xelement_map_impl';
    
    LynxXElementMapService.registerProvider(new SystemMapProvider());
    const behaviors: BehaviorRegistryMap = new Map([
      ['map', new Behavior(LynxUIMap, undefined)],
      ['map-marker', new Behavior(LynxUIMapMarker, undefined)],
    ]);

    To use a different map SDK, depend on the interface package and register your own provider at the same point during startup.

    Compatibility

    Map compatibility

    LCD tables only load in the browser

    Marker compatibility

    LCD tables only load in the browser

    Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.