Skip to content

Commit

Permalink
Add Pane
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulLeCam committed Oct 17, 2016
1 parent 10e7b12 commit 440d026
Show file tree
Hide file tree
Showing 28 changed files with 1,100 additions and 559 deletions.
1,116 changes: 753 additions & 363 deletions dist/react-leaflet.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/react-leaflet.min.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions example/components/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Leaflet from 'leaflet'
import React from 'react'
import { render } from 'react-dom'

Expand All @@ -12,6 +13,9 @@ import BoundsExample from './bounds'
import CustomComponentExample from './custom-component'
import AnimateExample from './animate'
import TooltipExample from './tooltip'
import PaneExample from './pane'

Leaflet.Icon.Default.imagePath = '//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0/images/'

const examples = (
<div>
Expand All @@ -31,6 +35,8 @@ const examples = (
<ZoomControlExample />
<h2>Layers control</h2>
<LayersControlExample />
<h2>Panes</h2>
<PaneExample />
<h2>Draggable Marker</h2>
<DraggableExample />
<h2>Map view by bounds</h2>
Expand Down
50 changes: 18 additions & 32 deletions example/components/pane.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react'
import { Pane, TileLayer, Rectangle } from '../../src'
import { Map, Pane, TileLayer, Rectangle } from '../../src'

const outer = [
[50.505, -29.09],
Expand All @@ -12,47 +12,33 @@ const inner = [

export default class PaneExample extends Component {
state = {
bounds: outer,
render: true,
}

onClickInner = () => {
this.setState({bounds: inner})
}

onClickOuter = () => {
this.setState({bounds: outer})
componentDidMount () {
setInterval(() => {
this.setState({
render: !this.state.render,
})
}, 5000)
}

render () {
return (
<Map bounds={this.state.bounds}>
<Map bounds={outer}>
<TileLayer
attribution='&copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url='http://{s}.tile.osm.org/{z}/{x}/{y}.png'
/>
<Pane name='cyan-rectangle' style={{
zIndex: 500,
}}>
<Rectangle
bounds={outer}
color={'Cyan'}
/>
</Pane>

<Pane name='yellow-rectangle' style={{
zIndex: 499,
}}>
<Rectangle
bounds={inner}
color={'Yellow'}
/>

{/* Nested Pane */}
<Pane name='purple-rectangle' className={'purplePane-purplePane'}>
<Rectangle
bounds={outer}
color={'Purple'}
/>
{this.state.render ? (
<Pane name='cyan-rectangle' style={{zIndex: 500}}>
<Rectangle bounds={outer} color='cyan' />
</Pane>
) : null}
<Pane name='yellow-rectangle' style={{zIndex: 499}}>
<Rectangle bounds={inner} color='yellow' />
<Pane name='purple-rectangle' className='purplePane-purplePane'>
<Rectangle bounds={outer} color='purple' />
</Pane>
</Pane>
</Map>
Expand Down
2 changes: 1 addition & 1 deletion lib/Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var Circle = function (_Path) {

var props = _objectWithoutProperties(_props, ['center', 'radius']);

this.leafletElement = (0, _leaflet.circle)(center, radius, props);
this.leafletElement = (0, _leaflet.circle)(center, radius, this.getOptions(props));
}
}, {
key: 'componentDidUpdate',
Expand Down
2 changes: 1 addition & 1 deletion lib/CircleMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var CircleMarker = function (_Path) {

var props = _objectWithoutProperties(_props, ['center']);

this.leafletElement = (0, _leaflet.circleMarker)(center, props);
this.leafletElement = (0, _leaflet.circleMarker)(center, this.getOptions(props));
}
}, {
key: 'componentDidUpdate',
Expand Down
2 changes: 1 addition & 1 deletion lib/FeatureGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var FeatureGroup = function (_Path) {
}, {
key: 'componentWillMount',
value: function componentWillMount() {
this.leafletElement = (0, _leaflet.featureGroup)();
this.leafletElement = (0, _leaflet.featureGroup)(this.getOptions(this.props));
}
}, {
key: 'componentDidMount',
Expand Down
4 changes: 2 additions & 2 deletions lib/GeoJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var GeoJSON = function (_Path) {

var props = _objectWithoutProperties(_props, ['data']);

this.leafletElement = (0, _leaflet.geoJSON)(data, props);
this.leafletElement = (0, _leaflet.geoJSON)(data, this.getOptions(props));
}
}, {
key: 'componentDidUpdate',
Expand All @@ -67,4 +67,4 @@ var GeoJSON = function (_Path) {
GeoJSON.propTypes = {
data: _react.PropTypes.oneOfType([_react.PropTypes.array, _react.PropTypes.object]).isRequired
};
exports.default = GeoJSON;
exports.default = GeoJSON;
2 changes: 1 addition & 1 deletion lib/GridLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var GridLayer = function (_MapLayer) {
key: 'componentWillMount',
value: function componentWillMount() {
_get(GridLayer.prototype.__proto__ || Object.getPrototypeOf(GridLayer.prototype), 'componentWillMount', this).call(this);
this.leafletElement = (0, _leaflet.gridLayer)(this.props);
this.leafletElement = (0, _leaflet.gridLayer)(this.getOptions(this.props));
}
}, {
key: 'componentDidUpdate',
Expand Down
2 changes: 1 addition & 1 deletion lib/ImageOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var ImageOverlay = function (_MapLayer) {

var props = _objectWithoutProperties(_props, ['bounds', 'url']);

this.leafletElement = (0, _leaflet.imageOverlay)(url, bounds, props);
this.leafletElement = (0, _leaflet.imageOverlay)(url, bounds, this.getOptions(props));
}
}, {
key: 'componentDidUpdate',
Expand Down
2 changes: 1 addition & 1 deletion lib/LayerGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var LayerGroup = function (_MapLayer) {
key: 'componentWillMount',
value: function componentWillMount() {
_get(LayerGroup.prototype.__proto__ || Object.getPrototypeOf(LayerGroup.prototype), 'componentWillMount', this).call(this);
this.leafletElement = (0, _leaflet.layerGroup)();
this.leafletElement = (0, _leaflet.layerGroup)(this.getOptions());
}
}]);

Expand Down
4 changes: 2 additions & 2 deletions lib/LayersControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ var LayersControl = function (_MapControl) {
}, {
key: 'addBaseLayer',
value: function addBaseLayer(layer, name) {
var checked = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
var checked = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;

if (checked) {
this.context.map.addLayer(layer);
Expand All @@ -217,7 +217,7 @@ var LayersControl = function (_MapControl) {
}, {
key: 'addOverlay',
value: function addOverlay(layer, name) {
var checked = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
var checked = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;

if (checked) {
this.context.map.addLayer(layer);
Expand Down
14 changes: 12 additions & 2 deletions lib/MapComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ var _clone2 = require('lodash/clone');

var _clone3 = _interopRequireDefault(_clone2);

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');
Expand Down Expand Up @@ -88,8 +90,8 @@ var MapComponent = function (_Component) {
}, {
key: 'bindLeafletEvents',
value: function bindLeafletEvents() {
var next = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var prev = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var next = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var prev = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

var el = this.leafletElement;
if (!el || !el.on) return {};
Expand Down Expand Up @@ -117,6 +119,14 @@ var MapComponent = function (_Component) {
var el = this.leafletElement;
if (el) el.fire(type, data);
}
}, {
key: 'getOptions',
value: function getOptions() {
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

var pane = props.pane || this.context.pane;
return pane ? _extends({}, props, { pane: pane }) : props;
}
}]);

return MapComponent;
Expand Down
3 changes: 2 additions & 1 deletion lib/MapLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ MapLayer.propTypes = {
};
MapLayer.contextTypes = {
layerContainer: _layerContainer2.default,
map: _map2.default
map: _map2.default,
pane: _react2.default.PropTypes.string
};
exports.default = MapLayer;
2 changes: 1 addition & 1 deletion lib/Marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var Marker = function (_MapLayer) {

var props = _objectWithoutProperties(_props, ['position']);

this.leafletElement = (0, _leaflet.marker)(position, props);
this.leafletElement = (0, _leaflet.marker)(position, this.getOptions(props));
}
}, {
key: 'componentDidUpdate',
Expand Down
Loading

0 comments on commit 440d026

Please sign in to comment.