Skip to content

Commit 928de2b

Browse files
Merge pull request soal#12 from geospoc/feat/add-custom-container-support
feat: add custom container support
2 parents 8e0ba70 + c7e06be commit 928de2b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Now you can add geocoder control like other controls:
2323
<MglGeocoderControl
2424
:accessToken="accessToken"
2525
:input.sync="defaultInput"
26+
container="geocoder_container_id"
27+
position="top-left"
2628
@results="handleSearch"
2729
/>
2830
</MglMap>

src/GeocoderControl.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ export default {
1616
inject: ['mapbox', 'map'],
1717

1818
props: {
19+
position: {
20+
type: String,
21+
default: 'top-right',
22+
},
23+
container: {
24+
type: String,
25+
default: null,
26+
},
1927
// Mapbox-geocoder options
2028
accessToken: {
2129
type: String,
@@ -123,7 +131,13 @@ export default {
123131

124132
methods: {
125133
$_deferredMount() {
126-
this.map.addControl(this.control);
134+
if (this.container !== null) {
135+
document
136+
.getElementById(this.container)
137+
.appendChild(this.control.onAdd(this.map));
138+
} else {
139+
this.map.addControl(this.control, this.position);
140+
}
127141
if (this.input) {
128142
this.control.setInput(this.input);
129143
}

0 commit comments

Comments
 (0)