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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:18:58+00:00 2026-05-31T00:18:58+00:00

I have a website using the Google-maps Javascript API V3. I would like to

  • 0

I have a website using the Google-maps Javascript API V3.
I would like to highlight the region of interest by placing a semi-transparent color on top of the map with a hole cut in the middle. See image attached.

The position of the cut-out could be anywhere. I am able to calculate the pixel (or lat/lng) coordinates of the cut-out, but what I’m struggling with is how best to create a mask. I’ve had a look at Google’s image tile overlays and polygons but couldn’t see a simple way to achieve this. Can anybody offer any pointers on the best way to proceed?

mask with cut-out

  • 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-05-31T00:18:59+00:00Added an answer on May 31, 2026 at 12:18 am

    Figured it out. Incase anyone else needs to do this …

    function MaskClass( map ){
    
        //constants
        var MAP_MAX_LAT = 85;
        var MAP_MIN_LAT = -85;
        var MAP_MAX_LNG = 179;
        var MAP_MIN_LNG = -179;
    
        // Object initialisation - create 4 rectangles to mask off the area
        var rectangleInitialisationOptions = {
            map: map,
            fillColor: "#F00",
            fillOpacity: 0.3,
            strokeOpacity: 0,
            clickable: false
            };
    
        this.rectangle1 = new google.maps.Rectangle(rectangleInitialisationOptions);
        this.rectangle2 = new google.maps.Rectangle(rectangleInitialisationOptions);
        this.rectangle3 = new google.maps.Rectangle(rectangleInitialisationOptions);
        this.rectangle4 = new google.maps.Rectangle(rectangleInitialisationOptions);
    
        // Method to place the cut-out   
        this.setMask = function(boundsSouthWest, boundsNorthEast){
    
            var swLat = boundsSouthWest.lat();
            var swLng = boundsSouthWest.lng();
            var neLat = boundsNorthEast.lat();
            var neLng = boundsNorthEast.lng();
    
            this.rectangle1.setBounds(
                new google.maps.LatLngBounds(
                    new google.maps.LatLng(neLat, MAP_MIN_LNG),
                    new google.maps.LatLng(MAP_MAX_LAT, MAP_MAX_LNG)));
    
            this.rectangle2.setBounds(
                new google.maps.LatLngBounds(
                    new google.maps.LatLng(MAP_MIN_LAT, MAP_MIN_LNG),
                    new google.maps.LatLng(swLat, MAP_MAX_LNG)));
    
            this.rectangle3.setBounds(
                new google.maps.LatLngBounds(
                    new google.maps.LatLng(swLat, MAP_MIN_LNG),
                    new google.maps.LatLng(neLat, swLng)));
    
            this.rectangle4.setBounds(
                new google.maps.LatLngBounds(
                    new google.maps.LatLng(swLat, neLng),
                    new google.maps.LatLng(neLat, MAP_MAX_LNG)));
    
            this.setVisible(true);
        };
    
        // Method to show/hide the mask
        this.setVisible = function(visibility){
            this.rectangle1.setVisible(visibility);
            this.rectangle2.setVisible(visibility);
            this.rectangle3.setVisible(visibility);
            this.rectangle4.setVisible(visibility);
        };
    
    }
    

    To use it…

    theMask = new MaskClass( referenceToYourMap );   //create mask
    
    theMask.setMask(boundsSouthWest, boundsNorthEast);    //place mask somewhere
    
    theMask.setVisible(false);    //hide mask
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using google maps api to have a map show up on my website
I am using the Google Maps api on my website and I have been
I would like to publish a website using msbuild. Since I have a website
I'm using the Google Maps API (v3) on my website to show a map
I have a drupal website using taxonomy. Now google indexed the taxonomy paths like:
i'm using google event tracking on our website, and would like to send the
I am using a google map with the full maps api on my website.
When I check the website, I see that web application using Google maps API
We have an existing website which currently uses v2 of the google maps api
I am using Google Maps API v3 on a website I am developing. I

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.