From 3cf3b8811d65741d8b5b1301ef12cb6dc820b137 Mon Sep 17 00:00:00 2001 From: john gravois Date: Wed, 28 Sep 2016 10:18:38 -0700 Subject: [PATCH] make max-width of attribution control configurable (#849) * make max-width of attribution control configurable in the majority of applications it makes sense to leverage as much horizontal space as possible to display attribution, primarily because of small form factor devices, but 55px is a little safer default because it accomodates a bottom oriented zoom control automatically. since other possibly bottom aligned controls like L.Control.Scale and L.Controls.Layers don't have a static predictable width our best bet is to just expose a mechanism to let developers indicate just how much space should be reserved. * better to store the new option in our own namespace * linting * better linting --- .gitignore | 1 + package.json | 2 +- src/EsriLeaflet.js | 1 + src/Options.js | 5 +++++ src/Util.js | 10 ++++++---- 5 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 src/Options.js diff --git a/.gitignore b/.gitignore index af5d24608..2b398672a 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ coverage # Debugging Files working debug/*.html +debug/archive/ !debug/sample.html # Docs Build diff --git a/package.json b/package.json index 7a225022f..2c5cd006c 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ }, "scripts": { "build": "rollup -c profiles/debug.js & rollup -c profiles/production.js", - "lint": "semistandard src/**/*.js | snazzy", + "lint": "semistandard \"src/**\" \"src/**/*.js\" | snazzy", "prebuild": "mkdirp dist", "prepublish": "npm run build", "pretest": "npm run build", diff --git a/src/EsriLeaflet.js b/src/EsriLeaflet.js index 9b0835e6b..7bae10cf4 100644 --- a/src/EsriLeaflet.js +++ b/src/EsriLeaflet.js @@ -3,6 +3,7 @@ export {version as VERSION} from '../package.json'; // import base export { Support } from './Support'; +export { Options } from './Options'; export { Util } from './Util'; export { get, post, request } from './Request'; diff --git a/src/Options.js b/src/Options.js new file mode 100644 index 000000000..d1d5feb50 --- /dev/null +++ b/src/Options.js @@ -0,0 +1,5 @@ +export var Options = { + attributionWidthOffset: 55 +}; + +export default Options; diff --git a/src/Util.js b/src/Util.js index a78de1388..68b6904b4 100644 --- a/src/Util.js +++ b/src/Util.js @@ -1,5 +1,7 @@ import L from 'leaflet'; import { jsonp } from './Request'; +import { Options } from './Options'; + import { geojsonToArcGIS as g2a, arcgisToGeoJSON as a2g @@ -139,8 +141,8 @@ export function warn () { } export function calcAttributionWidth (map) { - // slightly less than the width of the map - return (map.getSize().x - 20) + 'px'; + // either crop at 55px or user defined buffer + return (map.getSize().x - Options.attributionWidthOffset) + 'px'; } export function setEsriAttribution (map) { @@ -150,7 +152,7 @@ export function setEsriAttribution (map) { var hoverAttributionStyle = document.createElement('style'); hoverAttributionStyle.type = 'text/css'; hoverAttributionStyle.innerHTML = '.esri-truncated-attribution:hover {' + - 'white-space: normal;' + 'white-space: normal;' + '}'; document.getElementsByTagName('head')[0].appendChild(hoverAttributionStyle); @@ -167,7 +169,7 @@ export function setEsriAttribution (map) { 'display: inline-block;' + 'transition: 0s white-space;' + 'transition-delay: 1s;' + - 'max-width:' + calcAttributionWidth(map) +';' + 'max-width: ' + calcAttributionWidth(map) + ';' + '}'; document.getElementsByTagName('head')[0].appendChild(attributionStyle);