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.
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="https://github.com/atmist/snazzy-info-window/blob/master/snazzy-info-window.min.css">
<script src="https://maps.googleapis.com/maps/api/js?key={{YOUR KEY HERE}}"></script>
<script src="https://github.com/atmist/snazzy-info-window/raw/master/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.
content
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.
latLng
Set the wrapperClass
of the info window. This can be called at any time.
wrapperClass
Will return the DOM Element for the wrapper container of the info window.
The Google Maps marker associated to this info window.
The text or DOM Element to insert into the info window body.
Choose where you want the info window to be displayed, relative to the marker.
'top'
'top'
, 'bottom'
, 'left'
, 'right'
The Google Map associated to this info window. Only required if you are not using a marker
.
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
.
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.
The max width in pixels of the info window.
200
The max height in pixels of the info window.
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.
Example:
offset: {
top: '10px',
left: '20px'
}
The offset from the map edge in pixels which is used when panning an info window into view.
Example:
edgeOffset: {
top: 20,
right: 20,
bottom: 20,
left: 20
}
The color to use for the background of the info window.
'#FF0000'
, 'blue'
A custom padding size around the content of the info window.
'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
.
Example:
border: {
width: '10px',
color: '#FF0000'
}
A custom CSS border radius property to specify the rounded corners of the info window.
'2px 20px'
The font color to use for the content inside the body of the info window.
'#FF0000'
, 'blue'
The font size to use for the content inside the body of the info window.
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
.
'10px'
The CSS properties for the shadow of the info window. Set to false
to
completely remove the shadow.
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.
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.
true
Determines if the info window will close when any other Snazzy Info Window is opened.
false
Determines if the info window will show a close button.
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.
Determines if the info window will be panned into view when opened.
true
All callbacks are optional and can access the info window instance via this
.
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.
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.
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.
Example:
function() {
console.log('Info window has opened.');
}
Called before the info window attempts to close. Return false
to cancel the close.
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.
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.
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.
placement
Used to css translate the info window into the placement
. The wrapperClass
is added to this element's class list.
placement
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
.
placement
Used to show the pointer shadow in the placement
. This element will not be included if
shadow
or pointer
is false
.
placement
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.
placement
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
.
placement
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.