【发布时间】:2012-06-21 22:29:13
【问题描述】:
我一直在制作带有许多静态图层的传单地图,这些静态图层可以使用传单的标准图层控件关闭和打开。
最近,当用户单击(当前为静态)图例中的图像之一时,我一直在尝试使用 onclick 方法运行在地图中添加和删除图层的函数。我尝试了许多不同的方法来让它工作,我认为它与 javascript 和网页元素的加载顺序有关(但我对此很陌生,所以我可能是错的)。
无论如何,无需粘贴太多代码 - 我正在将所有脚本加载到文档头部:
<html>
<head>
<title>St. Louis River Estuary Deep Map</title>
<link rel="stylesheet" href="css/leaflet.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://code.leafletjs.com/leaflet-0.3.1/leaflet.ie.css" />
<![endif]-->
<script type="text/javascript" src="js/leafletcopy.js"></script>
<script type="text/javascript" src="http://gettopup.com/releases/latest/top_up-min.js"></script>
<script src="http://maps.google.com/maps/api/js?v=3.2&sensor=false"></script>
<script type= "text/javascript" src="js/googlemaps.js"></script>
<script type="text/javascript"src='js/wax.leaf.min.js'></script>
<script type='text/javascript' src='js/htmlswitch.js'></script>
<link rel='stylesheet' href='css/webmapstylesheet1.css'/>
<!--[if lte IE 8]>
<link rel="stylesheet" href="leaflet.ie.css" />
<![endif]-->
<script type="text/javascript" src="js/hearding.js"></script>
<script type="text/javascript" src="js/boundaries.js"></script>
<script type="text/javascript" src="js/bath1.js"></script>
<script type="text/javascript" src="js/bath2.js"></script>
<script type="text/javascript" src="js/bath3.js"></script>
<script type="text/javascript" src="js/monitoring.js"></script>
功能删除娱乐(){
map.removeLayer(recreationLayer);
};
window.onload = 函数(){
//创建全局地图变量
变量映射;
var 娱乐层;
我想我只是不确定要全局定义哪个变量,以使 removeRecreation 函数在我从附加到的图像中单击时调用该函数时有效运行。如以下代码所示:
可以在以下位置找到实时版本:
https://mywebspace.wisc.edu/axler/SLRE_Deep_Map/index2.html
</head>
<body>
<div id ="divHeader">
<h1>St. Louis River Deep Map</h1>
<div class="navHome"><a href="http://stlre.pebbleonline.com/">return home</a></div>
</div>
<div id="legend">
<h2>Legend:</h2>
<hr>
<p class ="legend"><img onclick = "removeRecreation();" src ="images/recreation1.png">Exploring</p>`
【问题讨论】:
标签: javascript leaflet mapping dom-events