-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/DivMarker' into supercluster
# Conflicts: # CHANGELOG.md # package.json # src/lib/index.js
- Loading branch information
Showing
5 changed files
with
218 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { DivIcon, marker } from 'leaflet'; | ||
import { MapLayer, withLeaflet, LeafletProvider } from 'react-leaflet'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export class LeafletDivMarker extends MapLayer { | ||
// static propTypes = { | ||
// opacity: PropTypes.number, | ||
// zIndexOffset: PropTypes.number, | ||
// } | ||
|
||
constructor(props){ | ||
super(props) | ||
super.componentDidMount(); | ||
} | ||
|
||
// See https://github.com/PaulLeCam/react-leaflet/issues/275 | ||
createLeafletElement(newProps) { | ||
const { map: _map, layerContainer: _lc, position, ...props } = newProps; | ||
this.icon = new DivIcon(newProps.iconOptions); | ||
const m = marker(position, { icon: this.icon, ...props }); | ||
this.contextValue = { ...props.leaflet, popupContainer: m } | ||
return m | ||
} | ||
|
||
updateLeafletElement(fromProps, toProps) { | ||
if (toProps.position !== fromProps.position) { | ||
this.leafletElement.setLatLng(toProps.position); | ||
} | ||
if (toProps.zIndexOffset !== fromProps.zIndexOffset) { | ||
this.leafletElement.setZIndexOffset(toProps.zIndexOffset); | ||
} | ||
if (toProps.opacity !== fromProps.opacity) { | ||
this.leafletElement.setOpacity(toProps.opacity); | ||
} | ||
if (toProps.draggable !== fromProps.draggable) { | ||
if (toProps.draggable) { | ||
this.leafletElement.dragging.enable(); | ||
} | ||
else { | ||
this.leafletElement.dragging.disable(); | ||
} | ||
} | ||
} | ||
|
||
componentDidUpdate(fromProps) { | ||
this.updateLeafletElement(fromProps, this.props); | ||
} | ||
|
||
render() { | ||
const container = this.leafletElement._icon; | ||
if (container) { | ||
return ReactDOM.createPortal(<LeafletProvider value={this.contextValue}> | ||
{this.props.children} | ||
</LeafletProvider>, container) | ||
} | ||
else { | ||
return null | ||
} | ||
} | ||
} | ||
|
||
export default withLeaflet(LeafletDivMarker) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import React, {Component} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import LeafletDivMarker from '../LeafletDivMarker'; | ||
|
||
/** | ||
* Marker is a wrapper of Marker in react-leaflet. | ||
* It takes similar properties to its react-leaflet counterpart. | ||
*/ | ||
export default class DivMarker extends Component { | ||
render() { | ||
const nProps = Object.assign({}, this.props); | ||
// Bind events. | ||
nProps.onclick = (e) => { | ||
nProps.setProps({ n_clicks: nProps.n_clicks + 1 }); | ||
} | ||
// Render the leaflet component. | ||
return <LeafletDivMarker {...nProps}/> | ||
} | ||
} | ||
|
||
DivMarker.defaultProps = { | ||
n_clicks: 0 | ||
} | ||
|
||
DivMarker.propTypes = { | ||
/** | ||
* A geographical point (lat, lon) | ||
*/ | ||
position: PropTypes.arrayOf(PropTypes.number).isRequired, | ||
|
||
/** | ||
* Options passed to DivIcon constructor. | ||
*/ | ||
iconOptions: PropTypes.shape({ | ||
iconSize: PropTypes.arrayOf(PropTypes.number), | ||
iconAnchor: PropTypes.arrayOf(PropTypes.number), | ||
popupAnchor: PropTypes.arrayOf(PropTypes.number), | ||
className: PropTypes.arrayOf(PropTypes.number), | ||
html: PropTypes.string | ||
}), | ||
|
||
/** | ||
* Whether the marker is draggable with mouse/touch or not. | ||
*/ | ||
draggable: PropTypes.bool, | ||
|
||
/** | ||
* The opacity of the marker. | ||
*/ | ||
opacity: PropTypes.number, | ||
|
||
/** | ||
* By default, marker images zIndex is set automatically based | ||
* on its latitude. Use this option if you want to put the | ||
* marker on top of all others (or below), specifying a high | ||
* value like 1000 (or high negative value, respectively). | ||
*/ | ||
zIndexOffset: PropTypes.number, | ||
|
||
// Static parameters | ||
|
||
/** | ||
* Whether the marker can be tabbed to with a keyboard and clicked by | ||
* pressing enter. | ||
*/ | ||
keyboard: PropTypes.bool, | ||
|
||
/** | ||
* Text for the browser tooltip that appear on marker hover (no tooltip | ||
* by default). | ||
*/ | ||
title: PropTypes.string, | ||
|
||
/** | ||
* Text for the alt attribute of the icon image (useful for accessibility). | ||
*/ | ||
alt: PropTypes.string, | ||
|
||
/** | ||
* If true, the marker will get on top of others when you hover the mouse | ||
* over it. | ||
*/ | ||
riseOnHover: PropTypes.bool, | ||
|
||
/** | ||
* The z-index offset used for the riseOnHover feature. | ||
*/ | ||
riseOffset: PropTypes.number, | ||
|
||
/** | ||
* When true, a mouse event on this marker will trigger the same event | ||
* on the map (unless L.DomEvent.stopPropagation is used). | ||
*/ | ||
bubblingMouseEvents: PropTypes.bool, | ||
|
||
/** | ||
* Whether to pan the map when dragging this marker near its edge or not. | ||
*/ | ||
autoPan: PropTypes.bool, | ||
|
||
/** | ||
* Distance (in pixels to the left/right and to the top/bottom) of the map | ||
* edge to start panning the map. | ||
*/ | ||
autoPanPadding: PropTypes.object, | ||
|
||
/** | ||
* Number of pixels the map should pan by. | ||
*/ | ||
autoPanSpeed: PropTypes.number, | ||
|
||
/** | ||
* If false, the layer will not emit mouse events and will act as a part of | ||
* the underlying map. | ||
*/ | ||
interactive: PropTypes.bool, | ||
|
||
// Inherited from MapLayer | ||
|
||
/** | ||
* The ID used to identify this component in Dash callbacks | ||
*/ | ||
id: PropTypes.string, | ||
|
||
/** | ||
* The children of this component | ||
*/ | ||
children: PropTypes.node, | ||
|
||
/** | ||
* The leaflet pane of the component | ||
*/ | ||
pane: PropTypes.string, | ||
|
||
/** | ||
* The attribution string for the component | ||
*/ | ||
attribution: PropTypes.string, | ||
|
||
// Events | ||
setProps: PropTypes.func, | ||
|
||
/** | ||
* Dash callback property. Number of times the marker has been clicked | ||
*/ | ||
n_clicks: PropTypes.number, | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters