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

  • Home
  • SEARCH
  • 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 8670093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:38:00+00:00 2026-06-12T18:38:00+00:00

I am using OpenLayers to display dynamically loaded images. The code I am using

  • 0

I am using OpenLayers to display dynamically loaded images. The code I am using is:

      var map;
      function init(strURL) {
      map = new OpenLayers.Map('map');

      var options = { numZoomLevels: 3,
                isBaseLayer: true, };

      var graphic = new OpenLayers.Layer.Image(
            'City Lights',
            strURL + "?sc=page",
            new OpenLayers.Bounds(-180, -88.759, 180, 88.759),
            new OpenLayers.Size(580, 288),
            options
        );

    //    graphic.events.on({
    //      loadstart: function () {
    //        OpenLayers.Console.log("loadstart");
    //      },
    //      loadend: function () {
    //        OpenLayers.Console.log("loadend");
    //      }
    //    });

    var jpl_wms = new OpenLayers.Layer.WMS("NASA Global Mosaic",
            "http://t1.hypercube.telascience.org/cgi-bin/landsat7",
            { layers: "landsat7" }, options);

    map.addLayers([graphic, jpl_wms]);


    map.addControl(new OpenLayers.Control.LayerSwitcher());
    map.zoomToMaxExtent();

  }

I am calling this function on a button click event and passing the strURL (sources of the images) at that time. The result is, with each click a different image is loaded and displayed on the web page but is not clearing the previous image. So I 5 different images on the webpage are shown with 5 clicks and so on.

My javascript knowledge is limited, so my apologies if this is a stupid question. How to stop this behavior? Thanks for any assistance.

Also, I didn’t quite understand the lines:

    var jpl_wms = new OpenLayers.Layer.WMS("NASA Global Mosaic",
        "http://t1.hypercube.telascience.org/cgi-bin/landsat7",
        { layers: "landsat7" }, options);

But I know these lines are needed since I’m getting js error if I remove them.

  • 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-12T18:38:01+00:00Added an answer on June 12, 2026 at 6:38 pm

    So currently you are calling init(strURL) with each button click? Divide that code into two parts:

    • On page load, create map and layer objects
    • On button click, just update URL of existing image layer. Image layer has setUrl(url) method for that: http://dev.openlayers.org/apidocs/files/OpenLayers/Layer/Image-js.html#OpenLayers.Layer.Image.setUrl

    Here is sample, that should explain it: http://jsfiddle.net/mEHrN/6/

    About var jpl_wms = … – it creates WMS layer, that should display Landsat imagery (but that URL doesn’t seem to work). If you remove it, remember also to remove it from map.addLayers:

    map.addLayers([graphic]); 
    

    Probably this was reason, why you got JS error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this code to draw a point on a map: function addPointToMap(pMap){ var
I am using an image to display my map with OpenLayers. My JS code
i'm using openlayers and geoExt. what i have is this: var options = {
I need to display markers with information on a slippy map using OpenLayers. An
I'm using OpenLayers to display a map in a web page. I am using
I'm using OpenLayers to display a map of the same projection as Google Maps,
I'm using OpenLayers to display a map on a standard HTML page, and I
I'm using OpenLayers to display OpenStreetMap maps. (Though, I'd assume this should be general
I'm using OpenLayers map in my project,I'm displaying list of items on map.Whenever user
I am using OpenLayers to create a map and plot locations. Each location has

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.