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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:42:56+00:00 2026-05-22T00:42:56+00:00

Google Maps JavaScript API V3. My mapping has me dealing with the idea of

  • 0

Google Maps JavaScript API V3.

My mapping has me dealing with the idea of polygons, and I’m trying to develop a strategy before I dive into the code.

I’m never going to have more than one polygon on the map at a time, so I’m hoping I can define one polygon and reuse it as you can with markers.

Is my understanding correct that the polygons setPath(); function will move the polygon to represent a new array of points? The documentation says… “Inserting or removing LatLngs from the MVCArray will automatically update the polygon on the map.” but it doesn’t come right out and say that you can use setPath(); to give it an entirely new array of points.

I’m thinking in psuedocode…

// some event fires
polygon.setPath(latlngArray);
bounds = new google.maps.LatLngBounds();
$.each(latlngArray, function(key, ll){
  bounds.extend(ll);
});
polygon.setMap(MyMap);
MyMap.fitBounds(bounds);

//a different event fires
polygon.setMap(null);
// build a new latlngArray
// do it again

Am I correct in thinking that I can reuse the same polygon object in this fasion, or do I need to rethink my strategy?

Thanks.

Skip

EDIT: The answer is yes it can. I’m going to hash out my code better and try to provide a well written answer, that shows the caveats I’ve come across. Such as, the map must be visible for map.fitBounds(); to give cogent results.

  • 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-22T00:42:56+00:00Added an answer on May 22, 2026 at 12:42 am

    Yes it is quite possible to reuse the same polygon object…

    I really don’t have any code to offer. The psuedocode I listed in the question basically works.

    These are the things I learned or chose in fleshing out my solution…

    As stated earlier, the map can’t be style="display: none;" for map.fitBounds(); to work as expected.

    I already keep a container object that holds my markers. I created a container object for the polygon paths, and add a ‘polygon’ attribute to markers that are associated with a polygon, so multiple markers can reference the same polygon path.

    Even for polygons with a single path, I chose to embed my path array, within another array, then use polygon.setPaths(); This way the code will scale easier if I expand to polygons with multiple paths.

    When initially parsing the polygon path build a LatLngBounds object, and then save its bounds.getSouthWest(); & bounds.getNorthEast(); along with the path. This allows for quick and easy map.fitBounds(); at display time, and keeps from recalculating the same bounds multiple times.

    Anyhow, yes it is certainly possible, and I think quite efficient to reuse the same polygon object with different paths.

    San Francisco & Oakland recycling the same polygon object…
    BayArea.png

    That’s all i got!

    Skip

    UPDATE: I found some polygon data with multiple paths. It plugged right in.

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

Sidebar

Related Questions

I'm trying Google Maps JavaScript API v2. I want to show a message in
I am trying to draw a geodesic polyline with Google Maps JavaScript API from
I'm trying to create map (using the Google Maps JavaScript API V3 ) which
Google has this fine new Google Maps API v3 which is a Javascript API.
I'm trying to use the Google maps JavaScript API to draw a line between
I am using Google maps JavaScript API. Here is code : <!DOCTYPE html PUBLIC
I have 4 days of experience with Google Maps Javascript API and i find
I'd like to have an autocomplete functionality in Eclipse for Google Maps JavaScript API.
I'm using the Google Maps Javascript API so that I can have someone put
I am using Google Maps JavaScript API v3. I want to wire up to

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.