84 lines
2.6 KiB
JavaScript
84 lines
2.6 KiB
JavaScript
"use strict";
|
|
|
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
|
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
|
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
import React, { Fragment } from 'react';
|
|
import { LeafletProvider } from './context';
|
|
import MapComponent from './MapComponent';
|
|
|
|
var MapLayer = /*#__PURE__*/function (_MapComponent) {
|
|
_inheritsLoose(MapLayer, _MapComponent);
|
|
|
|
function MapLayer(props) {
|
|
var _this;
|
|
|
|
_this = _MapComponent.call(this, props) || this;
|
|
|
|
_defineProperty(_assertThisInitialized(_this), "contextValue", void 0);
|
|
|
|
_defineProperty(_assertThisInitialized(_this), "leafletElement", void 0);
|
|
|
|
_this.leafletElement = _this.createLeafletElement(props);
|
|
return _this;
|
|
}
|
|
|
|
var _proto = MapLayer.prototype;
|
|
|
|
_proto.createLeafletElement = function createLeafletElement(_props) {
|
|
throw new Error('createLeafletElement() must be implemented');
|
|
};
|
|
|
|
_proto.updateLeafletElement = function updateLeafletElement(_fromProps, _toProps) {};
|
|
|
|
_proto.componentDidMount = function componentDidMount() {
|
|
_MapComponent.prototype.componentDidMount.call(this);
|
|
|
|
this.layerContainer.addLayer(this.leafletElement);
|
|
};
|
|
|
|
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
_MapComponent.prototype.componentDidUpdate.call(this, prevProps);
|
|
|
|
if (this.props.attribution !== prevProps.attribution) {
|
|
var map = this.props.leaflet.map;
|
|
|
|
if (map != null && map.attributionControl != null) {
|
|
map.attributionControl.removeAttribution(prevProps.attribution);
|
|
map.attributionControl.addAttribution(this.props.attribution);
|
|
}
|
|
}
|
|
|
|
this.updateLeafletElement(prevProps, this.props);
|
|
};
|
|
|
|
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
_MapComponent.prototype.componentWillUnmount.call(this);
|
|
|
|
this.layerContainer.removeLayer(this.leafletElement);
|
|
};
|
|
|
|
_proto.render = function render() {
|
|
var children = this.props.children;
|
|
|
|
if (children == null) {
|
|
return null;
|
|
}
|
|
|
|
return this.contextValue == null ? /*#__PURE__*/React.createElement(Fragment, null, children) : /*#__PURE__*/React.createElement(LeafletProvider, {
|
|
value: this.contextValue
|
|
}, children);
|
|
};
|
|
|
|
_createClass(MapLayer, [{
|
|
key: "layerContainer",
|
|
get: function get() {
|
|
return this.props.leaflet.layerContainer || this.props.leaflet.map;
|
|
}
|
|
}]);
|
|
|
|
return MapLayer;
|
|
}(MapComponent);
|
|
|
|
export { MapLayer as default }; |