Skip to content

Commit

Permalink
Merge pull request #18 from qazsato/fix_rotate
Browse files Browse the repository at this point in the history
stop rotate while zooming
  • Loading branch information
qazsato authored Dec 7, 2024
2 parents 4e7c66d + 859f718 commit ac26efd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
10 changes: 5 additions & 5 deletions docs/index-srYCoeZP.js → docs/index-ByibBDP4.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="icon" type="image/svg+xml" href="/maplibre-gl-compass/compass.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>maplibre-gl-compass</title>
<script type="module" crossorigin src="/maplibre-gl-compass/index-srYCoeZP.js"></script>
<script type="module" crossorigin src="/maplibre-gl-compass/index-ByibBDP4.js"></script>
<link rel="stylesheet" crossorigin href="/maplibre-gl-compass/index-C4Yj2jNw.css">
</head>
<body>
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maplibre-gl-compass",
"version": "0.2.0",
"version": "0.3.0",
"description": "A heading-up compass for MapLibre GL JS",
"type": "module",
"files": [
Expand Down
38 changes: 19 additions & 19 deletions src/maplibre-gl-compass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@ export class CompassControl implements IControl {
constructor(options?: CompassControlOptions) {
this.options = { ...defaultOptions, ...options }
this.compass = new Compass()

this.compass.on('deviceorientation', (event: CompassEvent) => {
if (!this.map) return
if (!this.map || event.heading === undefined) {
return
}
this.currentEvent = event
this.compassButton.stopLoading()
const heading = event.heading
const bearing = this.map.getBearing()
if (!this.map.isZooming() && Math.abs(heading - bearing) >= 1) {
this.map.setBearing(heading)
}
if (this.options.debug) {
this.updateDebugView()
}
if (heading === undefined) {
return
}
const bearing = this.map.getBearing()
if (Math.abs(heading - bearing) >= 1) {
this.map?.setBearing(heading)
}
this.compassButton.stopLoading()

if (this.compassCallback) {
this.compassCallback(event)
}
})

this.compass.on('error', (error: CompassError) => {
this.disable()
if (this.errorCallback) {
Expand All @@ -65,7 +65,14 @@ export class CompassControl implements IControl {
})

this.compassButton = new CompassButton(this.container)
this.compassButton.on('click', () => this.onClick())

this.compassButton.on('click', () => {
if (this.active) {
this.turnOff()
} else {
this.turnOn()
}
})
if (this.options.debug) {
this.debugView = new DebugView(this.container)
}
Expand All @@ -79,6 +86,7 @@ export class CompassControl implements IControl {
this.active = false
}
})

return this.container
}

Expand Down Expand Up @@ -138,14 +146,6 @@ export class CompassControl implements IControl {
this.active = false
}

private onClick() {
if (this.active) {
this.turnOff()
} else {
this.turnOn()
}
}

private updateDebugView() {
this.debugView?.update(this.currentEvent)
}
Expand Down

0 comments on commit ac26efd

Please sign in to comment.