如何缩放图像以正确适合容器尺寸?我想要一个两个图像和每个图像的网格,以适应提供的大小.
https://codepen.io/peteringram0/pen/gebYWo?editors=0010
img.set({
left: 0,
top: 0,
width: 300,
height: 300
// Scale image to fit width / height ?
});
Run Code Online (Sandbox Code Playgroud)
编辑:对不起,我没有非常清楚地解释我的问题.我希望将其定位在网格中,但作为"封面"类型.https://codepen.io/peteringram0/pen/xWwZmy?editors=0011.例如,在链接中,网格中有4个图像,但图像位于中心并且溢出.我想让每个图像垂直居中,没有超出设定大小的溢出.谢谢(x应该在中心,同时保持纵横比)
升级到babel 7.1.5后,当我使用import * as时,我的测试失败。
test.spec.js
import * as Helper from "../../../../src/renderer/modules/Helper";
describe('Testing', () => {
it('Should import correctly', () => {
console.log(Helper.test()) // a
spyOn(Helper, 'test').and.returnValue('b');
});
});
Run Code Online (Sandbox Code Playgroud)
Helper.js
function test() {
return 'a'
}
export {test}
Run Code Online (Sandbox Code Playgroud)
错误
'Upgrade.spec.js (7:8)', 'a'
Error: <spyOn> : test is not declared writable or has no setter
Usage: spyOn(<object>, <methodName>)
at <Jasmine>
at UserContext.it (webpack:///./test/unit/specs/renderer/Upgrade.spec.js?:7:5)
at <Jasmine>
Run Code Online (Sandbox Code Playgroud) 我使用以下 UK Geo JSON 来渲染英国 SVG 地图 http://martinjc.github.io/UK-GeoJSON/json/eng/topo_eer.json
在这张地图上,我希望能够获取经度+纬度点并绘制在地图上。
我通过以下方式将 GeometryCollection 位置添加到地图中:
data.objects.places = {
type: "GeometryCollection",
geometries: [
{
type: "Point",
coordinates: [-0.127758, 51.507351], // London
properties: {
name: "London - Testing"
}
}
]
};
Run Code Online (Sandbox Code Playgroud)
但是坐标未位于正确的位置。
下面是完整的 JavaScript。
var width = 960;
var height = 1000;
var projection = d3.geo.albers()
.center([0, 55.4])
.rotate([4.4, 0])
.parallels([50, 60])
.scale(4000)
.translate([width / 2, height / 2]);
var path = d3.geo.path().projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("topo_eer.json", function(error, data) …Run Code Online (Sandbox Code Playgroud)