Skip to content

Commit 74057df

Browse files
thaddmthdworld11
andauthored
chore(geo): Add section to geo search for customizing search icons (aws-amplify#3721)
* chore(geo): Add section to geo search for customizing search icons * change geocoder custom image screenshot * Update src/fragments/lib/geo/js/search.mdx Co-authored-by: Harshita Daddala <[email protected]> * Update src/fragments/lib/geo/js/search.mdx Co-authored-by: Harshita Daddala <[email protected]> Co-authored-by: Harshita Daddala <[email protected]>
1 parent 38de1f9 commit 74057df

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed
911 KB
Loading

src/fragments/lib/geo/js/search.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,24 @@ document.getElementById("search").appendChild(geocoder.onAdd());
6363

6464
![A search box](/images/geocoder-search-box.png)
6565

66+
### Customize Search Icons
67+
68+
You can customize the search icons used by the [maplibre-gl-geocoder](https://github.com/maplibre/maplibre-gl-geocoder) to use any image of your choosing. [MapLibre markers](https://maplibre.org/maplibre-gl-js-docs/api/markers/) require an [HTMLElement](https://developer.mozilla.org/en-US/docs/Web/HTML/Element) when passing in custom images.
69+
70+
The following example puts an existing SVG icon into an HTMLElement before being passed to `createAmplifyGeocoder` which creates a [maplibre-gl-geocoder](https://github.com/maplibre/maplibre-gl-geocoder).
71+
72+
```javascript
73+
import myIcon from "./myIcon.svg" // relative path to your custom icon
74+
75+
const icon = new Image(100, 100);
76+
icon.src = myIcon;
77+
78+
const geocoder = createAmplifyGeocoder({ showResultMarkers: { element: icon } });
79+
map.addControl(geocoder);
80+
```
81+
82+
![A search box](/images/geocoder-custom-images.png)
83+
6684
## Location-based search capabilities
6785

6886
Amplify Geo enables you to search for locations by text, addresses, or geo-coordinates.

0 commit comments

Comments
 (0)