-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(osmPoi): accessibility using dom elements on canvas (#120)
- Loading branch information
Showing
9 changed files
with
114 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* Adapted from https://github.com/mapbox/mapbox-gl-accessibility | ||
Copyright (c) 2018, Mapbox | ||
ISC License | ||
*/ | ||
.mapboxgl-accessibility-marker { | ||
background: transparent; | ||
margin: 0; | ||
padding: 0; | ||
border-radius: 0; | ||
border: none; | ||
position: fixed; | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* Copyright (c) Institut national de l'information géographique et forestière | ||
* | ||
* This program and the accompanying materials are made available under the terms of the GPL License, Version 3.0. | ||
* | ||
* Adapted from https://github.com/mapbox/mapbox-gl-accessibility | ||
* Copyright (c) 2018, Mapbox | ||
* ISC License | ||
* | ||
*/ | ||
|
||
import debounce from 'lodash/debounce'; | ||
|
||
import Legend from "./map-interactivity/legend-plan-ign"; | ||
|
||
class MapboxAccessibility { | ||
constructor(map, options) { | ||
this.map = map; | ||
this.layers = options.layers || [ | ||
'POI OSM isochrone$$$OSM.POI$GEOPORTAIL:GPP:TMS', | ||
"POI OSM 14$$$OSM.POI$GEOPORTAIL:GPP:TMS", | ||
"POI OSM 15$$$OSM.POI$GEOPORTAIL:GPP:TMS", | ||
"POI OSM 16et17$$$OSM.POI$GEOPORTAIL:GPP:TMS", | ||
"POI OSM 18et19$$$OSM.POI$GEOPORTAIL:GPP:TMS", | ||
] | ||
this.features = null; | ||
map.on('movestart', this._movestart); | ||
map.on('moveend', this._render); | ||
map.on('render', this._render); | ||
this._debouncedQueryFeatures = debounce(this.queryFeatures, 100); | ||
} | ||
|
||
clearMarkers = () => { | ||
if (this.features) { | ||
this.features.forEach(feature => { | ||
if (feature.marker) { | ||
this.map.getCanvasContainer().removeChild(feature.marker); | ||
delete feature.marker; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
queryFeatures = () => { | ||
this._debouncedQueryFeatures.cancel(); | ||
this.clearMarkers(); | ||
|
||
this.features = this.map.queryRenderedFeatures({ layers: this.layers }); | ||
this.features.map((feature) => { | ||
const label = Legend.beautifyLayerName(feature, "poi_osm").split("<p class=\"positionSubTitle\">")[0]; | ||
|
||
feature.marker = document.createElement('button'); | ||
feature.marker.setAttribute('title', label); | ||
feature.marker.setAttribute('tabindex', 0); | ||
feature.marker.style.display = 'block'; | ||
|
||
let position; | ||
if (feature.geometry.type === 'Point') { | ||
position = this.map.project(feature.geometry.coordinates); | ||
} | ||
feature.marker.style.width = "24px"; | ||
feature.marker.style.height = "24px"; | ||
feature.marker.style.transform = `translate(-50%, -50%) translate(${position.x}px, ${position.y}px)`; | ||
feature.marker.className = 'mapboxgl-accessibility-marker'; | ||
|
||
this.map.getCanvasContainer().appendChild(feature.marker); | ||
return feature; | ||
}); | ||
} | ||
|
||
_movestart = () => { | ||
this._debouncedQueryFeatures.cancel(); | ||
this.clearMarkers(); | ||
} | ||
|
||
_render = () => { | ||
if (!this.map.isMoving()) { | ||
this._debouncedQueryFeatures(); | ||
} | ||
} | ||
} | ||
|
||
export default MapboxAccessibility; |