これは capdragon からの更新による新しいコードですが、マーカーを作成しません。これを修正する方法がわかりません。コード スニペットは、マーカーを識別するという以前の問題を解決するための非常にスマートな方法であり、おそらく今私が見逃している非常に小さなものだと思います。もう一度助けていただければ幸いです。
<title>Open Street Map</title>
<style type="text/css">
html, body, #demo {
position: absolute;
left: 2%;
width = 25%
}
html, body, #activePlanes {
position: absolute;
left: 2%;
width = 25%
}
html, body, #mapBox {
position: fixed;
top: 0;
right: 0;
width: 75%;
height: 100%;
}
</style>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
var arrMarkers = [];
function AddPlaneMarker(planeID, lonlat)
{
var markers = new OpenLayers.Layer.Markers("Markers");
map.addLayer(markers);
var marker = new OpenLayers.Marker(lonlat);
marker.PlaneID = planeID;
markers.addMarker(marker);
arrMarkers.push(marker);
}
function RemovePlaneMarker(planeID)
{
for(var x in arrMarkers)
{
if(arrMarkers[x].PlaneID == planeID)
{
arrMarkers.splice(x, 1);
markers.removeMarker(arrMarkers[x]);
return;
}
}
}
function GetPlaneMarker(planeID)
{
for(var x in arrMarkers)
{
if(arrMarkers[x].PlaneID == planeID)
{
return arrMarkers[x];
}
}
}
function displayPlane()
{
var x = document.getElementById('planeList');
var newPlane = document.createElement('option');
newPlane.text = document.getElementById("plane_ID").value;
if (newPlane.text == null || newPlane.text == "")
{
alert("Please specify an Aircraft ID");
}
else
{
try
{
x.add(newPlane, x.newPlane[null]); // standards compliant; doesn't work in IE
}
catch(e)
{
x.add(newPlane, null); // IE only
}
var lonLat = new OpenLayers.LonLat(document.getElementById("long").value, document.getElementById("lat").value).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject());
var planeID = document.getElementById("plane_ID");
AddPlaneMarker(planeID,lonLat);
}
}
function init()
{
map = new OpenLayers.Map("mapBox");
map.addLayer(new OpenLayers.Layer.OSM());
focusPoint = new OpenLayers.LonLat(-81.04818, 29.18710)
focusPoint.transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
map.setCenter(focusPoint, 14);
}
function newLonLat()
{
var newValues = prompt("Please specify new location of the Aircraft", "-81.07870 29.17210");
var theValues = newValues.split(" ");
var newPixel = map.getLayerPxFromViewPortPx(map.getPixelFromLonLat(new OpenLayers.LonLat(theValues[0], theValues[1]).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject())));
marker.moveTo(newPixel);
}
function removePlane()
{
var x=document.getElementById("planeList");
x.remove(x.selectedIndex);
var planeID = x.options[x.selectedIndex].text;
RemovePlaneMarker(planeID);
}
</script>
<body onload="init();">
<div id="mapBox"></div>
</body>
<body>
<br /><div id="demo">
Aircraft ID: <input type="text" id="plane_ID" value="AA5024"/><br />
Longitude: <input type="text" id="long" value="-81.04818" /><br />
Latitude: <input type="text" id="lat" value="29.18710" /><br /><br />
<dd> <button value="Add Aircraft" OnClick="displayPlane()">Add Aircraft</button></dd>
<br /><br />
<h3><dd>Active Planes</dd></h3>
<select id="planeList" size="10" multiple="multiple" style="text-align:center" ondblclick="newLonLat()">
<option>----------Plane ID----------</option>
</select><br />
<dd><button value="Remove Aircraft" OnClick="removePlane()">Remove Aircraft</button></dd>
</div>
</body>