Код: Выделить всё
import React, { useEffect } from 'react';
import './TrimbleTestPage.css';
import TrimbleMaps from "@trimblemaps/trimblemaps-js";
TrimbleMaps.setAPIKey("API KEY");
export default function TrimbleTestPage() {
useEffect(() => {
const center = [-87, 38];
const zoomLevel = 6;
const map = new TrimbleMaps.Map({
container: 'map', // container id
center: center,
zoom: zoomLevel,
maxCanvasSize: [500,1000],
region: TrimbleMaps.Common.Region.NA
});
map.on('load', () => {
// Create a marker with a label on top of an icon
const el = document.createElement('div');
el.classList.add('cust-marker');
el.title = 'Marker with a label and an icon';
const htmlContent =
'Green truck' +
'';
el.innerHTML = htmlContent;
const marker = new TrimbleMaps.Marker({
draggable: false,
anchor: 'top-left', // default: center, if width is too wide, you will see marker moves after zoom out.
element: el
}).setLngLat(center).addTo(map);
});
// Cleanup function to remove the map instance when the component unmounts
return () => map.remove();
}, []);
return (
)
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... markers-ar