Select to view content in your preferred language

Map view re-render on click on android

765
1
12-22-2023 10:24 AM
MichalKopčil
New Contributor

Hello, Im using ArcGis javascript to create a web app especially for phones. At some point I found out, that on Android devices when the map is clicked (not touched - movement on map is fine), it re-renders for some reason. 
Ive tried it on different devices and OS (iphones, tablets, desktops with mobile settings..) and all are good but android devices.

Here is a video with issue. Before each rerender comes click: video 

The code is pretty simple:

const mapDiv = useRef<any>(null);
useEffect(() => {
if (!mapDiv.current) return;

const initializeMap = () => {
try {
const map = new Map({
basemap: 'dark-gray-vector',
});

const mapView = new MapView({
container: mapDiv.current,
map: map,
center: [16, 49],
zoom: 18,
});

return () => {
mapView && mapView.destroy()
};
} catch (error) {
console.error("Error creating map:", error);
}
};

initializeMap();
}, []);
return (
<div ref={ mapDiv } className="map-container" />
);

 

Ive also tried some ArcGis examples and with some of them I experience the same behavior. 
For example:

https://developers.arcgis.com/javascript/latest/sample-code/basemaps-portal/ in codepen this map rerenders after click on android phone.

But this one doesnt get rerendered: https://developers.arcgis.com/javascript/latest/sample-code/widgets-basemapgallery/

Im really confused about this behavior, can anyone tell me how to stop these unwanted mapView re-renders?

Thanks in advance!



Im using:
- Typescript 4.4.2
- React 18.2.0
- Arcgis core 4.28.10

0 Kudos
1 Reply
mleahy_cl
Regular Contributor

I can confirm this happens with the live view of the sample linked above in the chrome browser on an up-to-date Samsung S20 FE:

https://developers.arcgis.com/javascript/latest/sample-code/basemaps-portal/live/

Note: the problem goes away if I view the same page in 'desktop' mode (though that introduces a different issue, where the map either does not draw, or draws incorrectly when displayed in portrait - only works in landscape...I'm pretty sure that's an unrelated concern, as I've been seeing that behaviour for a while).

0 Kudos