Skip to content

Commit

Permalink
make max-width of attribution control configurable (#849)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jgravois authored Sep 28, 2016
1 parent adf7237 commit 3cf3b88
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ coverage
# Debugging Files
working
debug/*.html
debug/archive/
!debug/sample.html

# Docs Build
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/EsriLeaflet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
5 changes: 5 additions & 0 deletions src/Options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export var Options = {
attributionWidthOffset: 55
};

export default Options;
10 changes: 6 additions & 4 deletions src/Util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import L from 'leaflet';
import { jsonp } from './Request';
import { Options } from './Options';

import {
geojsonToArcGIS as g2a,
arcgisToGeoJSON as a2g
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 3cf3b88

Please sign in to comment.