Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using existing input control #162

Open
stevage opened this issue Aug 24, 2017 · 1 comment
Open

Allow using existing input control #162

stevage opened this issue Aug 24, 2017 · 1 comment

Comments

@stevage
Copy link

stevage commented Aug 24, 2017

It would be really handy if we could use an existing Input control (outside the Leaflet map), rather than creating one.

I'd appreciate any feedback on the feasibility of implementing this, as we may implement it ourselves.

@stevage
Copy link
Author

stevage commented Aug 30, 2017

Ok, so this turned out to be pretty easy to implement, but not in a way which is likely to survive a PR. I changed the first few lines of onAdd to:

      onAdd: function (map) {
        this._body = document.body || document.getElementsByTagName('body')[0];
        var container;
        if (this.options.inputId) {
          this._input = L.DomUtil.get(this.options.inputId);
          container = this._input.parentElement;
        } else {
          container =  L.DomUtil.create('div', 'leaflet-pelias-control leaflet-bar leaflet-control');
          this._input = L.DomUtil.create('input', 'leaflet-pelias-input', container);
        }
        this._container = container;

        // unchanged from here...
        this._input.spellcheck = false;

The awkward bit is that calling geocoder.addTo(map) triggers other code in Leaflet which always moves the control inside the map. So instead, I do this:

      map.geocoder._map = map;
      map.geocoder.onAdd(map);

It works pretty well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant