From 3a22b01c88292b0be2c89bf90f9714db6f1c9e82 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Mon, 16 Jan 2017 10:20:09 -0500 Subject: [PATCH 1/2] Use a css file rather than inline styles. --- examples/common/css/examples.css | 1 + package.json | 3 ++ src/annotationLayer.js | 2 +- src/canvas/canvasRenderer.js | 3 +- src/canvas/heatmapFeature.js | 2 +- src/gl/vglRenderer.js | 3 +- src/index.js | 2 ++ src/layer.js | 8 ++---- src/main.styl | 47 ++++++++++++++++++++++++++++++++ src/map.js | 19 ++----------- src/tileLayer.js | 12 ++------ tests/cases/tileLayer.js | 2 +- webpack-examples.config.js | 3 -- webpack.config.js | 6 ++++ 14 files changed, 71 insertions(+), 42 deletions(-) create mode 100644 src/main.styl diff --git a/examples/common/css/examples.css b/examples/common/css/examples.css index 2804a78433..57c8c30091 100644 --- a/examples/common/css/examples.css +++ b/examples/common/css/examples.css @@ -16,4 +16,5 @@ html, body { #map { width: 100%; height: calc(100% - 60px); + overflow: hidden; } diff --git a/package.json b/package.json index c1dec27c00..ec9ec217b2 100644 --- a/package.json +++ b/package.json @@ -62,12 +62,15 @@ "karma-webpack": "^1.7.0", "mousetrap": "^1.6.0", "node-fs-extra": "^0.8.1", + "nib": "^1.1.2", "node-resemble": "^1.1.3", "phantomjs-prebuilt": "^2.1.5", "proj4": "^2.3.14", "raw-body": "^2.1.6", "sinon": "1.17.3", "style-loader": "^0.13.1", + "stylus": "^0.54.5", + "stylus-loader": "^2.4.0", "url-loader": "^0.5.7", "vgl": "0.3.10", "webpack": "^1.12.14", diff --git a/src/annotationLayer.js b/src/annotationLayer.js index 93cf89a67d..9f4558fbdf 100644 --- a/src/annotationLayer.js +++ b/src/annotationLayer.js @@ -326,7 +326,7 @@ var annotationLayer = function (args) { var createAnnotation, actions, mapNode = m_this.map().node(), oldMode = m_mode; m_mode = arg; - mapNode.css('cursor', m_mode ? 'crosshair' : ''); + mapNode.toggleClass('annotation-input', !!m_mode); if (m_mode) { Mousetrap(mapNode[0]).bind('esc', function () { m_this.mode(null); }); } else { diff --git a/src/canvas/canvasRenderer.js b/src/canvas/canvasRenderer.js index f6bab2ce5b..8e2bf9d0b2 100644 --- a/src/canvas/canvasRenderer.js +++ b/src/canvas/canvasRenderer.js @@ -57,8 +57,7 @@ var canvasRenderer = function (arg) { var canvas = $(document.createElement('canvas')); m_this.context2d = canvas[0].getContext('2d'); - canvas.attr('class', 'canvas-canvas'); - canvas.css('display', 'block'); + canvas.addClass('canvas-canvas'); $(m_this.layer().node().get(0)).append(canvas); m_this.canvas(canvas); diff --git a/src/canvas/heatmapFeature.js b/src/canvas/heatmapFeature.js index 1ff1fc920d..e3a1590a98 100644 --- a/src/canvas/heatmapFeature.js +++ b/src/canvas/heatmapFeature.js @@ -349,7 +349,7 @@ var canvas_heatmapFeature = function (arg) { context2d.setTransform(1, 0, 0, 1, 0, 0); context2d.clearRect(0, 0, viewport.width, viewport.height); - layer.canvas().css({transform: '', 'transform-origin': '0px 0px'}); + layer.canvas().css({transform: ''}); m_this._createCircle(); m_this._computeGradient(); diff --git a/src/gl/vglRenderer.js b/src/gl/vglRenderer.js index 076a5a33b6..51cc9a0669 100644 --- a/src/gl/vglRenderer.js +++ b/src/gl/vglRenderer.js @@ -87,8 +87,7 @@ var vglRenderer = function (arg) { s_init.call(m_this); var canvas = $(document.createElement('canvas')); - canvas.attr('class', 'webgl-canvas'); - canvas.css('display', 'block'); + canvas.addClass('webgl-canvas'); $(m_this.layer().node().get(0)).append(canvas); if (window.contextPreserveDrawingBuffer) { diff --git a/src/index.js b/src/index.js index dfc38e7ce6..b49958d7d3 100644 --- a/src/index.js +++ b/src/index.js @@ -30,6 +30,8 @@ var $ = require('jquery'); require('./polyfills'); +require('./main.styl'); + module.exports = $.extend({ annotation: require('./annotation'), annotationLayer: require('./annotationLayer'), diff --git a/src/layer.js b/src/layer.js index c8f22c4197..74cf53a6ae 100644 --- a/src/layer.js +++ b/src/layer.js @@ -386,9 +386,7 @@ var layer = function (arg) { m_canvas = m_renderer.canvas(); } - if (!m_this.active()) { - m_node.css('pointerEvents', 'none'); - } + m_node.toggleClass('active', m_this.active()); m_initialized = true; @@ -481,10 +479,8 @@ var layer = function (arg) { // Create top level div for the layer m_node = $(document.createElement('div')); + m_node.addClass('geojs-layer'); m_node.attr('id', m_name); - m_node.css('position', 'absolute'); - m_node.css('width', '100%'); - m_node.css('height', '100%'); m_this.opacity(m_opacity); // set the z-index diff --git a/src/main.styl b/src/main.styl new file mode 100644 index 0000000000..801c804ec6 --- /dev/null +++ b/src/main.styl @@ -0,0 +1,47 @@ +@import '~nib/index.styl' + +.geojs-map + position relative + + .geo-attribution + position absolute + right 0px + bottom 0px + padding-right 5px + cursor auto + font 11px/1.5 "Helvetica Neue", Arial, Helvetica, sans-serif + z-index 1001 + background rgba(255,255,255,0.7) + clear both + display block + pointer-events auto + + .geo-attribution-layer + padding-left 5px + + .canvas-canvas + display block + transform-origin 0px 0px + .webgl-canvas + display block + + .geojs-layer + position absolute + width 100% + height 100% + pointer-events none + &.active + pointer-events auto + + .geo-tile-layer + transform-origin 0px 0px + line-height 0 + font-size 0 + + &.annotation-input + cursor crosshair + +.geo-tile-container + position absolute + &.crop + overflow hidden diff --git a/src/map.js b/src/map.js index 1eaa639815..adb21005ef 100644 --- a/src/map.js +++ b/src/map.js @@ -894,7 +894,7 @@ var map = function (arg) { throw 'Map require DIV node'; } - m_node.css('position', 'relative'); + m_node.addClass('geojs-map'); return m_this; }; @@ -1518,19 +1518,7 @@ var map = function (arg) { // generate a new attribution node var $a = $('
') .addClass('geo-attribution') - .css({ - position: 'absolute', - right: '0px', - bottom: '0px', - 'padding-right': '5px', - cursor: 'auto', - font: '11px/1.5 "Helvetica Neue", Arial, Helvetica, sans-serif', - 'z-index': '1001', - background: 'rgba(255,255,255,0.7)', - clear: 'both', - display: 'block', - 'pointer-events': 'auto' - }).on('mousedown', function (evt) { + .on('mousedown', function (evt) { evt.stopPropagation(); }); @@ -1540,9 +1528,6 @@ var map = function (arg) { if (content) { $('') .addClass('geo-attribution-layer') - .css({ - 'padding-left': '5px' - }) .html(content) .appendTo($a); } diff --git a/src/tileLayer.js b/src/tileLayer.js index c61c6f587a..ac39d2a963 100644 --- a/src/tileLayer.js +++ b/src/tileLayer.js @@ -779,17 +779,15 @@ module.exports = (function () { // apply a transform to place the image correctly container.append(tile.image); container.css({ - position: 'absolute', left: (bounds.left - parseInt(div.attr('offsetx') || 0, 10)) + 'px', top: (bounds.top - parseInt(div.attr('offsety') || 0, 10)) + 'px' }); crop = this.tileCropFromBounds(tile); if (crop) { - container.css({ + container.addClass('crop').css({ width: crop.x + 'px', - height: crop.y + 'px', - overflow: 'hidden' + height: crop.y + 'px' }); } @@ -1005,11 +1003,7 @@ module.exports = (function () { if (!node) { node = $( '
' - ).css({ - 'transform-origin': '0px 0px', - 'line-height': 0, - 'font-size': 0 - }).get(0); + ).get(0); this.canvas().append(node); } return node; diff --git a/tests/cases/tileLayer.js b/tests/cases/tileLayer.js index ad2eb3c286..a4a1cc872b 100644 --- a/tests/cases/tileLayer.js +++ b/tests/cases/tileLayer.js @@ -1332,7 +1332,7 @@ describe('geo.tileLayer', function () { }); }); - describe('HTML renderering', function () { + describe('HTML rendering', function () { function layer_html(opts) { var node = $('