File tree Expand file tree Collapse file tree 1 file changed +78
-0
lines changed
Expand file tree Collapse file tree 1 file changed +78
-0
lines changed Original file line number Diff line number Diff line change 11# Vue-mapbox-geocoder
22
33[ Vue-mapbox] ( https://github.com/soal/vue-mapbox ) plugin for [ mapbox-gl-geocoder] ( https://github.com/mapbox/mapbox-gl-geocoder ) support.
4+
5+
6+ ## Usage
7+ First of all you need to install Mapbox GL and Vue-mapbox. [ See vue-mapbox doc] ( https://soal.github.io/vue-mapbox/#/quickstart )
8+
9+ After, obviosly, you need to install mabbox-gl-geocoder:
10+
11+ ``` bash
12+ ```
13+
14+ Then, on plugin registration you need to add plugins option:
15+
16+ ``` javascript
17+ import Vue from ' vue'
18+ import VueMapbox from ' vue-mapbox'
19+ import Mapbox from ' mapbox-gl'
20+ import MapboxGeocoder from ' @mapbox/mapbox-gl-geocoder'
21+
22+ Vue .use (VueMapbox, {
23+ mapboxgl: Mapbox,
24+ plugins: [{ mapboxGeocoder: MapboxGeocoder }] // Notice plugins property
25+ })
26+
27+ new Vue ({
28+ el: ' #app' ,
29+ render : h => h (require (' ./App' ))
30+ })
31+ ```
32+
33+ Now you can add geocoder control like other controls:
34+
35+ ``` vue
36+ <template>
37+ <mgl-map
38+ :accessToken="accessToken"
39+ :mapStyle.sync="mapStyle"
40+ >
41+ <mgl-navigation-control position="top-right"/>
42+ <mgl-geolocate-control position="top-right" />
43+ <mgl-geocoder-control
44+ :accessToken="accessToken"
45+ @results="handleSearch"
46+ />
47+ </mgl-map>
48+ </template>
49+
50+ <script>
51+ import {
52+ MglMap,
53+ MglNavigationControl,
54+ MglGeolocateControl
55+ } from 'vue-mapbox'
56+
57+ import MglGeocoderControl from 'vue-mapbox-geocoder'
58+
59+ export default {
60+ name: 'App',
61+
62+ components: {
63+ MglMap,
64+ MglNavigationControl,
65+ MglGeolocateControl,
66+ MglGeocoderControl
67+ },
68+ data() {
69+ return {
70+ accessToken: 'some_token',
71+ mapStyle: 'some_style'
72+ }
73+ },
74+ methods: {
75+ handleSearch(event) {
76+ console.log(event)
77+ }
78+ }
79+ }
80+ </script>
81+ ```
You can’t perform that action at this time.
0 commit comments