|
66 | 66 | }).addTo(map);
|
67 | 67 |
|
68 | 68 | // Function to zoom to a place
|
69 |
| - async function zoomToPlace(placeName, isAiCall = false) { |
70 |
| - if (isAiCall) { |
71 |
| - document.getElementById('place-input').value = placeName; |
72 |
| - } |
73 |
| - |
74 |
| - const response = await fetch( |
75 |
| - `https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(placeName)}`, |
76 |
| - ); |
77 |
| - const data = await response.json(); |
| 69 | + async function zoomToPlace(placeName) { |
| 70 | + try { |
| 71 | + const response = await fetch( |
| 72 | + `https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(placeName)}`, |
| 73 | + ); |
| 74 | + const data = await response.json(); |
78 | 75 |
|
79 |
| - if (data && data.length > 0) { |
80 |
| - const { lat, lon } = data[0]; |
81 |
| - map.setView([lat, lon], 13); // Adjust zoom level as needed |
82 |
| - return `Zoomed to ${placeName} at (${lat}, ${lon})`; |
83 |
| - } else { |
84 |
| - return `Place ${placeName} not found!`; |
| 76 | + if (data && data.length > 0) { |
| 77 | + const { lat, lon } = data[0]; |
| 78 | + map.setView([lat, lon], 13); // Adjust zoom level as needed |
| 79 | + return { |
| 80 | + success: true, |
| 81 | + message: `Zoomed to ${placeName} at (${lat}, ${lon})`, |
| 82 | + }; |
| 83 | + } else { |
| 84 | + return { success: false, message: `Place ${placeName} not found!` }; |
| 85 | + } |
| 86 | + } catch (error) { |
| 87 | + return { |
| 88 | + success: false, |
| 89 | + message: `Error fetching data: ${error.message}`, |
| 90 | + }; |
85 | 91 | }
|
86 | 92 | }
|
87 | 93 |
|
|
118 | 124 | id: 'mapControl.V1',
|
119 | 125 | name: 'zoomToPlace',
|
120 | 126 | description:
|
121 |
| - 'This function can zoom to places on a map on the same webpage.', |
| 127 | + 'This function can be used by the AI to zoom a map displayed on the webpage to a specified place. It returns feedback based on the success of the operation.', |
122 | 128 | parameters: {
|
123 | 129 | type: 'object',
|
124 | 130 | properties: {
|
|
129 | 135 | },
|
130 | 136 | required: ['placeName'],
|
131 | 137 | },
|
132 |
| - function: (params) => zoomToPlace(params.placeName, true), // Assign the zoom function here |
| 138 | + function: (params) => zoomToPlace(params.placeName), |
133 | 139 | },
|
134 | 140 | ];
|
135 | 141 | </script>
|
|
0 commit comments