From ed3d0e10ad36050e4ea63deb4c1b0733ac6a0e32 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 25 Jan 2019 16:40:12 -0500 Subject: [PATCH] expose option to create context with antialiasing fix #7543 --- debug/threejs.html | 1 + src/ui/map.js | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/debug/threejs.html b/debug/threejs.html index cca332b4f4a..2587ec0348e 100644 --- a/debug/threejs.html +++ b/debug/threejs.html @@ -22,6 +22,7 @@ var map = window.map = new mapboxgl.Map({ container: 'map', + antialias: true, zoom: 16.5, center: [-79.390307, 43.658956], bearing: 20, diff --git a/src/ui/map.js b/src/ui/map.js index ca86320323e..55a159fbf5f 100755 --- a/src/ui/map.js +++ b/src/ui/map.js @@ -75,6 +75,7 @@ type MapOptions = { logoPosition?: ControlPosition, failIfMajorPerformanceCaveat?: boolean, preserveDrawingBuffer?: boolean, + antialias?: boolean, refreshExpiredTiles?: boolean, maxBounds?: LngLatBoundsLike, scrollZoom?: boolean, @@ -183,6 +184,7 @@ const defaultOptions = { * @param {boolean} [options.failIfMajorPerformanceCaveat=false] If `true`, map creation will fail if the performance of Mapbox * GL JS would be dramatically worse than expected (i.e. a software renderer would be used). * @param {boolean} [options.preserveDrawingBuffer=false] If `true`, the map's canvas can be exported to a PNG using `map.getCanvas().toDataURL()`. This is `false` by default as a performance optimization. + * @param {boolean} [options.antialias] If `true`, create the gl context will be created with msaa antialiasing, which can be useful for antialiasing custom layers. this is `false` by default as a performance optimization. * @param {boolean} [options.refreshExpiredTiles=true] If `false`, the map won't attempt to re-request tiles once they expire per their HTTP `cacheControl`/`expires` headers. * @param {LngLatBoundsLike} [options.maxBounds] If set, the map will be constrained to the given bounds. * @param {boolean|Object} [options.scrollZoom=true] If `true`, the "scroll to zoom" interaction is enabled. An `Object` value is passed as options to {@link ScrollZoomHandler#enable}. @@ -255,6 +257,7 @@ class Map extends Camera { _trackResize: boolean; _preserveDrawingBuffer: boolean; _failIfMajorPerformanceCaveat: boolean; + _antialias: boolean; _refreshExpiredTiles: boolean; _hash: Hash; _delegatedListeners: any; @@ -317,6 +320,7 @@ class Map extends Camera { this._maxTileCacheSize = options.maxTileCacheSize; this._failIfMajorPerformanceCaveat = options.failIfMajorPerformanceCaveat; this._preserveDrawingBuffer = options.preserveDrawingBuffer; + this._antialias = options.antialias; this._trackResize = options.trackResize; this._bearingSnap = options.bearingSnap; this._refreshExpiredTiles = options.refreshExpiredTiles; @@ -1547,10 +1551,11 @@ class Map extends Camera { } _setupPainter() { - const attributes = extend({ + const attributes = extend({}, isSupported.webGLContextAttributes, { failIfMajorPerformanceCaveat: this._failIfMajorPerformanceCaveat, - preserveDrawingBuffer: this._preserveDrawingBuffer - }, isSupported.webGLContextAttributes); + preserveDrawingBuffer: this._preserveDrawingBuffer, + antialias: this._antialias || false + }); const gl = this._canvas.getContext('webgl', attributes) || this._canvas.getContext('experimental-webgl', attributes);