Im trying to use trimble maps javascript sdk in a react app to display a map. I also want to add points to the map at specified lat longs. However, whenever I add a marker to the map the marker appears to shift off the map and not show at the lat/long. When you zoom in or out the marker does look like it moves.
I will also note that I have also been adding routes to the map with the lat longs and those work and show where they should. So this issue is just with the markers.
The version of trimble Im using is: “@trimblemaps/trimblemaps-js”: “^4.2.1”
If theres a better method for adding markers to the map I can switch to that. I just cant understand why the marker is being shifted. I copied this from examples on the trimble developer portal so Im not sure what Im doing wrong. I will say the examples on trimble are just javascript and I am doing this in react so Im not sure if that is making a difference or not.
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 =
'<div id="text">Green truck</div>' +
'<div id="image" style="background: url(https://maps.alk.com/api/1.2/img/truck_green.png) no-repeat; height: 26px; width: 26px;"/>';
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 (
<div style={{width: "100%", height: "100%"}}>
<div id="map" style={{height: "500px", width: "1000px;"}}></div>
</div>
)
}
Here is what the map looks like with the marker when it renders:


