Google maps infowindow autopan: is it possible to customize the distance to the map's top? - google-maps

I have a map with a semi-transparent search bar on top of it. I have also got a bunch of markers with infowindow attached to them.
The problem is that google maps autopan feature obviously doesn't take my search bar into account, therefore if my marker is too close to the top, a part of the infowindow gets covered by the bar.
Is it possible to somehow specify the minimum distance the infowindow needs to be from the map's top?
I was also thinking of limiting the bounds of the map using markers' positions but in my case the markers can also end up under the search bar, so it is not an option.
Any ideas? Thank you for your time!

There exists a library called Snazzy Info Window that can be used instead of the usual InfoWindow. Then you can pass an option edgeOffset in pixels to this object and voila, problem solved. Hope this helps someone in the future!

Related

leaflet location-filter example and draggable-resizeable rectangular area-select on a map

I need to select an rectangular area on a map and identify markers that fall within that area.
Ideally, rectangle should be draggable and resizeable.
I am not too particular about the mapping and Google or Mapbox or Leaflet would all work just fine.
I found location-filter for Leaflet (https://github.com/kajic/leaflet-locationfilter/), which does seem to do the job. However, I couldn't find simple example code that shows how to use it. It has been used on tripcode.com but it is hard to make anything out of what is going on.
Does anyone have any experience with location-filter? If so, can you please point me to simple example of how to use it?
Are there similar examples for other mapping services particularly google maps?
Thanks.
For my bbox page I've snatched two files: SimpleShape, Rectangle from Leaflet.draw plugin and fixed them for better usability. The code for the rectangle is simple:
var rect = L.rectangle([[59.9, 29.9], [60.1, 30.1]]);
map.addLayer(rect);
rect.editing.enable();
rect.on('edit', function() { console.log(rect.getBounds().getBBoxString()); });
For advanced things like centering the rectangle on screen, see source code for the page.
When you are drawing the markers onto the map you will need to add them to some kind of an array which will contain the lat/lng pair of each marker.
You can use Leaflet.draw to draw the rectangle and modify it to return top left and bottom right coordinates on mouse up. On mouse up you can go over the entire list and which elements fit inside that bounding box.
This solution is just an example, there are many ways you can do this.

Adding padding to Google Maps fitBounds and other positioning methods

I have a google map as page background and a few div layers above it. When I place markers on the map I would like to be placed in the visible part of the map, not below the divs. In other words.. I need to add padding to the map so the functions like fitBounds(), setCenter() and etc. to position the markers in the visible part of the map.
There are many examples around but none of them looks quite well or it is working at all. Most of them are similar to:
I have tried to calculate the bounds and to extend bounds with some padding but it is a two step process. At first.. the map is positioned at original bounds to get the correct projection and then it is animated to the extended bounds. It doesnt look professional, we have two fitBounds() and the second one is animated. http://jsfiddle.net/seddass/CuKTK/
I have tried to add custom control to my map but it seems that the custom controls doesnt add padding to the map as suggested on many places. http://jsfiddle.net/seddass/wtT3t/1/
Can anyone can provide a working example or a better solution for padding to for Google Map v3? Thanks in advance!

Google Maps - Infobox API - scroll pane vs change position

Using Google Maps InfoBox -
http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html
Currently the map will scroll - pan control - when your infobox is outside of the bounds of the map.
I'm looking for a way to detect if the infobox will be outside of the bounds of the map, and if so the position is switched (currently I have the infoBoxAnchor set at 9,2) - so set the infoboxanchor in the opposite x direction.
Anyone done anything like this?
Thanks.
Could be tricky - infowindows are dynamically sized based on the content in them. What you could do, is in the InfoWindowOptions, set disableAutoPan=true. This will prevent the map panning to display the infowindow. Then I'm guessing you could use jQuery (or any other JS you like) to figure out:
the size of the infowindow based on the position where it's anchored to on the map,
is the entire infowindow visible
if not, move the infowindow's position
Related:
Auto adjustment of InfoWindow position on Google Maps
Google Maps Mashup with Intelligently positioning InfoBox
Google Maps: How to prevent InfoWindow from shifting the map
And a possible solution (thanks to above links) at http://gmaps-samples-v3.googlecode.com/svn/trunk/smartinfowindow/smartinfowindow.html

How can I have a smooth animated move between 2 Google Maps locations?

When clicking from one marker to another in Google Maps, the map screen animates the move smoothly if both markers are within them initial map view but jumps if one of the markers is off screen.
I'm trying to set up a map which has several locations within the main map area but has one which is 'off screen'. I have a signpost icon to the more distant location within the initial map area which I want to smoothly scroll to the off screen location when clicked (so as to give a better sense of it's relative location). I can't find anything in the Maps API which would let me do this however.
I could zoom out, move and then zoom in again but this looks a bit jarring. Am I missing something in the API, or does anyone have any suggestions?
Unfortunately, I don't think this is possible (without a change from Google). From the v3 API reference for panTo:
Changes the center of the map to the given LatLng. If the change is less than both the width and height of the map, the transition will be smoothly animated.
which implies that if that change is not less than the dimensions of the map, the transition won't be smoothly animated. The other pan methods are similar.
You could try moving in multiple steps but that's a bit of a hack and I suspect the result will be poor.
Sorry that's not very helpful (I have the same problem).
For me this method works, but i'm using Google Maps API v2.
LatLng latLng = new LatLng(lat,lng);
map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, ZOOM_FACTOR));
This animates the camera from current position to the new one.
If you are using Gmaps API V2, then you can implement smooth animated move very easily by using panBy() method. You have to use fromLatLngToContainerPixel() method to find the amount of pixels to pan by.
Here is the bit of code:
var newLoc = map.fromLatLngToContainerPixel(new GLatLng(lat, lng));
map.panBy(new GSize( newLoc.x, newLoc.y ));
However, what I am trying to do is to achieve the same thing in maps API V3, but sadly fromLatLngToContainerPixel() method does not work anymore the way it did :(

Controlling GDirections mini-popup-maps

I am using the Google Maps API to code a campus map for my university. On the main map, when it is being viewed in the "Map" maptype, there is a custom overlay of the campus, which is set (by using GEvent.addDomListener) to be removed when the map is viewed in Satellite or Hybrid mode. When the user gets directions, through my map, to and from the campus, a polyline and 2 markers show up, like normal. When the marker is clicked, a small popup map is display, focused on the area of campus around that particular marker.
I was wondering if anyone knew of a way to set attributes of these mini-popup-maps. I need to extend the event listener to make sure that the overlay gets taken off when the mini map is clicked out of "Map" mode. I also need to be able to set the zoom level for these maps.
Any ideas?
(code can be provided as needed, wasn't really sure what parts would be needed and didn't want to post the whole f'n thing up here.)
Doesn't look like there are any built in options to modify the infoWindow you get from the GDirection markers, but you can explicitly replace the markers once you get them back.
This post describes the process.