|
|
@ -15,8 +15,8 @@ const loadHTMLFile = async () => { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
function goToPosition(mapRef, lat, long) { |
|
|
|
mapRef.injectJavaScript(`map.setView([${lat}, ${long}], 13);`); |
|
|
|
function goToRegion(mapRef, { lat, long, zoom }) { |
|
|
|
mapRef.injectJavaScript(`map.setView([${lat}, ${long}], ${zoom});`); |
|
|
|
} |
|
|
|
|
|
|
|
const code_to_function = { |
|
|
@ -38,18 +38,25 @@ function markerCallback(payload) { |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
function parseInput(event) { |
|
|
|
function handleEvent(event) { |
|
|
|
const payload = JSON.parse(event.nativeEvent.data); |
|
|
|
return code_to_function[payload.code](payload); |
|
|
|
} |
|
|
|
|
|
|
|
function insertMarker(mapRef, props) { |
|
|
|
function insertMarker(mapRef, ID, cords) { |
|
|
|
mapRef.injectJavaScript(`
|
|
|
|
if (!(${props.ID} in markers)) { |
|
|
|
markers[${props.ID}] = L.marker([${props.cords.lat}, ${props.cords.long}], |
|
|
|
{ID: ${props.ID}}); |
|
|
|
markers[${props.ID}].addTo(map).on('click', onPopupClick); |
|
|
|
// Check if there is no other marker with same ID already in map
|
|
|
|
if (!(${ID} in markers)) { |
|
|
|
|
|
|
|
// Creates marker object
|
|
|
|
markers[${ID}] = L.marker([${cords.lat}, ${cords.long}], |
|
|
|
{ID: ${ID}}); |
|
|
|
|
|
|
|
|
|
|
|
// Add marker to map and bing callback event to its function
|
|
|
|
markers[${ID}].addTo(map).on('click', onPopupClick); |
|
|
|
} |
|
|
|
`);
|
|
|
|
} |
|
|
|
export { loadHTMLFile, parseInput, insertMarker, goToPosition }; |
|
|
|
|
|
|
|
export { loadHTMLFile, handleEvent, insertMarker, goToRegion }; |