From 18274a300bbc85f4dcf295b3f676796f5bbc0d05 Mon Sep 17 00:00:00 2001 From: Molly Lloyd Date: Mon, 9 Jan 2017 17:37:08 -0800 Subject: [PATCH] add mapbox watermark by default --- dist/mapbox-gl.css | 9 +++++++++ documentation.yml | 1 + js/mapbox-gl.js | 1 + js/ui/control/logo_control.js | 34 ++++++++++++++++++++++++++++++++++ js/ui/map.js | 4 ++++ 5 files changed, 49 insertions(+) create mode 100644 js/ui/control/logo_control.js diff --git a/dist/mapbox-gl.css b/dist/mapbox-gl.css index 841457e2a6e..f8306088edb 100644 --- a/dist/mapbox-gl.css +++ b/dist/mapbox-gl.css @@ -95,6 +95,15 @@ display: inline-block; } +a.mapboxgl-ctrl-logo { + width: 60px; + height: 20px; + display: block; + background-repeat: no-repeat; + cursor: pointer; + background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxuczpzdmc9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgeD0iMCIgeT0iMCIgd2lkdGg9IjU5LjEiIGhlaWdodD0iMTgiIHZpZXdCb3g9IjAgMCA1OS4xIDE4IiBlbmFibGUtYmFja2dyb3VuZD0ibmV3IDAgMCA1OS4xMTkgMTgiIHhtbDpzcGFjZT0icHJlc2VydmUiPjxwYXRoIGQ9Ik0xLjQgMEMwLjYgMC4xIDAgMC44IDAgMS41TDAgMTMuNEMwIDE0LjIgMC43IDE0LjggMS41IDE0LjhMMy4zIDE0LjhDNCAxNC44IDQuNyAxNC4yIDQuOCAxMy40TDQuOCA5LjEgNS41IDEwLjNDNiAxMS4yIDcuNSAxMS4yIDggMTAuM0w4LjggOS4xIDguOCAxMy40QzguOCAxNC4xIDkuNSAxNC44IDEwLjIgMTQuOEwxMiAxNC44QzEyLjggMTQuOCAxMy41IDE0LjIgMTMuNSAxMy40TDEzLjUgMTMuMkMxNC41IDE0LjMgMTUuOSAxNSAxNy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gMi42IDEuMiAyLjYgMi44IDAgMS41LTEuMiAyLjgtMi42IDIuOEM0My43IDExLjggNDIuNSAxMC41IDQyLjUgOWMwLTEuNSAxLjItMi44IDIuNi0yLjh6bS0yMC4yIDAgMS42IDBjMS42IDAgMi42IDEuMyAyLjYgMi44IDAgMS41LTEuMSAyLjgtMi42IDIuOGwtMS42IDAgMC01LjV6bTkgMCAxLjUgMGMxLjUgMCAyLjYgMS4zIDIuNiAyLjggMCAxLjUtMSAyLjgtMi42IDIuOGwtMS41IDAgMC01LjV6IiBmaWxsPSIjZmZmIi8+PC9zdmc+"); +} + .mapboxgl-ctrl.mapboxgl-ctrl-attrib { padding: 0 5px; background-color: rgba(255, 255, 255, .5); diff --git a/documentation.yml b/documentation.yml index 14d9a6a644b..331ed246fbc 100644 --- a/documentation.yml +++ b/documentation.yml @@ -17,6 +17,7 @@ toc: - GeolocateControl - AttributionControl - ScaleControl + - LogoControl - name: Handlers description: | Handlers add different kinds of interactivity to the map - diff --git a/js/mapbox-gl.js b/js/mapbox-gl.js index 163412774e6..d52dc3de904 100644 --- a/js/mapbox-gl.js +++ b/js/mapbox-gl.js @@ -10,6 +10,7 @@ mapboxgl.workerCount = Math.max(Math.floor(browser.hardwareConcurrency / 2), 1); mapboxgl.Map = require('./ui/map'); mapboxgl.NavigationControl = require('./ui/control/navigation_control'); +mapboxgl.LogoControl = require('./ui/control/logo_control'); mapboxgl.GeolocateControl = require('./ui/control/geolocate_control'); mapboxgl.AttributionControl = require('./ui/control/attribution_control'); mapboxgl.ScaleControl = require('./ui/control/scale_control'); diff --git a/js/ui/control/logo_control.js b/js/ui/control/logo_control.js new file mode 100644 index 00000000000..0ac07a2f22b --- /dev/null +++ b/js/ui/control/logo_control.js @@ -0,0 +1,34 @@ +'use strict'; + +const DOM = require('../../util/dom'); + +/** + * A `LogoControl` is a control that adds the Mapbox watermark + * to the map as required by the [terms of service](https://www.mapbox.com/tos/) for Mapbox + * vector tiles and core styles. + * + * @implements {IControl} +**/ + +class LogoControl { + constructor() { + } + + onAdd(map) { + this._map = map; + this._container = DOM.create('div', 'mapboxgl-ctrl'); + const anchor = DOM.create('a', 'mapboxgl-ctrl-logo'); + anchor.target = "_blank"; + anchor.href = "https://www.mapbox.com/"; + this._container.append(anchor); + return this._container; + } + + onRemove() { + this._container.parentNode.removeChild(this._container); + this._map = undefined; + } +} + + +module.exports = LogoControl; diff --git a/js/ui/map.js b/js/ui/map.js index 12837508269..aa5c2dfd570 100755 --- a/js/ui/map.js +++ b/js/ui/map.js @@ -19,6 +19,7 @@ const LngLat = require('../geo/lng_lat'); const LngLatBounds = require('../geo/lng_lat_bounds'); const Point = require('point-geometry'); const AttributionControl = require('./control/attribution_control'); +const LogoControl = require('./control/logo_control'); const isSupported = require('mapbox-gl-supported'); const defaultMinZoom = 0; @@ -47,6 +48,7 @@ const defaultOptions = { hash: false, attributionControl: true, + logoControl: true, failIfMajorPerformanceCaveat: false, preserveDrawingBuffer: false, @@ -99,6 +101,7 @@ const defaultOptions = { * in an HTML element's `class` attribute. To learn more about Mapbox style classes, read about * [Layers](https://www.mapbox.com/mapbox-gl-style-spec/#layers) in the style specification. * @param {boolean} [options.attributionControl=true] If `true`, an [AttributionControl](#AttributionControl) will be added to the map. + * @param {boolean} [options.logoControl=true] If `true`, a [LogoControl](#LogoControl) will be added to the map. * @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. @@ -200,6 +203,7 @@ class Map extends Camera { if (options.style) this.setStyle(options.style); if (options.attributionControl) this.addControl(new AttributionControl()); + if (options.logoControl) this.addControl(new LogoControl(), 'bottom-left'); this.on('style.load', function() { if (this.transform.unmodified) {