我使用Html2Canvas和傳單。當我向左,向右,向上或向下平移地圖,然後導出時,我會得到一張我失蹤的地圖。此外,我的疊加層不再存在。但是,如果我不平移,我會覆蓋覆蓋。這是缺少瓷磚的照片。 圖像缺失瓷磚和svg
有沒有人知道如何解決這個問題?
這裏是我的代碼
//CSS
/* Map */
#map {
height: 440px;
}
//HTML
<div id="map"></div>
<div id="exportDiv">
<button id="btnClickHere" type="button">Click Me!</button>
</div>
//Javascript
var tilesReady;
$(document).ready(function() {
buildMap();
$("#btnClickHere").on("click", function() {
exportMap();
});
});
function exportMap() {
//get transform value
html2canvas($("#map")[0], {
useCORS: true,
background: "#E8F0F6",
onrendered: function (canvas) {
var a = document.createElement('a');
a.download = name;
a.href = canvas.toDataURL('image/png');
document.body.appendChild(a);
a.click();
},
width: 800,
height: 500
});
}
function buildMap() {
tilesReady = false;
map = L.map('map', {
center: [28.418749, -81.581211],
zoom: 12
});
var data = [{
"coords": [28.3710, -81.5500],
"time": 1
}, {
"coords": [28.4186, -81.5811],
"time": 2
}, {
"coords": [28.3570, -81.5561],
"time": 3
}];
var layers = L.tileLayer('http://{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.png', {
attribution: "Map: Tiles Courtesy of MapQuest (OpenStreetMap, CC-BY-SA)",
subdomains: ["otile1", "otile2", "otile3", "otile4"],
maxZoom: 18,
minZoom: 2
}).addTo(map);
/* Initialize the SVG layer */
map._initPathRoot();
/* We simply pick up the SVG from the map object */
var svg = d3.select("#map").select("svg"),
g = svg.append("g");
/* Add a LatLng object to each item in the dataset */
data.forEach(function (d) {
d.LatLng = new L.LatLng(d.coords[0],
d.coords[1]);
});
var feature = g.selectAll("circle")
.data(data)
.enter().append("circle")
.style("stroke", "black")
.style("opacity", '.6')
.style("fill", "red")
.attr("r", 20);
map.on("viewreset", update);
update();
function update() {
feature.attr("transform",
function (d) {
return "translate(" + map.latLngToLayerPoint(d.LatLng).x + "," + map.latLngToLayerPoint(d.LatLng).y + ")";
});
}
}
我們就需要看你的代碼必須在回答這個機會。 –
請編輯問題並在其中添加代碼,而我並不只是指實際的代碼。 –