Skip to content

Commit b2bed86

Browse files
committed
fix: geolocate
1 parent 7b803af commit b2bed86

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/MaptilerGeolocateControl.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,10 @@ export class MaptilerGeolocateControl extends GeolocateControl {
4040
}
4141

4242
onAdd(map: SDKMap | MapMLGL) {
43-
if (this.removeDefaultDOM) {
44-
this.setupExternalElements();
45-
46-
return DOMcreate("div");
47-
}
43+
this._map = map as SDKMap;
4844
return super.onAdd(map as MapMLGL);
4945
}
5046

51-
setupExternalElements = () => {
52-
this.externalGeolocateElement?.addEventListener("click", () =>
53-
this.trigger(),
54-
);
55-
};
56-
5747
/**
5848
* Update the camera location to center on the current position
5949
*
@@ -161,8 +151,14 @@ export class MaptilerGeolocateControl extends GeolocateControl {
161151

162152
this._map.on("move", this._onZoom);
163153
}
164-
165-
this._geolocateButton.addEventListener("click", this.trigger.bind(this));
154+
if (this.externalGeolocateElement) {
155+
this.externalGeolocateElement.addEventListener(
156+
"click",
157+
this.trigger.bind(this),
158+
);
159+
} else {
160+
this._geolocateButton.addEventListener("click", this.trigger.bind(this));
161+
}
166162

167163
this._setup = true;
168164

0 commit comments

Comments
 (0)