Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design better format for setting & getting map bounds #2112

Open
ansis opened this issue Feb 11, 2016 · 9 comments
Open

Design better format for setting & getting map bounds #2112

ansis opened this issue Feb 11, 2016 · 9 comments
Labels
breaking change ⚠️ Requires a backwards-incompatible change to the API feature 🍏 needs discussion 💬

Comments

@ansis
Copy link
Contributor

ansis commented Feb 11, 2016

LngLatBounds can currently represent an axis-aligned rectangular bounding box. When the map is rotated or tilted this doesn't fit the current view exactly.

Should switch LngLatBounds to storing four locations so that it can represent skewed and rotated bounding boxes?

We could it make it backwards compatible by making the constructor accept only two points.

cc @mourner

@jfirebaugh
Copy link
Contributor

LatLngBounds is used:

My conclusion is that LatLngBounds doesn't even make sense as a geographical primitive for Mapbox GL and should over time be eliminated.

@indus
Copy link
Contributor

indus commented Feb 17, 2016

My usecase for Map#getBounds is to use LatLngBounds as a constrain in a postgis-db query rertieving some GeoJSON.

@lucaswoj lucaswoj changed the title LngLatBounds with four points Design better format for setting map bounds Mar 10, 2016
@lucaswoj
Copy link
Contributor

Lets focus this ticket on

  • For the maxBounds Map option. This was basically inherited from Mapbox.js/Leaflet without much thought as to whether it makes sense for a rotate- and pitch-enabled map. We should come up with a plan for a better constraint system.
  • As the return value for Map#getBounds. Not sure what the use cases for this are, given its behavior with rotated and pitched maps.

I'll ticket out other follow-ups separately

@iplanwebsites
Copy link

Any ways it's possible to have a fit bound across the dateline? For a flight product, we can't visualize any trans-pacific flights properly and it's pretty much a deal-breaker.

@anandthakker
Copy link
Contributor

@iplanwebsites As discussed in #2112, I think the ideal solution to this problem is the fitFeature method proposed in #2245.

@iplanwebsites
Copy link

Thanks @anandthakker! Yes I think that'd be a much needed feature :)

@agiratech-vigneshm
Copy link

I need to get a closed loop (the visible area) from the map, But I am getting only two corners. I think there must be a way to get the other two corners. Is there any method for that or can anyone point me in the right direction? I need to get a closed loop like four sets of lat, lang values for the visible rectangle.

@ansis
Copy link
Contributor Author

ansis commented Apr 18, 2018

@agiratech-vigneshm map.unproject([x, y]) can give you the LngLat of any point on the map. Running this for all corners (map.unproject([width, height]) for bottom right) can get you the bounds as a workaround for this issue

@agiratech-vigneshm
Copy link

agiratech-vigneshm commented Apr 19, 2018

@ansis Thanks for your time, I solved it by using below code.

getMapBoundingBox()
  {
    const lat = this.map.getBounds();
    const multiPolygon = {
      type: 'MultiPolygon',
      coordinates: [[]]
    };
    const bound = [];
    bound.push(lat.getNorthEast().toArray());
    bound.push(lat.getNorthWest().toArray());
    bound.push(lat.getSouthWest().toArray());
    bound.push(lat.getSouthEast().toArray());
    bound.push(lat.getNorthEast().toArray());
    multiPolygon.coordinates[0].push(bound);
    return multiPolygon;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change ⚠️ Requires a backwards-incompatible change to the API feature 🍏 needs discussion 💬
Projects
None yet
Development

No branches or pull requests

8 participants