1.0.7 • Published 3 years ago

leaflet-notifications v1.0.7

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
3 years ago

Leaflet.Notifications Demo

A leaflet plugin to show notification messages (toasts) inside the map. Image

Installation

npm install leaflet-notifications

Usage

var mymap = L.map('mapid').setView([50, 8], 13);
var notification = L.control
    .notifications({
        timeout: 3000,
        position: 'topright',
        closable: true,
        dismissable: true,
    })
    .addTo(mymap);

//spawn notification popups
notification.alert('Alert', 'some alert message');
notification.info('Info', 'some infomessage');
notification.success('Success', 'some successmessage');
notification.warning('Warning', 'some warning message');
notification.custom('Custom', 'some <span>custom</span> message'); //HTML works for every notification, not only custom()

//custom options per notification
notification.alert('Alert', 'some more important alert message', {
    timeout: 6000,
    closable: false,
    dismissable: false,
    icon: 'fa fa-times-circle',
    className: 'important-alert',
});

/* STYLE CLASS */

/* default (picture 1) */
var notifications = L.control.notifications().addTo(mymap);
/* pastel (picture 2) */
var pastelNotifications = L.control.notifications({ className: 'pastel' }).addTo(mymap);
/* modern (picture 3) */
var modernNotifications = L.control.notifications({ className: 'modern' }).addTo(mymap);

Control options

PropertyTypeDefaultDescription
timeoutNumber3000Time after which the notification will vanish
positionString'topright'Position of the notifications. Possible values are topright, topleft, bottomright, bottomleft
closableBooleantrueShows a close button on all notifications
dismissableBooleantrueIf true a click on a notification will close it
classNameStringnullA custom class name for styling
iconsobjectnullIcon (class) names. Defaults are font-awesome icons
marginLeftString/Numbernullmargin-left, e.g. "5rem", 20, "30px"
marginRightString/Numbernullmargin-right, e.g. "5rem", 20, "30px"

icons options

PropertyTypeDefaultDescription
alertString'fa fa-exclamation-circle'alert icon class name
successString'fa fa-check-circle'success icon class name
warningString'fa fa-exclamation-triangle'warning icon class name
infoString'fa fa-info-circle'info icon class name
customString'fa fa-cog'custom icon class name

Hint: you might need to include the ./node_modules/font-awesome/css/font-awesome.min.css to your project

Notification options

PropertyTypeDefaultDescription
iconStringIcon (class) name for the specific notification. Defaults are font-awesome icons
timeoutNumbernullTime after which the specific notification will vanish
closableBooleantrueShows a close button
dismissableBooleantrueIf true a click on the specific notification will close it
classNameStringnullA custom class name for styling

Methods

MethodReturnsExampleDescription
alert(title, message, options)voidnotification.alert("title", "some message")shows an alert message notification
info(title, message, options)voidnotification.alert("title", "some message")shows an info message notification
success(title, message, options)voidnotification.alert("title", "some message")shows a success message notification
warn(title, message, options)voidnotification.alert("title", "some message")shows a warning message notification
custom(title, message, options)voidnotification.alert("title", "some message")shows a custom message notification
clear()voidnotification.clear()removes all notifications
1.0.7

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago