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 9193155
In Process

The Archive Base Latest Questions

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

Is it possible to create two layers (with one being translucent) in OpenLayers and

  • 0

Is it possible to create two layers (with one being translucent) in OpenLayers and move them independently? If so, how?
I want to let the user choose which layer to move or if that’s not possible, move one layer via my own JavaScript code while the other is controlled by the user.

Both will be prerendered pixmap layers, if that is important.

  • 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-17T21:05:39+00:00Added an answer on June 17, 2026 at 9:05 pm

    This is the solution I came up with. It isn’t pretty but it works for my purposes.

    Better alternatives are very welcome …

    /**
    * @requires OpenLayers/Layer/TMS.js
    */
    MyLayer = OpenLayers.Class(OpenLayers.Layer.TMS, {
        latShift: 0.0,
        latShiftPx: 0,
    
        setMap: function(map) {
            OpenLayers.Layer.TMS.prototype.setMap.apply(this, arguments);
            map.events.register("moveend", this, this.mapMoveEvent)
        },
        // This is the function you will want to modify for your needs
        mapMoveEvent: function(event) {
            var resolution = this.map.getResolution();
            var center = this.map.getCenter();
    
            // This is some calculation I use, replace it whatever you like:
            var h = center.clone().transform(projmerc, proj4326);
            var elliptical = EllipticalMercator.fromLonLat(h.lon, h.lat);
            var myCenter = new OpenLayers.LonLat(elliptical.x, elliptical.y);
    
            this.latShift = myCenter.lat - center.lat;
            this.latShiftPx = Math.round(this.latShift/resolution);
    
            this.div.style.top = this.latShiftPx + "px";
        },
        moveTo: function(bounds, zoomChanged, dragging) {
            bounds = bounds.add(0, this.latShift);
            OpenLayers.Layer.TMS.prototype.moveTo.apply(this, [bounds, zoomChanged, dragging]);
        },
        // mostly copied and pasted from Grid.js ...
        moveGriddedTiles: function() {
            var buffer = this.buffer + 1;
            while(true) {
                var tlTile = this.grid[0][0];
                var tlViewPort = {
                    x: tlTile.position.x +
                        this.map.layerContainerOriginPx.x,
                    y: tlTile.position.y +
                        this.map.layerContainerOriginPx.y + this.latShiftPx // ... except this line
                };
                var ratio = this.getServerResolution() / this.map.getResolution();
                var tileSize = {
                    w: Math.round(this.tileSize.w * ratio),
                    h: Math.round(this.tileSize.h * ratio)
                };
                if (tlViewPort.x > -tileSize.w * (buffer - 1)) {
                    this.shiftColumn(true, tileSize);
                } else if (tlViewPort.x < -tileSize.w * buffer) {
                    this.shiftColumn(false, tileSize);
                } else if (tlViewPort.y > -tileSize.h * (buffer - 1)) {
                    this.shiftRow(true, tileSize);
                } else if (tlViewPort.y < -tileSize.h * buffer) {
                    this.shiftRow(false, tileSize);
                } else {
                    break;
                }
            }
        },
        CLASS_NAME: "MyLayer"
    });
    

    Note that this only works with OpenLayers 2.13 or newer

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

Sidebar

Related Questions

Is it possible to create two different plugins in the same dll, one for
is there any possible way to create two storyboards, one portrait and one landscape,
I want to create two users on my MySQL test database, One with read-only
I want to create two divs beside each other, however I want the one
I want to use Maven to create two separate jars for my project. One
I want to create two NetworkStreams objects and i want that one should only
I would like to know if its possible to create two triggers, one on
Possible Duplicate: Button half width of screen I want to create two buttons inside
I wonder if it's possible to create two consecutive lists in markdown without them
Is it possible to create two icons (that link to different functionality) for a

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.