JavaScript之谜似乎没有人能弄明白——复制到剪贴板并不总是在相同的值上工作。无误
我是一个比较新的人,我知道我的代码不是很好,但我正在学习,并且仍然处于使事情变得更好的步骤中,在我着手使事情变得更好之前 我用小册子做了一张地图。当我单击某个地方时,它会提示我输入标题、说明和图标,它们会复制一行填充了提示值的代码。我可以将该代码粘贴到js文件中,以便在地图上永久添加这些标记。不是最好的,但就像我说的,先做,后改进 我遇到的问题是,似乎没有人能够帮助我,有时,它似乎是武断地,不会将代码复制到我的剪贴板上。我试过排除故障,但我无法确定问题所在。而且,没有错误 这是我的整个项目(19mb):-我的代码在HTML文件和markers.js中 以下是JavaScript/HTML本身:JavaScript之谜似乎没有人能弄明白——复制到剪贴板并不总是在相同的值上工作。无误,javascript,leaflet,copy,clipboard,Javascript,Leaflet,Copy,Clipboard,我是一个比较新的人,我知道我的代码不是很好,但我正在学习,并且仍然处于使事情变得更好的步骤中,在我着手使事情变得更好之前 我用小册子做了一张地图。当我单击某个地方时,它会提示我输入标题、说明和图标,它们会复制一行填充了提示值的代码。我可以将该代码粘贴到js文件中,以便在地图上永久添加这些标记。不是最好的,但就像我说的,先做,后改进 我遇到的问题是,似乎没有人能够帮助我,有时,它似乎是武断地,不会将代码复制到我的剪贴板上。我试过排除故障,但我无法确定问题所在。而且,没有错误 这是我的整个项目(19
绿色互动地图
#mapid{
高度:99vh;
宽度:99vw;
光标:十字线;
}
var map=L.map('mapid',{attributecontrol:false}).setView(新的L.LatLng(0,0),0);
var dzLayer=L.tileLayer.deepzoom('DZI2/westergreen_files/',{
宽度:7604,
身高:9071
}).addTo(地图);
fitBounds(dzLayer.options.bounds);
点击功能(点击位置){
var POITHEL=提示(“输入POI标题”、“梅洛瀑布”);
控制台日志(“标题:+POITHELL”);
如果(POITHELL==null | | POITHELL==''){
警报(“取消标记”);
返回;
}
var POIdesc=prompt(“输入该POI的描述”);
console.log(“DESC:+POIdesc”);
if(POIdesc==null){
警报(“取消标记”);
返回;
}
var POICON=prompt(“输入POI图标\n默认值(空白)\n城镇(t)\n村庄(a)\n大城市(bc)\n洞穴(c)\n洞穴2(c2)\n洞穴(d)\n洞穴(dh)\n洞穴(f)\n洞穴(g)\n中世纪城堡(mc)\n洞穴(s)\n白色骷髅(ws)\n山脉(mn)\n小帐篷(st)\n”、“”);
控制台日志(“图标:+POICON”);
var poiconparsed=“默认”;
如果(POICON==null){
警报(“取消标记”);
返回;
}
控制台日志(“预切换”);
开关(POICON){
案例“”:
POIConParsed=“defaultIcon”
打破
案例“a”:
POICONPARSED=“铁砧图标”
打破
案例“bc”:
POICONPARSED=“bigCityIcon”
打破
案例“c”:
POICONPARSED=“caveIcon”
打破
案例“c2”:
POICONPARSED=“cave2con”
打破
案例“d”:
POICONPARSED=“dockIcon”
打破
个案“dh”:
POICONPARSED=“dockhouseIcon”
打破
案例“f”:
POICONPARSED=“堡垒图标”
打破
案例“g”:
POICONPARSED=“网关图标”
打破
案例“mc”:
POICONPARSED=“mediumcastleIcon”
打破
案例“s”:
POICONPARSED=“skullIcon”
打破
案例“ws”:
POICONPARSED=“whiteskullIcon”
打破
案例“mn”:
poiconParsed=“mineIcon”
打破
案例“st”:
POICONPARSED=“smalltentIcon”
打破
案例“t”:
POICONPARSED=“townIcon”
打破
}
控制台日志(“post开关”);
var POITETLEVAR=POITTILE.replace(/\s+/g',);
copyToClipboard('var'+POItitleVar+'=L.marker(['+clickedPos.latlng.lat+','+clickedPos.latlng.lng+'],{icon:'+poiconParsed+}).addTo(map);\n'+POItitleVar+'.bindpoppopup('+poitile+'
'+POIdesc+'));
}
map.on('click',onmaclick);
console.log(“剪贴板前函数”);
功能copyToClipboard(文本){
var dummy=document.createElement(“textarea”);
文件.正文.附件子文件(假人);
dummy.value=文本;
dummy.select();
文件。执行命令(“副本”);
document.body.removeChild(虚拟);
log(“剪贴板结束函数”);
}
console.log(“后剪贴板函数”);
//图标
var anvilIcon=L.icon({
iconUrl:'images/icon\u anvil.png',
shadowUrl:'images/icon shadow.png',
图标大小:[26,23],//图标的大小
阴影大小:[26,23],//阴影的大小
iconAnchor:[13,30],//对应于标记位置的图标点
阴影锚:[13,27],//阴影也一样
popupAnchor:[0,-25]//相对于iconAnchor打开弹出窗口的点
});
var bigCityIcon=L.icon({
iconUrl:'images/icon_big.png',
shadowUrl:'images/icon shadow.png',
图标大小:[26,23],//图标的大小
阴影大小:[26,23],//阴影的大小
iconAnchor:[13,30],//对应于标记位置的图标点
阴影锚:[13,27],//阴影也一样
popupAnchor:[0,-25]//相对于iconAnchor打开弹出窗口的点
});
var caveIcon=L.icon
<html>
<head>
<meta charset="utf-8">
<title>Westergreen Interactive Map</title>
<link rel="stylesheet" href="leaflet.css" />
<style type="text/css">
#mapid {
height: 99vh;
width: 99vw;
cursor: crosshair;
}
</style>
</head>
<body>
<div id="mapid"></div>
<script type="text/javascript" src="leaflet.js"></script>
<script type="text/javascript" src="leaflet-deepzoom.js"></script>
<script type="text/javascript">
var map = L.map('mapid', { attributionControl:false }).setView(new L.LatLng(0,0), 0);
var dzLayer = L.tileLayer.deepzoom('DZI2/westergreen_files/', {
width: 7604,
height: 9071
}).addTo(map);
map.fitBounds(dzLayer.options.bounds);
function onMapClick(clickedPos) {
var POItitle = prompt("Enter POI title", "Mellow Falls");
console.log("TITLE: " + POItitle);
if(POItitle == null || POItitle == ''){
alert("Cancelled marker.");
return;
}
var POIdesc = prompt("Enter a description for that POI", "");
console.log("DESC: " + POIdesc);
if(POIdesc == null){
alert("Cancelled marker.");
return;
}
var POIicon = prompt("Enter POI icon \n default (blank)\ntown (t)\nanvil (a)\nbigCity (bc)\ncave (c)\ncave2 (c2)\ndock (d)\ndockhouse (dh)\nfortress (f)\ngate (g)\nmedium castle (mc)\nskull (s)\nwhite skull (ws)\nmine (mn)\nsmall tent (st)\n", "");
console.log("ICON: " + POIicon);
var POIiconParsed = "default";
if(POIicon == null){
alert("Cancelled marker.");
return;
}
console.log("pre switch");
switch(POIicon) {
case "":
POIiconParsed = "defaultIcon"
break;
case "a":
POIiconParsed = "anvilIcon"
break;
case "bc":
POIiconParsed = "bigCityIcon"
break;
case "c":
POIiconParsed = "caveIcon"
break;
case "c2":
POIiconParsed = "cave2Icon"
break;
case "d":
POIiconParsed = "dockIcon"
break;
case "dh":
POIiconParsed = "dockhouseIcon"
break;
case "f":
POIiconParsed = "fortressIcon"
break;
case "g":
POIiconParsed = "gateIcon"
break;
case "mc":
POIiconParsed = "mediumcastleIcon"
break;
case "s":
POIiconParsed = "skullIcon"
break;
case "ws":
POIiconParsed = "whiteskullIcon"
break;
case "mn":
POIiconParsed = "mineIcon"
break;
case "st":
POIiconParsed = "smalltentIcon"
break;
case "t":
POIiconParsed = "townIcon"
break;
}
console.log("post switch");
var POItitleVar = POItitle.replace(/\s+/g, '');
copyToClipboard('var ' + POItitleVar + ' = L.marker([' + clickedPos.latlng.lat + ', ' + clickedPos.latlng.lng + '], {icon: ' + POIiconParsed + '}).addTo(map);\n' + POItitleVar + '.bindPopup("<b>' + POItitle + '</b><br />' + POIdesc + '");');
}
map.on('click', onMapClick);
console.log("pre clipboard func");
function copyToClipboard(text) {
var dummy = document.createElement("textarea");
document.body.appendChild(dummy);
dummy.value = text;
dummy.select();
document.execCommand("copy");
document.body.removeChild(dummy);
console.log("end of clipboard func");
}
console.log("post clipboard func");
// ICONS
var anvilIcon = L.icon({
iconUrl: 'images/icon_anvil.png',
shadowUrl: 'images/icon-shadow.png',
iconSize: [26, 23], // size of the icon
shadowSize: [26, 23], // size of the shadow
iconAnchor: [13, 30], // point of the icon which will correspond to marker's location
shadowAnchor: [13, 27], // the same for the shadow
popupAnchor: [0, -25] // point from which the popup should open relative to the iconAnchor
});
var bigCityIcon = L.icon({
iconUrl: 'images/icon_big.png',
shadowUrl: 'images/icon-shadow.png',
iconSize: [26, 23], // size of the icon
shadowSize: [26, 23], // size of the shadow
iconAnchor: [13, 30], // point of the icon which will correspond to marker's location
shadowAnchor: [13, 27], // the same for the shadow
popupAnchor: [0, -25] // point from which the popup should open relative to the iconAnchor
});
var caveIcon = L.icon({
iconUrl: 'images/icon_cave.png',
shadowUrl: 'images/icon-shadow.png',
iconSize: [26, 23], // size of the icon
shadowSize: [26, 23], // size of the shadow
iconAnchor: [13, 30], // point of the icon which will correspond to marker's location
shadowAnchor: [13, 27], // the same for the shadow
popupAnchor: [0, -25] // point from which the popup should open relative to the iconAnchor
});
var townIcon = L.icon({
iconUrl: 'images/icon_town.png',
shadowUrl: 'images/icon-shadow.png',
iconSize: [26, 23], // size of the icon
shadowSize: [26, 23], // size of the shadow
iconAnchor: [13, 30], // point of the icon which will correspond to marker's location
shadowAnchor: [13, 27], // the same for the shadow
popupAnchor: [0, -25] // point from which the popup should open relative to the iconAnchor
});
var cave2Icon = L.icon({
iconUrl: 'images/icon_cave2.png',
shadowUrl: 'images/icon-shadow.png',
iconSize: [26, 23], // size of the icon
shadowSize: [26, 23], // size of the shadow
iconAnchor: [13, 30], // point of the icon which will correspond to marker's location
shadowAnchor: [13, 27], // the same for the shadow
popupAnchor: [0, -25] // point from which the popup should open relative to the iconAnchor
});
var dockIcon = L.icon({
iconUrl: 'images/icon_dock.png',
shadowUrl: 'images/icon-shadow.png',
iconSize: [26, 23], // size of the icon
shadowSize: [26, 23], // size of the shadow
iconAnchor: [13, 30], // point of the icon which will correspond to marker's location
shadowAnchor: [13, 27], // the same for the shadow
popupAnchor: [0, -25] // point from which the popup should open relative to the iconAnchor
});
var dockhouseIcon = L.icon({
iconUrl: 'images/icon_dockhouse.png',
shadowUrl: 'images/icon-shadow.png',
iconSize: [26, 23], // size of the icon
shadowSize: [26, 23], // size of the shadow
iconAnchor: [13, 30], // point of the icon which will correspond to marker's location
shadowAnchor: [13, 27], // the same for the shadow
popupAnchor: [0, -25] // point from which the popup should open relative to the iconAnchor
});
var fortressIcon = L.icon({
iconUrl: 'images/icon_fortress.png',
shadowUrl: 'images/icon-shadow.png',
iconSize: [26, 23], // size of the icon
shadowSize: [26, 23], // size of the shadow
iconAnchor: [13, 30], // point of the icon which will correspond to marker's location
shadowAnchor: [13, 27], // the same for the shadow
popupAnchor: [0, -25] // point from which the popup should open relative to the iconAnchor
});
var gateIcon = L.icon({
iconUrl: 'images/icon_gate.png',
shadowUrl: 'images/icon-shadow.png',
iconSize: [26, 23], // size of the icon
shadowSize: [26, 23], // size of the shadow
iconAnchor: [13, 30], // point of the icon which will correspond to marker's location
shadowAnchor: [13, 27], // the same for the shadow
popupAnchor: [0, -25] // point from which the popup should open relative to the iconAnchor
});
var mediumcastleIcon = L.icon({
iconUrl: 'images/icon_medium.png',
shadowUrl: 'images/icon-shadow.png',
iconSize: [26, 23], // size of the icon
shadowSize: [26, 23], // size of the shadow
iconAnchor: [13, 30], // point of the icon which will correspond to marker's location
shadowAnchor: [13, 27], // the same for the shadow
popupAnchor: [0, -25] // point from which the popup should open relative to the iconAnchor
});
var skullIcon = L.icon({
iconUrl: 'images/icon_skull.png',
shadowUrl: 'images/icon-shadow.png',
iconSize: [26, 23], // size of the icon
shadowSize: [26, 23], // size of the shadow
iconAnchor: [13, 30], // point of the icon which will correspond to marker's location
shadowAnchor: [13, 27], // the same for the shadow
popupAnchor: [0, -25] // point from which the popup should open relative to the iconAnchor
});
var mineIcon = L.icon({
iconUrl: 'images/icon_mine.png',
shadowUrl: 'images/icon-shadow.png',
iconSize: [26, 23], // size of the icon
shadowSize: [26, 23], // size of the shadow
iconAnchor: [13, 30], // point of the icon which will correspond to marker's location
shadowAnchor: [13, 27], // the same for the shadow
popupAnchor: [0, -25] // point from which the popup should open relative to the iconAnchor
});
var smalltentIcon = L.icon({
iconUrl: 'images/icon_tentsmall.png',
shadowUrl: 'images/icon-shadow.png',
iconSize: [26, 23], // size of the icon
shadowSize: [26, 23], // size of the shadow
iconAnchor: [13, 30], // point of the icon which will correspond to marker's location
shadowAnchor: [13, 27], // the same for the shadow
popupAnchor: [0, -25] // point from which the popup should open relative to the iconAnchor
});
var whiteskullIcon = L.icon({
iconUrl: 'images/icon_whiteskull.png',
shadowUrl: 'images/icon-shadow.png',
iconSize: [26, 23], // size of the icon
shadowSize: [26, 23], // size of the shadow
iconAnchor: [13, 30], // point of the icon which will correspond to marker's location
shadowAnchor: [13, 27], // the same for the shadow
popupAnchor: [0, -25] // point from which the popup should open relative to the iconAnchor
});
var defaultIcon = L.icon({
iconUrl: 'images/marker-icon.png',
shadowUrl: 'images/marker-shadow.png',
iconSize: [25, 41], // size of the icon
shadowSize: [41, 41], // size of the shadow
iconAnchor: [13, 30], // point of the icon which will correspond to marker's location
shadowAnchor: [13, 27], // the same for the shadow
popupAnchor: [0, -25] // point from which the popup should open relative to the iconAnchor
});
</script>
<script type="text/javascript" src="markers.js"></script>
</body>
</html>
JalagAhur.bindPopup("<b>Jalag Ahur</b><br />Orcs live here!");
var JalagAhur = L.marker([85.02761631140275, -179.55230712890628], {icon: skullIcon}).addTo(map);
JalagAhur.bindPopup("<b>Jalag Ahur</b><br />Orcs hunt here at all times");
var VenbrookOcean = L.marker([85.02309108892199, -179.8001861572266], {icon: defaultIcon}).addTo(map);
VenbrookOcean.bindPopup("<b>Venbrook Ocean</b><br />");
var EelSwamps = L.marker([85.01796548800317, -179.64019775390628], {icon: whiteskullIcon}).addTo(map);
EelSwamps.bindPopup("<b>Eel Swamps</b><br />");
var CrestlanceGarrison = L.marker([85.02460987789058, -179.62371826171875], {icon: fortressIcon}).addTo(map);
CrestlanceGarrison.bindPopup("<b>Crestlance Garrison</b><br />Destroyed by Online Group 2");
var TheOrcenPass = L.marker([85.02237620468962, -179.46235656738284], {icon: skullIcon}).addTo(map);
TheOrcenPass.bindPopup("<b>The Orcen Pass</b><br />");
var FortLawson = L.marker([85.01930699660839, -179.49600219726562], {icon: townIcon}).addTo(map);
FortLawson.bindPopup("<b>Fort Lawson</b><br />");
var BayOfTheEel = L.marker([85.02005212346822, -179.61891174316406], {icon: defaultIcon}).addTo(map);
BayOfTheEel.bindPopup("<b>Bay Of The Eel</b><br />");
var NewtLake = L.marker([85.01617624920391, -179.52475547790527], {icon: defaultIcon}).addTo(map);
NewtLake.bindPopup("<b>Newt Lake</b><br />");
var TheBarrens = L.marker([84.993217303584, -179.4273376464844], {icon: skullIcon}).addTo(map);
TheBarrens.bindPopup("<b>The Barrens</b><br />Dangerous wasteland. Used to be Eastergreen. Very hot.");