You need to get bounds card without taking into account, for example, 15px on each side. (As if padding the card);

The essence of the problem, bound in the form of coordinates lat, lng - will not work out by changing the coordinates in this way: lat-0.004, lng -0.00x, since with different zoom you need to subtract different values.

Now I’m trying to turn the coordinates from lat, lng into pixel coordinates, subtract 15 pixels from them and convert them to lat, lng again. But not yet, maybe there are ideas?

ANSWER:

 var scale = Math.pow(2,myMap.getZoom()); var gbounds = myMap.getBounds(); var proj = myMap.getProjection(); var topRight = proj.fromLatLngToPoint(gbounds.getNorthEast()); var bottomLeft = proj.fromLatLngToPoint(gbounds.getSouthWest()); var bounds = new google.maps.LatLngBounds(); var sw = new google.maps.Point(((topRight.x * scale) - 30)/ scale, ((topRight.y * scale) + 80)/ scale); bounds.extend(proj.fromPointToLatLng(sw)); var ne = new google.maps.Point(((bottomLeft.x * scale) + 20)/ scale, ((bottomLeft.y * scale) - 10)/ scale); bounds.extend(proj.fromPointToLatLng(ne)); var opts = { bounds: bounds, map: myMap, editable:true }; var rect = new google.maps.Rectangle(opts); 

At the output we get the variable bounds with ready pixel indents, draw a rectangle for: visibility, testing, making changes.

  • Please specify the question itself. You can make changes by clicking edit below question text. - aleksandr barakin
  • Added a more detailed description - sivik_xes

0