leaflet-control-geocoder icon indicating copy to clipboard operation
leaflet-control-geocoder copied to clipboard

What about `htmlTemplate` option and `html` prop for other geocoders ?

Open Cyrille37 opened this issue 11 months ago • 1 comments

Hi

What about htmlTemplate option (and it's associated html) for other geocoders ? It's only available for Nominatim and Photon.

Is there a reason ? May we suggest Pull request ?

It's very useful for localizing result's items order ;-)

Regards & cheers

Cyrille37 avatar Dec 25 '24 21:12 Cyrille37

Hi, I like the idea. I'm happy to review a patch.

I wonder whether there's a good way to achieve this functionality without adapting every single geocoder. Maybe the following?

diff --git a/src/control.ts b/src/control.ts
index ee0fb86..3f3676d 100644
--- a/src/control.ts
+++ b/src/control.ts
@@ -390,6 +390,9 @@ export class GeocoderControl extends EventedControl {
 
     li.setAttribute('data-result-index', String(index));
 
+    if (this.options.htmTemplate) {
+      result.html = this.options.htmTemplate(result);
+    }
     if (result.html) {
       a.innerHTML = a.innerHTML + result.html;
     } else if (text) {

simon04 avatar Dec 26 '24 18:12 simon04