Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-leaflet-dialog

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-leaflet-dialog

React wrapper of Leaflet.Dialog. A dialog modal window that is resizable and positionable on the map.

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

react-leaflet-dialog

version react-leaflet compatibility travis build dependencies peer dependencies issues downloads MIT License

React wrapper of Leaflet.Dialog for react-leaflet.

A dialog modal window that is resizable and positionable on the map.

Tested with Leaflet 1.4.0 and React-Leaflet 1.9.1, React-Leaflet 2.2.0

Demos

VersionDemo
react-leaflet@1.9.1CodePen
react-leaflet@2.xCodePen

Installation

Install via NPM

npm install react-leaflet-dialog --save

Include font-awesome css to your project.

<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

Usage example for react-leaflet v1

import { Map, TileLayer } from 'react-leaflet';
import Dialog from 'react-leaflet-dialog';
		
<Map center={[101.483459, 2.938926]} zoom={12}>
  <TileLayer
    url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
    attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
  />

  <Dialog ref={(ref) => { this.dialog = ref; }} id="dialog1">
	<div>Dialog content.</div>
  </Dialog>
</Map>

Usage example for react-leaflet v2

import { Map, TileLayer, withLeaflet } from 'react-leaflet';
import DialogDefault from 'react-leaflet-dialog';

// wrap `Dialog` component with `withLeaflet` HOC
const Dialog = withLeaflet(DialogDefault);
		
<Map center={[101.483459, 2.938926]} zoom={12}>
  <TileLayer
    url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
    attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
  />

  <Dialog ref={(ref) => { this.dialog = ref; }} id="dialog1">
	<div>Dialog content.</div>
  </Dialog>
</Map>

Options

Any props passed to Dialog are passed down to Leaflet.Dialog.

Refer Leaflet.Dialog options for a complete list of options supported.

PropertyTypeDefaultDescription
size[Array][width, height][ 300, 300 ]An array of the starting width and height values (in pixels).
minSize[Array][width, height][ 100, 100 ]An array with the minimum resize width and height (in pixels).
maxSize[Array][width, height][ 350, 350 ]An array with the maximum resize width and height (in pixels).
anchor[Array][top, left][ 250, 250 ]The starting point anchor location (from the upper left) in pixels.
position[String]'topleft'The leaflet control div to place the modal inside, as a starting reference point.
initOpen[Boolean]trueWhether or not to initialize in an open state.

Methods

MethodReturnsExampleDescription
open()thisdialog.open();Opens the dialog window.
close()thisdialog.close();Closes the dialog window.
destroy()thisdialog.destroy();Removes the dialog box from the window.
setLocation( [Array][top, left] anchor location )thisdialog.setLocation( [ 15, 15 ] );Move the dialog box to the specified pixel location ( Relative to the 'position' option )
setSize( [Array][width, height] size )thisdialog.setSize( [ 150, 150 ] );Resize the dialog window to the specified width and height.
setContent( [Stringnode] content )thisdialog.setContent("

Hello! Welcome to your nice new dialog box!

");
lock()thisdialog.lock();Hides all visible dialog window controls.
unlock()thisdialog.unlock();Re-instates all dialog window controls.
freeze()thisdialog.freeze();Hides all visible dialog window movement/sizing controls.
unfreeze()thisdialog.unfreeze();Re-instates all dialog window movement/sizing controls.
hideClose()thisdialog.hideClose();Hides the closing 'x'
showClose()thisdialog.showClose();Shows the closing 'x'
hideResize()thisdialog.hideResize();Hides the resizing symbol
showResize()thisdialog.showResize();Shows the resizing symbol

Example


...

openDialog() {
  this.dialog.open();
}

closeDialog() {
  this.dialog.close();
}

destroyDialog() {
  this.dialog.destroy();
}

updateDialogContent() {
  this.dialog.setContent("<div>This is the new dialog content.</div>");
}

render() {
  return (
	<Map center={[101.483459, 2.938926]} zoom={12}>
	  <TileLayer
		url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
		attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
	  />

	  <Dialog ref={(ref) => { this.dialog = ref; }} id="dialog1" />
	</Map>
  );
}

...

Events

EventDataDescription
onOpenedthisFired when open() is called.
onClosedthisFired when close() is called or when the 'x' is clicked.
onDestroyedthisFired when destroy() is called.
onLockedthisFired when lock() is called.
onUnlockedthisFired when unlock() is called.
onFrozenthisFired when freeze() is called.
onUnfrozenthisFired when unfreeze() is called.
onUpdatedthisFired when contents are set or when added to the map.
onResizeStartthisFired when the resize button is clicked.
onResizingthisFired continuously as the resize button is dragged.
onResizeEndthisFired when the resize button click is released.
onMoveStartthisFired when the move button is clicked.
onMovingthisFired continuously as the move button is dragged.
onMoveEndthisFired when the move button click is released.
onCloseHiddenthisFired when hideClose() is called.
onCloseShownthisFired when the showClose() is called.
onResizeHiddenthisFired when hideResize() is called.
onResizeShownthisFired when the showResize() is called.

Credits

Credits goes to NBTSolutions and all the contributors for the original work.

License

MIT License

Keywords

FAQs

Package last updated on 05 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc