Skip to content

Commit

Permalink
feat(MapGL): add a lot of Mapbox GL JS Map options as MapGL props
Browse files Browse the repository at this point in the history
  • Loading branch information
stepankuzmin committed Oct 19, 2017
1 parent a33a944 commit b9a6649
Showing 1 changed file with 114 additions and 5 deletions.
119 changes: 114 additions & 5 deletions src/components/MapGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,88 @@ type Props = {
/** Specify the pitch of the viewport */
pitch?: number,

/** If true, multiple copies of the world will be rendered, when zoomed out */
renderWorldCopies?: boolean,
/** The minimum zoom level of the map (0-22). */
minZoom?: number,

/** The maximum zoom level of the map (0-22). */
maxZoom?: number,

/**
* If `true`, the map's position (zoom, center latitude,
* center longitude, bearing, and pitch) will be synced
* with the hash fragment of the page's URL. For example,
* http://path/to/my/page.html#2.59/39.26/53.07/-24.1/60.
*/
hash?: boolean,

/**
* The threshold, measured in degrees, that determines when
* the map's bearing (rotation) will snap to north. For
* example, with a bearingSnap of 7, if the user rotates the
* map within 7 degrees of north, the map will automatically
* snap to exact north.
*/
bearingSnap?: number,

/**
* If `false`, the map's pitch (tilt) control with "drag to
* rotate" interaction will be disabled.
*/
pitchWithRotate?: boolean,

/** If `true`, an AttributionControl will be added to the map. */
attributionControl?: boolean,

/* A string representing the position of the Mapbox wordmark on the map. */
logoPosition?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right',

/**
* 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).
*/
failIfMajorPerformanceCaveat?: boolean,

/** Mapbox WebGL context creation option. Useful when you want to export the canvas as a PNG. */
preserveDrawingBuffer?: boolean,

/**
* If `false`, the map won't attempt to re-request tiles once they
* expire per their HTTP `cacheControl`/`expires` headers.
*/
refreshExpiredTiles?: boolean,

/** If set, the map will be constrained to the given bounds. */
maxBounds?: mapboxgl.LngLatBoundsLike,

/** If `true`, the "box zoom" interaction is enabled */
boxZoom?: boolean,

/** If `true`, the "drag to rotate" interaction is enabled */
dragRotate?: boolean,

/** If `true`, the "drag to pan" interaction is enabled */
dragPan?: boolean,

/** If `true`, keyboard shortcuts are enabled */
keyboard?: boolean,

/** If `true`, the "double click to zoom" interaction is enabled */
doubleClickZoom?: boolean,

/** If `true`, the map will automatically resize when the browser window resizes. */
trackResize?: boolean,

/**
* The maxiumum number of tiles stored in the tile cache for a given
* source. If omitted, the cache will be dynamically sized based on
* the current viewport.
*/
maxTileCacheSize?: number,

/** If true, multiple copies of the world will be rendered, when zoomed out */
renderWorldCopies?: boolean,

/**
* `onViewportChange` callback is fired when the user interacted with the
* map. The object passed to the callback contains viewport properties
Expand Down Expand Up @@ -71,8 +147,24 @@ class MapGL extends PureComponent<Props, State> {
accessToken: null,
bearing: 0,
pitch: 0,
renderWorldCopies: true,
minZoom: 0,
maxZoom: 22,
hash: false,
bearingSnap: 7,
pitchWithRotate: true,
attributionControl: true,
logoPosition: 'bottom-left',
failIfMajorPerformanceCaveat: false,
preserveDrawingBuffer: false,
refreshExpiredTiles: true,
boxZoom: true,
dragRotate: true,
dragPan: true,
keyboard: true,
doubleClickZoom: true,
trackResize: true,
renderWorldCopies: true,
maxTileCacheSize: null,
onViewportChange: null,
onLoad: null
};
Expand Down Expand Up @@ -103,13 +195,30 @@ class MapGL extends PureComponent<Props, State> {
const map = new mapboxgl.Map({
container: this._container,
style: mapStyle,
interactive: !!this.props.onViewportChange,
center: [this.props.longitude, this.props.latitude],
zoom: this.props.zoom,
pitch: this.props.pitch,
bearing: this.props.bearing,
minZoom: this.props.minZoom,
maxZoom: this.props.maxZoom,
hash: this.props.hash,
bearingSnap: this.props.bearingSnap,
pitchWithRotate: this.props.pitchWithRotate,
attributionControl: this.props.attributionControl,
logoPosition: this.props.logoPosition,
failIfMajorPerformanceCaveat: this.props.failIfMajorPerformanceCaveat,
preserveDrawingBuffer: this.props.preserveDrawingBuffer,
refreshExpiredTiles: this.props.refreshExpiredTiles,
maxBounds: this.props.maxBounds,
boxZoom: this.props.boxZoom,
dragRotate: this.props.dragRotate,
dragPan: this.props.dragPan,
keyboard: this.props.keyboard,
doubleClickZoom: this.props.doubleClickZoom,
trackResize: this.props.trackResize,
renderWorldCopies: this.props.renderWorldCopies,
interactive: !!this.props.onViewportChange,
preserveDrawingBuffer: this.props.preserveDrawingBuffer
maxTileCacheSize: this.props.maxTileCacheSize
});

map.once('load', () => {
Expand Down

0 comments on commit b9a6649

Please sign in to comment.