在main_map.js您有:
// Insert the <div> into the body document.
document.body.appendChild(div);
这就是为什么它是一切后,产生的原因。
创建自己的div + id和appendChild()代替body标签。 DEMO
var apme = document.getElementById('ap');
// Create the div we'll be slotting the map into and set it to the correct size.
var div = document.createElement('div');
div.setAttribute('id', "mobilize_maine_map");
div.style.width = "200px";
div.style.height = "200px";
div.style.borderWidth = "1px";
div.style.borderColor = "#000";
div.style.borderStyle = "solid";
// Insert the <div> into the heml document.
apme.appendChild(div);
现在,这个div被插入在div#AP内。这个div可以是你希望在你的标记中的任何地方。
<edit>
你做:
// Create the div we'll be slotting the map into and set it to the correct size.
var div = document.createElement('div');
div.setAttribute('id', "mobilize_maine_map");
div.style.width = divWidth+"px";
div.style.height = divHeight+"px";
// div.style.borderWidth = "0px";
// div.style.borderColor = "#000";
// div.style.borderStyle = "solid";
// Insert the <div> into the heml document.
document.body.appendChild(div);
var apme = document.getElementById('map');
// Create the div we'll be slotting the map into and set it to the correct size.
var div = document.createElement('div');
div.setAttribute('id', "mobilize_maine_map");
div.style.width = "203px";
div.style.height = "306px";
div.style.borderWidth = "0px";
div.style.borderColor = "#000";
div.style.borderStyle = "solid";
// Insert the <div> into the heml document.
apme.appendChild(div);
这使得2格用相同的ID,这是不是你找什么:)。
您应该已经删除了:
// Create the div we'll be slotting the map into and set it to the correct size.
var div = document.createElement('div');
div.setAttribute('id', "mobilize_maine_map");
div.style.width = divWidth+"px";
div.style.height = divHeight+"px";
// div.style.borderWidth = "0px";
// div.style.borderColor = "#000";
// div.style.borderStyle = "solid";
// Insert the <div> into the heml document.
document.body.appendChild(div);
并将其替换为:
var apme = document.getElementById('map');
// Create the div we'll be slotting the map into and set it to the correct size.
var div = document.createElement('div');
div.setAttribute('id', "mobilize_maine_map");
div.style.width = divWidth+"px";
div.style.height = divHeight+"px";
// Insert the <div> into the heml document.
apme.appendChild(div);
这样做的工作。非常感谢你。我从来不会想到我自己的! – user2984710
现在我已经有了这个工作,我意识到脚本在页面的底部推送了额外的空白空间 - 在你提出上述编辑之前,SVG地图在哪里。你有什么想法可以解决这个问题吗? – user2984710
@ user2984710我会编辑我的答案给你看。不要犹豫,给点或接受答案的方式 –