{"id":16564634,"url":"https://github.com/okdistribute/mapbox-gl-toggle-control","last_synced_at":"2025-09-13T17:32:28.068Z","repository":{"id":141862389,"uuid":"101017856","full_name":"okdistribute/mapbox-gl-toggle-control","owner":"okdistribute","description":"Toggle an HTMLElement with a button control on your Mapbox GL map.","archived":false,"fork":false,"pushed_at":"2017-08-22T19:17:24.000Z","size":2001,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-03T09:42:55.891Z","etag":null,"topics":["button","control","javascript","legend","mapbox","mapbox-gl","mapbox-gl-js","node","toggle"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/okdistribute.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-08-22T03:36:49.000Z","updated_at":"2020-02-07T09:17:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"9184df86-cf95-4b26-b91a-1de6e9e023ae","html_url":"https://github.com/okdistribute/mapbox-gl-toggle-control","commit_stats":null,"previous_names":["karissa/mapbox-gl-legend"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/okdistribute%2Fmapbox-gl-toggle-control","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/okdistribute%2Fmapbox-gl-toggle-control/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/okdistribute%2Fmapbox-gl-toggle-control/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/okdistribute%2Fmapbox-gl-toggle-control/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/okdistribute","download_url":"https://codeload.github.com/okdistribute/mapbox-gl-toggle-control/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232893575,"owners_count":18592980,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["button","control","javascript","legend","mapbox","mapbox-gl","mapbox-gl-js","node","toggle"],"created_at":"2024-10-11T20:44:40.557Z","updated_at":"2025-01-07T14:37:56.259Z","avatar_url":"https://github.com/okdistribute.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mapbox-gl-toggle-control\n\n[![npm version][0]][1]\n\nAdd a toggle control to your Mapbox GL Map that has the look and feel of other Mapbox GL controls. When clicked, the given HTMLElement will appear or disappear.\n\n\n```npm install mapbox-gl-toggle-control```\n\n[![example.gif](example.gif)]()\n\n## Example\n\n```js\nvar mapbox = require('mapbox-gl')\nvar ToggleControl = require('mapbox-gl-toggle-control')\n\nvar map = new mapboxgl.Map({\n  container: 'map', // container id\n  zoom: 5.5, // starting zoom\n  maxBounds: [-87, -9, -70, 6]\n})\n\nvar toggle = new ToggleControl(document.querySelector('#my-legend'))\nmap.addControl(toggle, 'top-left')\n```\n\n```html\n\u003cstyle\u003e\n  .mapboxgl-ctrl-toggle {\n    background-image: url(/icons/my-toggle-button.svg);\n    background-repeat: no-repeat;\n    background-size: 20px;\n    background-position: center;\n  }\n\u003c/style\u003e\n\u003cdiv id=\"map\"\u003e\u003c/div\u003e\n\u003cdiv id=\"my-legend\"\u003e\n  \u003cul\u003e\n    \u003cli\u003e\u003cimg src=\"/icons/fairy.png\"\u003e Fairy\u003c/li\u003e\n    \u003cli\u003e\u003cimg src=\"/icons/centaur.png\"\u003e Centaur\u003c/li\u003e\n  \u003c/ul\u003e\n\u003c/div\u003e\n```\n\nThis will create a control button on the map. The contents of the button can be changed via the CSS class `mapboxgl-ctrl-toggle`.\n\n## API\n\n#### ```var ctrl = ToggleControl(el: HTMLElement, [contents])```\n\nCreate the toggle control. The control can be added to the map using `map.addControl(ctrl, 'top-left')`.\n\n* `el`: (required) HTMLElement. When the control is clicked or `toggle` is called, the element will be shown or hidden.\n* `contents`: (optional) The innerHTML contents of the button.\n\n#### ```ctrl.hide()```\n\nHide the element.\n\n#### ```ctrl.show()```\n\nShow the element.\n\n#### ```ctrl.toggle()```\n\nToggle showing or hiding the element.\n\n#### ```ctrl.isOpen()```\n\nReturns `true` if the element is visible.\n\n## License\n\nMIT\n\n[0]: https://img.shields.io/npm/v/mapbox-gl-toggle-control.svg?style=flat-square\n[1]: https://npmjs.org/package/mapbox-gl-toggle-control\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fokdistribute%2Fmapbox-gl-toggle-control","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fokdistribute%2Fmapbox-gl-toggle-control","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fokdistribute%2Fmapbox-gl-toggle-control/lists"}