Git Product home page Git Product logo

vue-mapbox-geocoder's Introduction

Vue-mapbox-geocoder

Vue-mapbox plugin for mapbox-gl-geocoder support.

Usage

First of all you need to install Mapbox GL and Vue-mapbox. See vue-mapbox doc

Install mabbox-gl-geocoder and vue-mapbox-geocoder:

npm i @mapbox/mapbox-gl-geocoder vue-mapbox vue-mapbox-geocoder

Now you can add geocoder control like other controls:

<template>
  <MglMap
    :accessToken="accessToken"
    :mapStyle="mapStyle"
  >
    <MglGeocoderControl
      <-- props needed for GeolocateControl -->
      :accessToken="accessToken"
      :input.sync="defaultInput"
      @results="handleSearch"
    />
  </MglMap>
</template>

<script>
import {
  MglMap,
  MglNavigationControl,
  MglGeolocateControl
} from 'vue-mapbox'

import MglGeocoderControl from 'vue-mapbox-geocoder'

export default {
  name: 'App',

  components: {
    MglMap,
    MglGeocoderControl
  },
  data() {
    return {
      accessToken: 'YOUR_ACCESS_TOKEN',
      mapStyle: 'YOUR_MAP_STYLE',
      defaultInput: 'Bodhgaya'
    }
  },
  methods: {
    handleSearch(event) {
      console.log(event)
    }
  }
}
</script>

Options for mapbox-gl-geocoder described here can be passed via props.

Additionaly you can pass syncronized prop input as in example below. It will be passed to mapbox-gl-geocoder as default input value. Each time you change value of this prop, mapbox-gl-geocoder .setInput method is called.

Same for proximity prop that internally invokes mapbox-gl-geocoder setProximity method.

Also you can call query method to query search and get results programmatically.

vue-mapbox-geocoder's People

Contributors

soal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vue-mapbox-geocoder's Issues

Attaching to an external DOM

How can I attach this to an external DOM element? My search bar is located outside of my map, and I would like the geocoder to do the same. So far I have tried the following:

Searchbar.vue

But I get the following error when calling the query() method:

[Vue warn]: Error in callback for watcher "defaultInput": "TypeError: this._loadingEl is undefined"

found in

---> at src/components/Searchbar.vue


at src/App.vue

vue.esm.js:591
TypeError: this._loadingEl is undefined
Stack trace:
_geocode@webpack-internal:///./node_modules/@mapbox/mapbox-gl-geocoder/lib/index.js:167:5
query@webpack-internal:///./node_modules/@mapbox/mapbox-gl-geocoder/lib/index.js:264:5
defaultInput@webpack-internal:///./node_modules/babel-loader/lib/index.js!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/components/Searchbar.vue:46:25
run@webpack-internal:///./node_modules/vue/dist/vue.esm.js:3232:11
flushSchedulerQueue@webpack-internal:///./node_modules/vue/dist/vue.esm.js:2980:5
nextTick/<@webpack-internal:///./node_modules/vue/dist/vue.esm.js:1836:9
flushCallbacks@webpack-internal:///./node_modules/vue/dist/vue.esm.js:1757:5

Stand along geocoder, without a map.

I need to get address from users. so all i need is an input text field, the user will type her address, and will get help from the geocoder. no map needed. is this possible? from what i see in the readme, the MglGeocoderControl must live inside a map object. Any way around that?

Position Props

Can't move control position.
Top right by default.
Need a props to set position like other control.

country prop not limiting results to country

As far as I can tell, passing a string of country codes to the country prop of the geocoder control component.

I've tried passing the string through countries and country, tried using "us" and "US" but the results are still not limited to the US.

<MglGeocoderControl :accessToken="token" :mapboxgl="mapboxgl" country="us" />
Is how I've been doing it. Any advice?

Base mixin deprecated breaks plugin

Hi,

With this commit the base mixin is dropped, which causes the plugin to stop working. It seems like things have moved into "withEvents.js", however, this is not globally available as a mixin.

Any ideas on how to remedy?

CSS?

In your demo app you've included CSS that I can't find in this repos. Can you add the .css or document it please?

No mapboxgl detected in options. Map markers are disabled. Please set options.mapboxgl.

I am a new programmer. Thank you very much for this package.

I have been running into the No mapboxgl detected error and therefore not receiving markers. I tried to pass on the object but still did not work.

I went into the GeocoderControl.js in src and saw that there was no prop to receive the mapboxgl so I added a null object after creating that prop.
props: {
// Mapbox-geocoder options
accessToken: {
type: String,
required: true
},
zoom: {
type: Number,
default: 16
},
...
// Component options
input: {
type: String,
default: null
},
mapboxgl:{
type: Object,
default: null
},
},

It seems to have worked. Now I can pass the mapboxgl object.

The error is gone but I wonder if I did something terribly wrong.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.