Snazzy Info Window is a plugin for customizable info windows using the Google Maps JavaScript API. Open sourced by the people that created Snazzy Maps.
- Responsive sizing
- The info window will size properly for a variety of screen and map sizes.
- Custom styling
- Customize the border radius, shadow, background color, border, and much more.
- Supports SCSS styling.
- Dynamic content
- Supports dynamic content after initialization with proper resizing.
- Multiple placements
- Place the info window to the top, bottom, right, or left of the marker.
- Simple
- Multiple markers
- Dynamic content
- Set position
- Styling with SCSS
- Styling with JavaScript
- Complex styling
You can install Snazzy Info Window from the following package managers:
yarn add snazzy-info-window
npm install --save snazzy-info-window
bower install --save snazzy-info-window
- Include all the required files.
<link rel="stylesheet" href="snazzy-info-window.min.css">
<script src="https://maps.googleapis.com/maps/api/js?key={{YOUR KEY HERE}}"></script>
<script src="snazzy-info-window.min.js"></script>
- Create a new
SnazzyInfoWindow
object with a marker.
var infoWindow = new SnazzyInfoWindow({
marker: marker,
content: 'Snazzy!'
});
Will attempt to open the info window.
Will attempt to close the info window.
Determines if the info window is open.
Will destroy the info window. If the info window is open it will be forced
closed bypassing the regular beforeClose
callback. All Google Map event
listeners associated to this info window will be removed.
Set the content in the info window. This can be called at any time.
- Parameter:
content
- string or DOM Element
Set the position
of the info window. A valid Google Map instance must be associated to the info window. This could be either through the marker
or map
option.
- Parameter:
latLng
Set the wrapperClass
of the info window. This can be called at any time.
- Parameter:
wrapperClass
- string
Will return the DOM Element for the wrapper container of the info window.
The Google Maps marker associated to this info window.
- Type: Marker
The text or DOM Element to insert into the info window body.
- Type: string or DOM Element
Choose where you want the info window to be displayed, relative to the marker.
- Type: string
- Default:
'top'
- Possible Values:
'top'
,'bottom'
,'left'
,'right'
The Google Map associated to this info window. Only required if you are not using a marker
.
- Type: Map
The latitude and longitude where the info window is anchored. The offset
will default to 0px
when using this option. Only required if you are not using a marker
.
- Type: LatLng or LatLngLiteral
An optional CSS class to assign to the wrapper container of the info window. Can be used for applying custom CSS to the info window.
- Type: string
The max width in pixels of the info window.
- Type: numeric
- Example:
200
The max height in pixels of the info window.
- Type: numeric
- Example:
200
The offset from the marker. This value should be different for each placement
.
By default the offset is configured for the default Google Maps marker.
-
Type: object
-
Example:
offset: { top: '10px', left: '20px' }
The offset from the map edge in pixels which is used when panning an info window into view.
-
Type: object
-
Example:
edgeOffset: { top: 20, right: 20, bottom: 20, left: 20 }
The color to use for the background of the info window.
- Type: string
- Possible Values: Any valid CSS color value.
- Examples:
'#FF0000'
,'blue'
A custom padding size around the content of the info window.
- Type: string
- Possible Values: Any valid CSS size value.
- Examples:
'10px'
,'2em'
,'5%'
A custom border around the info window. Set to false
to completely remove
the border. The units used for border
should be the same as pointer
.
-
Type: object or boolean
-
Example:
border: { width: '10px', color: '#FF0000' }
A custom CSS border radius property to specify the rounded corners of the info window.
- Type: string
- Example:
'2px 20px'
The font color to use for the content inside the body of the info window.
- Type: string
- Possible Values: Any valid CSS color value.
- Examples:
'#FF0000'
,'blue'
The font size to use for the content inside the body of the info window.
- Type: string
- Possible Values: Any valid CSS font size value.
The height of the pointer from the info window to the marker. Set to false
to completely remove the pointer. The units used for pointer
should be the
same as border
.
- Type: string or boolean
- Possible Values: Any valid CSS size value.
- Example:
'10px'
The CSS properties for the shadow of the info window. Set to false
to
completely remove the shadow.
-
Type: object or boolean
-
Default:
shadow: { h: '0px', v: '3px', blur: '6px', spread: '0px', opacity: 0.5, color: '#000' }
Determines if the info window will open when the marker is clicked. An internal
listener is added to the Google Maps click
event which calls the open()
method.
- Type: boolean
- Default:
true
Determines if the info window will close when the map is clicked. An internal
listener is added to the Google Maps click
event which calls the close()
method. This will not activate on the Google Maps drag
event when the user is
panning the map.
- Type: boolean
- Default:
true
Determines if the info window will close when any other Snazzy Info Window is opened.
- Type: boolean
- Default:
false
Determines if the info window will show a close button.
- Type: boolean
- Default:
true
The text or DOM Element to replace the default close button. No click handler or positioning is added to your markup if you use this option.
- Type: string or DOM Element
Determines if the info window will be panned into view when opened.
- Type: boolean
- Default:
true
All callbacks are optional and can access the info window instance via this
.
-
Type: object
-
Example:
callbacks: { beforeOpen: function(){}, open: function(){}, afterOpen: function(){}, beforeClose: function(){}, close: function(){}, afterClose: function(){} }
Called before the info window attempts to open. Return false
to cancel the open.
-
Type: function
-
Example:
function() { console.log('Cancel opening the info window.'); return false; }
Called when the info window is opening. This occurs at the end of the
OverlayView onAdd()
implementation. At this point the info window is added
to the DOM but is not drawn yet.
-
Type: function
-
Example:
function() { console.log('Info window has started opening.'); }
Called when the info window has opened. This occurs at the end of the
OverlayView draw()
implementation. At this point the info window is added
to the DOM and should be visible.
-
Type: function
-
Example:
function() { console.log('Info window has opened.'); }
Called before the info window attempts to close. Return false
to cancel the close.
-
Type: function
-
Example:
function() { console.log('Cancel closing the info window.'); return false; }
Called when the info window is closing. This occurs at the beginning of the
OverlayView onRemove()
implementation. At this point the info window is still
in the DOM.
-
Type: function
-
Example:
function() { console.log('Info window has started closing.'); }
Called after the info window has closed. This occurs at the end of the
OverlayView onRemove()
implementation. At this point the info window should
be removed from the DOM.
-
Type: function
-
Example:
function() { console.log('Info window has closed.'); }
<div class="si-float-wrapper">
<div class="si-wrapper-top">
<div class="si-shadow-wrapper-top">
<div class="si-shadow-frame"></div>
<div class="si-shadow-pointer-top">
<div class="si-shadow-inner-pointer-top"></div>
</div>
</div>
<div class="si-content-wrapper">
<button class="si-close-button"></div>
<div class="si-content">
<!-- Your content goes here -->
</div>
</div>
<div class="si-pointer-border-top"></div>
<div class="si-pointer-bg-top"></div>
</div>
</div>
Used to absolute position the info window in the Google Maps floatPane.
Used to css translate the info window into the placement
. The wrapperClass
is added to this element's class list.
Used to blend opacity for all shadow elements. This div will not be included if
shadow
is false
.
Used to create the box shadow for the content wrapper. This element will not be
included if shadow
is false
.
Used to show the pointer shadow in the placement
. This element will not be included if
shadow
or pointer
is false
.
Used to create the shadow for the pointer. This element will not be included if
shadow
or pointer
is false
.
Used for adding padding and border around the content.
Used for showing the default close button in the top right hand corner. This
element will not be included if showCloseButton
is false
.
Used for wrapping your content and showing a scroll bar when there is overflow.
Used for rendering the tip of the pointer when there is a border present.
This element will not be included if pointer
or border
is false
.
Used for rendering the inner tip of the pointer when there is a border present.
This element will not be included if pointer
is false
.
If you find a bug with the library, please open an issue. If you would like fix an issue or contribute a feature, follow the steps outlined here.