<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
Geographic coordinate at the center of the map, in degrees.
scale
Android
iOS
Harmony
4.5
Camera zoom level. A larger value zooms in.
enable-scale
Android
iOS
Harmony
4.5
Allow pinch-to-zoom gestures.
enable-drag
Android
iOS
Harmony
4.5
Allow the user to pan the map.
enable-rotate
Android
iOS
Harmony
4.5
Allow the user to rotate the map.
enable-tilt
Android
iOS
Harmony
4.5
Allow the user to tilt the camera with a gesture.
<map> events
bindmapload
Android
iOS
Harmony
4.5
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
Move the camera to a geographic coordinate. Pass scale to change the zoom level in the same call.
getCenter
Android
iOS
Harmony
4.5
Read the current map center. The success callback receives both coordinates in degrees.
setScale
Android
iOS
Harmony
4.5
Change the zoom level while keeping the current map center.
getScale
Android
iOS
Harmony
4.5
Read the current zoom level in the success callback.
<map-marker> attributes
position
Android
iOS
Harmony
4.5
Geographic coordinate at which to place the marker. Supply both latitude and longitude in degrees, as for center.
anchor
Android
iOS
Harmony
4.5
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
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
Marker opacity, from 0 (transparent) to 1 (opaque).
enable-click
Android
iOS
Harmony
4.5
Allow taps on this marker to fire clickmarker.
<map-marker> events
bindclickmarker
Android
iOS
Harmony
4.5
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
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.
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.
Register the Google Maps provider in Application.onCreate() before initializing Lynx.
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.
Add the metadata inside <application> in AndroidManifest.xml. Lynx Explorer already declares the placeholder and accepts the same build settings.
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.
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
