Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8097403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:45:05+00:00 2026-06-05T21:45:05+00:00

This is the new code with the update from capdragon, but now it would

  • 0

This is the new code with the update from capdragon, but now it would not create markers. I don’t know how to fix this now.
I think the code snippet was a really smart way to fix my previous problem of identifying the markers, and it is probably a really small things i am missing now. Any help again would be greatly appreciated.

<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: &nbsp;<input type="text" id="long" value="-81.04818" /><br />
        Latitude: &nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="lat" value="29.18710" /><br /><br />
        <dd>&nbsp;&nbsp;&nbsp;&nbsp;<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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T21:45:06+00:00Added an answer on June 5, 2026 at 9:45 pm

    markers and marker don’t look like they are available in the scope of removePlane().

    Try declaring them in the global scope and removing the var when you instantiate them.:

    <script type="text/javascript">
    ...
    var markers, marker;
    ...
            function displayPlane()
                 ...
                 markers = new OpenLayers.Layer.Markers(name);
                 ...
                 marker = new OpenLayers.Marker(lonLat);
    ...
    

    Update per comment:

    I actually like my last option best

    I would keep track of them in an array of my own Plane objects that contain a reference to the Markers. Something like this:

    ​var arrPlaneObjects = []​;
    
    function AddPlaneMarker(planeID, lonlat){
    
        var objPlane = {};
        objPlane.ID = planeID;
        objPlane.Marker = new OpenLayers.Marker(lonLat);
        //Add to layer.
        markers.addMarker(objPlane.Marker);
        //Add to array.
        arrPlaneObjects.push(objPlane);
    }
    
    function RemovePlaneMarker(planeID){
        for(var x in arrPlaneObjects){
            if(arrPlaneObjects[x].ID == planeID){
                //Remove from array.
                arrPlaneObjects.splice(x, 1);
                //Remove from layer.
                markers.removeMarker(arrPlaneObjects[x].Marker); 
                return;
            }       
        }
    }
    

    Then you could use this to easily add and remove markers:

    AddPlaneMarker("AA5024", lonLat);
    
    RemovePlaneMarker("AA2222");
    

    Another option would be to just keep of track of the markers in an array and store the plane id within that marker like such:

    ​var arrMarkers = []​;
    
    function AddPlaneMarker(planeID, lonlat){
    
        var marker = new OpenLayers.Marker(lonLat);
        marker.PlaneID = planeID;
        //Add to layer.
        markers.addMarker(marker);
        //Add to array.
        arrMarkers.push(marker);
    }
    
    function RemovePlaneMarker(planeID){
        for(var x in arrMarkers){
            if(arrMarkers[x].PlaneID == planeID){
    
                //Remove from layer.
                markers.removeMarker(arrMarkers[x]); 
                //Remove from array.
                arrMarkers.splice(x, 1);
                return;
            }       
        }
    }
    

    To call them later on:

    function GetPlaneMarker(planeID){
        for(var x in arrMarkers){
            if(arrMarkers[x].PlaneID == planeID){
                return arrMarkers[x];
            }       
        }
    }
    
    var myPlaneMarker = GetPlaneMarker("AA2222");
    

    Solution Update

    <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 = [];
                var markers;
    
                function AddPlaneMarker(planeID, lonlat) {
    
                    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) {
    
                            markers.removeMarker(arrMarkers[x]);
                            arrMarkers.splice(x, 1);
    
                            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").value;
                        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);
    
                    markers = new OpenLayers.Layer.Markers("Markers");
                    map.addLayer(markers);
                }
    
                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");
                    var id = x.options[x.selectedIndex].value;
                    x.remove(x.selectedIndex);
                    RemovePlaneMarker(id);
                }
            </script>
    
            <body onload="init();">
            <div id="mapBox"></div>
    
            <br /><div id="demo">
            Aircraft ID: <input type="text" id="plane_ID" value="AA5024"/><br />
            Longitude: &nbsp;<input type="text" id="long" value="-81.04818" /><br />
            Latitude: &nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="lat" value="29.18710" /><br /><br />
            <dd>&nbsp;&nbsp;&nbsp;&nbsp;<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>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to update/change contact ringtone using this code: ContentValues values = new ContentValues();
It's nothing new to de-couple the data access code from your business objects, but
I have this code UPDATE OPENQUERY (db,'SELECT * FROM table WHERE ref = ''+
This is my Python code - cursor.execute(UPDATE tasks SET task_owner=%s,task_remaining_hours=%s, task_impediments=%s,task_notes=%s WHERE task_id=%s, (new_task_owner,new_task_remaining_hours,new_task_impediments,
Consider this code: new Ajax.Request('?service=example', { parameters : {tags : 'exceptions'}, onSuccess : this.dataReceived.bind(this)
I have a lot of C# VS2008 code that looks like this: new SqlParameter(@Description,
Hi I have below pseudo code with throws an exception like this throw new
Actually my code is: LinearLayout ll = new LinearLayout(this); ll.setId(i); ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); ll.setPadding(0, 0,
I'm guessing this must be new functionality as this code fail on my iOS4
Hi i have a code like this: $doc = new DOMDocument(); $doc->Load('courses.xml'); foreach ($doc->getElementsByTagName('courses')

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.