Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a css file rather than inline styles. #660

Merged
merged 2 commits into from
Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/common/css/examples.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ html, body {
#map {
width: 100%;
height: calc(100% - 60px);
overflow: hidden;
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/annotationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
53 changes: 27 additions & 26 deletions src/canvas/canvasRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ var canvasRenderer = function (arg) {
renderer.call(this, arg);

var m_this = this,
m_renderAnimFrameRef = null,
m_clearCanvas = true,
s_init = this._init,
s_exit = this._exit;
Expand Down Expand Up @@ -57,8 +56,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);
Expand Down Expand Up @@ -89,32 +87,35 @@ var canvasRenderer = function (arg) {
*/
////////////////////////////////////////////////////////////////////////////
this._render = function () {
if (m_renderAnimFrameRef === null) {
m_renderAnimFrameRef = window.requestAnimationFrame(function () {
m_renderAnimFrameRef = null;

var layer = m_this.layer(),
map = layer.map(),
camera = map.camera(),
viewport = camera._viewport;

// Clear the canvas.
if (m_clearCanvas) {
m_this.context2d.setTransform(1, 0, 0, 1, 0, 0);
m_this.context2d.clearRect(0, 0, viewport.width, viewport.height);
}

var features = layer.features();
for (var i = 0; i < features.length; i += 1) {
if (features[i].visible()) {
features[i]._renderOnCanvas(m_this.context2d, map);
}
}
});
}
m_this.layer().map().scheduleAnimationFrame(this._renderFrame);
return m_this;
};

////////////////////////////////////////////////////////////////////////////
/**
* Render during an animation frame callback.
*/
////////////////////////////////////////////////////////////////////////////
this._renderFrame = function () {
var layer = m_this.layer(),
map = layer.map(),
camera = map.camera(),
viewport = camera._viewport;

// Clear the canvas.
if (m_clearCanvas) {
m_this.context2d.setTransform(1, 0, 0, 1, 0, 0);
m_this.context2d.clearRect(0, 0, viewport.width, viewport.height);
}

var features = layer.features();
for (var i = 0; i < features.length; i += 1) {
if (features[i].visible()) {
features[i]._renderOnCanvas(m_this.context2d, map);
}
}
};

////////////////////////////////////////////////////////////////////////////
/**
* Exit
Expand Down
18 changes: 16 additions & 2 deletions src/canvas/heatmapFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var canvas_heatmapFeature = function (arg) {
m_typedClampedBuffer,
m_typedBufferData,
m_heatMapPosition,
m_heatMapTransform,
s_exit = this._exit,
s_init = this._init,
s_update = this._update,
Expand Down Expand Up @@ -349,7 +350,9 @@ 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'});
m_heatMapTransform = '';
map.scheduleAnimationFrame(m_this._setTransform, false);
layer.canvas().css({transform: ''});

m_this._createCircle();
m_this._computeGradient();
Expand Down Expand Up @@ -408,6 +411,16 @@ var canvas_heatmapFeature = function (arg) {
return m_this;
};

////////////////////////////////////////////////////////////////////////////
/**
* Update the css transform for the layer as part of an animation frame.
* @protected
*/
////////////////////////////////////////////////////////////////////////////
this._setTransform = function () {
m_this.layer().canvas()[0].style.transform = m_heatMapTransform;
};

////////////////////////////////////////////////////////////////////////////
/**
* Animate pan (and zoom)
Expand All @@ -434,8 +447,9 @@ var canvas_heatmapFeature = function (arg) {
' scale(' + scale + ')' +
' rotate(' + ((rotation - m_heatMapPosition.rotation) * 180 / Math.PI) + 'deg)';

m_this.layer().canvas()[0].style.transform = transform;
map.scheduleAnimationFrame(m_this._setTransform);

m_heatMapTransform = transform;
m_heatMapPosition.lastScale = scale;
m_heatMapPosition.lastOrigin.x = origin.x;
m_heatMapPosition.lastOrigin.y = origin.y;
Expand Down
3 changes: 1 addition & 2 deletions src/gl/vglRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
var $ = require('jquery');
require('./polyfills');

require('./main.styl');

module.exports = $.extend({
annotation: require('./annotation'),
annotationLayer: require('./annotationLayer'),
Expand Down
8 changes: 2 additions & 6 deletions src/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions src/main.styl
Original file line number Diff line number Diff line change
@@ -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
19 changes: 2 additions & 17 deletions src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -1518,19 +1518,7 @@ var map = function (arg) {
// generate a new attribution node
var $a = $('<div/>')
.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();
});

Expand All @@ -1540,9 +1528,6 @@ var map = function (arg) {
if (content) {
$('<span/>')
.addClass('geo-attribution-layer')
.css({
'padding-left': '5px'
})
.html(content)
.appendTo($a);
}
Expand Down
12 changes: 3 additions & 9 deletions src/tileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
}

Expand Down Expand Up @@ -1005,11 +1003,7 @@ module.exports = (function () {
if (!node) {
node = $(
'<div class=geo-tile-layer data-tile-layer="' + level.toFixed() + '"/>'
).css({
'transform-origin': '0px 0px',
'line-height': 0,
'font-size': 0
}).get(0);
).get(0);
this.canvas().append(node);
}
return node;
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/tileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ describe('geo.tileLayer', function () {
});
});

describe('HTML renderering', function () {
describe('HTML rendering', function () {
function layer_html(opts) {
var node = $('<div class="geo-test-container" style="display: none"/>'), m, l;
opts = opts || {};
Expand Down
3 changes: 0 additions & 3 deletions webpack-examples.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ var external = require('./external.config');
require('./examples/build');

var loaders = base.module.loaders.concat([{
test: /\.css$/,
loader: 'style-loader!css-loader'
}, {
test: /\.jade$/,
loader: 'jade'
}, {
Expand Down
6 changes: 6 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ module.exports = {
loaders: [{
test: /\.json$/,
loader: 'json-loader'
}, {
test: /\.styl$/,
loader: 'style-loader!css-loader!stylus-loader'
}, {
test: /\.css$/,
loader: 'style-loader!css-loader'
}, {
test: /vgl\.js$/,
loader: 'expose?vgl!imports?mat4=gl-mat4,vec4=gl-vec4,vec3=gl-vec3,vec2=gl-vec2,$=jquery'
Expand Down