Skip to content

Commit

Permalink
Merge pull request #132 from boromisp/master
Browse files Browse the repository at this point in the history
Layer container interface
  • Loading branch information
PaulLeCam committed Apr 3, 2016
2 parents d057013 + d19fbc7 commit 02ce664
Show file tree
Hide file tree
Showing 18 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/CanvasTileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import BaseTileLayer from './BaseTileLayer';
export default class CanvasTileLayer extends BaseTileLayer {
componentWillMount() {
super.componentWillMount();
const { map: _, ...props } = this.props;
const { map: _map, layerContainer: _lc, ...props } = this.props;
this.leafletElement = tileLayer.canvas(props);
}
}
2 changes: 1 addition & 1 deletion src/Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class Circle extends Path {

componentWillMount() {
super.componentWillMount();
const { center, map: _, radius, ...props } = this.props;
const { center, map: _map, layerContainer: _lc, radius, ...props } = this.props;
this.leafletElement = circle(center, radius, props);
}

Expand Down
2 changes: 1 addition & 1 deletion src/CircleMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class CircleMarker extends Path {

componentWillMount() {
super.componentWillMount();
const { center, map: _, ...props } = this.props;
const { center, map: _map, layerContainer: _lc, ...props } = this.props;
this.leafletElement = circleMarker(center, props);
}

Expand Down
2 changes: 1 addition & 1 deletion src/GeoJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class GeoJson extends Path {

componentWillMount() {
super.componentWillMount();
const { data, map: _, ...props } = this.props;
const { data, map: _map, layerContainer: _lc, ...props } = this.props;
this.leafletElement = geoJson(data, props);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ImageOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class ImageOverlay extends MapLayer {

componentWillMount() {
super.componentWillMount();
const { bounds, map: _, url, ...props } = this.props;
const { bounds, map: _map, layerContainer: _lc, url, ...props } = this.props;
this.leafletElement = imageOverlay(url, bounds, props);
}

Expand Down
2 changes: 1 addition & 1 deletion src/LayerGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class LayerGroup extends MapLayer {

render() {
return this.renderChildrenWithProps({
layerGroup: this.leafletElement,
layerContainer: this.leafletElement,
});
}
}
2 changes: 1 addition & 1 deletion src/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default class Map extends MapComponent {
render() {
const map = this.leafletElement;
const children = map ? React.Children.map(this.props.children, child => {
return child ? React.cloneElement(child, {map}) : null;
return child ? React.cloneElement(child, {map, layerContainer: map}) : null;
}) : null;

return (
Expand Down
13 changes: 7 additions & 6 deletions src/MapLayer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assign } from 'lodash';
import React, { PropTypes } from 'react';
import { Map } from 'leaflet';

import { layerContainer as layerContainerType } from './types';
import MapComponent from './MapComponent';

export default class MapLayer extends MapComponent {
Expand All @@ -10,22 +10,23 @@ export default class MapLayer extends MapComponent {
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]),
map: PropTypes.instanceOf(Map),
layerContainer: layerContainerType.isRequired,
map: PropTypes.instanceOf(Map).isRequired,
};

componentDidMount() {
super.componentDidMount();
(this.props.layerGroup || this.props.map).addLayer(this.leafletElement);
this.props.layerContainer.addLayer(this.leafletElement);
}

componentWillUnmount() {
super.componentWillUnmount();
(this.props.layerGroup || this.props.map).removeLayer(this.leafletElement);
this.props.layerContainer.removeLayer(this.leafletElement);
}

getClonedChildrenWithMap(extra) {
const { children, map } = this.props;
const props = assign({map}, extra);
const { children, map, layerContainer } = this.props;
const props = assign({map, layerContainer}, extra);

return React.Children.map(children, child => {
return child ? React.cloneElement(child, props) : null;
Expand Down
2 changes: 1 addition & 1 deletion src/Marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class Marker extends MapLayer {

componentWillMount() {
super.componentWillMount();
const { map: _, position, ...props } = this.props;
const { map: _map, layerContainer: _lc, position, ...props } = this.props;
this.leafletElement = marker(position, props);
}

Expand Down
2 changes: 1 addition & 1 deletion src/MultiPolygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class MultiPolygon extends Path {

componentWillMount() {
super.componentWillMount();
const { map: _, polygons, ...props } = this.props;
const { map: _map, layerContainer: _lc, polygons, ...props } = this.props;
this.leafletElement = multiPolygon(polygons, props);
}

Expand Down
2 changes: 1 addition & 1 deletion src/MultiPolyline.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class MultiPolyline extends Path {

componentWillMount() {
super.componentWillMount();
const {map: _, polylines, ...props} = this.props;
const {map: _map, layerContainer: _lc, polylines, ...props} = this.props;
this.leafletElement = multiPolyline(polylines, props);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class Polygon extends Path {

componentWillMount() {
super.componentWillMount();
const { map: _, positions, ...props } = this.props;
const { map: _map, layerContainer: _lc, positions, ...props } = this.props;
this.leafletElement = polygon(positions, props);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Polyline.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class Polyline extends Path {

componentWillMount() {
super.componentWillMount();
const { map: _, positions, ...props } = this.props;
const { map: _map, layerContainer: _lc, positions, ...props } = this.props;
this.leafletElement = polyline(positions, props);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class Rectangle extends Path {

componentWillMount() {
super.componentWillMount();
const { bounds, map: _, ...props } = this.props;
const { bounds, map: _map, layerContainer: _lc, ...props } = this.props;
this.leafletElement = rectangle(bounds, props);
}

Expand Down
2 changes: 1 addition & 1 deletion src/TileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class TileLayer extends BaseTileLayer {

componentWillMount() {
super.componentWillMount();
const { map: _, url, ...props } = this.props;
const { map: _map, layerContainer: _lc, url, ...props } = this.props;
this.leafletElement = tileLayer(url, props);
}

Expand Down
2 changes: 1 addition & 1 deletion src/WMSTileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class WMSTileLayer extends BaseTileLayer {

componentWillMount() {
super.componentWillMount();
const { map: _, url, ...props } = this.props;
const { map: _map, layerContainer: _lc, url, ...props } = this.props;
this.leafletElement = tileLayer.wms(url, props);
}
}
1 change: 1 addition & 0 deletions src/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export bounds from './bounds';
export controlPosition from './controlPosition';
export latlng from './latlng';
export latlngList from './latlngList';
export layerContainer from './layerContainer';
6 changes: 6 additions & 0 deletions src/types/layerContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { PropTypes } from 'react';

export default PropTypes.shape({
addLayer: PropTypes.func.isRequired,
removeLayer: PropTypes.func.isRequired,
});

0 comments on commit 02ce664

Please sign in to comment.