-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add panning and zooming to SVG map element
This commit adds a dependency on the [`svg-pan-zoom` package][svg-pan-zoom]. To manage the configuration and execution of that plugin, this commit introduces `controllers/seats_controller` JavaScript module. [That module will be instantiated with elements that declare `data-controller="seats"`][controllers]. Once an element with `data-controller="seats"` exists on the page, the module's [`connect()` life cycle hook][connect] will be invoked, which will initiate the `svgPanZoom` plugin configuration, passing a reference to `this.element` as the DOM Node to attach the map to. Additionally, This commit wraps the collection of `<use>` elements in an outer [`<g>` element][g-element] (as suggested by [aritutta/svg-pan-zoom#146]). [controllers]: https://stimulusjs.org/reference/controllers [connect]: https://stimulusjs.org/reference/lifecycle-callbacks#connection [svg-pan-zoom]: https://github.com/ariutta/svg-pan-zoom/tree/3.6.0 [g-element]: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/g [aritutta/svg-pan-zoom#146]: bumbu/svg-pan-zoom#146
- Loading branch information
1 parent
2afc60d
commit cd15bea
Showing
5 changed files
with
63 additions
and
47 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Controller } from "stimulus" | ||
import svgPanZoom from "svg-pan-zoom" | ||
|
||
export default class extends Controller { | ||
static targets = [ | ||
"map", | ||
] | ||
|
||
connect() { | ||
this.map = svgPanZoom(this.mapTarget, { | ||
viewportSelector: "#map-viewport", | ||
center: true, | ||
fit: true, | ||
zoomEnabled: false, | ||
zoomScaleSensitivity: 0.75, | ||
minZoom: 1.0, | ||
maxZoom: 8, | ||
}) | ||
} | ||
|
||
disconnect() { | ||
this.map.destroy() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters