rc-tile-map
Version:
160 lines (131 loc) • 7.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports['default'] = undefined;
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 _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _class, _temp2;
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _MapComponent2 = require('../MapComponent');
var _MapComponent3 = _interopRequireDefault(_MapComponent2);
var _layer = require('../propTypes/layer');
var _layer2 = _interopRequireDefault(_layer);
var _map = require('../propTypes/map');
var _map2 = _interopRequireDefault(_map);
var _index = require('../propTypes/index');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
require('../BMapLib/InfoBox');
var InfoBox = (_temp2 = _class = function (_MapComponent) {
_inherits(InfoBox, _MapComponent);
function InfoBox() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, InfoBox);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = InfoBox.__proto__ || Object.getPrototypeOf(InfoBox)).call.apply(_ref, [this].concat(args))), _this), _this.onClickMarker = function () {
var markerInstance = _this.context.markerInstance;
_this.componentInstance.open(markerInstance);
var dom = _this.getHtmlDomByReactDom(_this.props.children);
_this.bindContentEvents(_this.props.contentEvents, dom, markerInstance, _this.componentInstance);
_this.componentInstance.setContent(dom);
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(InfoBox, [{
key: 'createComponentInstance',
value: function createComponentInstance(props) {
var instance = new window.BMapLib.InfoBox(this.context.map, null, _extends({}, this.getOptions(props)));
if (!props.show) {
instance.hide();
}
return instance;
}
}, {
key: 'updateComponentInstance',
value: function updateComponentInstance(fromProps, toProps) {
this.updatePropsByBoolFun('show', 'hide', fromProps.show, toProps.show);
this.updatePropsByBoolFun('enableAutoPan', 'disableAutoPan', fromProps.enableAutoPan, toProps.enableAutoPan);
}
}, {
key: 'componentWillMount',
value: function componentWillMount() {
_get(InfoBox.prototype.__proto__ || Object.getPrototypeOf(InfoBox.prototype), 'componentWillMount', this).call(this);
this.componentInstance = this.createComponentInstance(this.props);
if (this.props.setComponentInstance) {
this.props.setComponentInstance(this.componentInstance);
}
}
}, {
key: 'componentDidMount',
value: function componentDidMount() {
var markerInstance = this.context.markerInstance;
if (markerInstance) {
// Attach to container component
markerInstance.addEventListener('click', this.onClickMarker);
}
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate(prevProps) {
this.updateComponentInstance(prevProps, this.props);
if (this.props.show) {
var oldContent = this.getHtmlDomByReactDom(prevProps.children).innerText;
var newContent = this.getHtmlDomByReactDom(this.props.children).innerText;
if (oldContent !== newContent) {
var dom = this.getHtmlDomByReactDom(this.props.children);
this.bindContentEvents(this.props.contentEvents, dom, this.context.markerInstance, this.componentInstance);
this.componentInstance.setContent(dom);
}
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.componentInstance.close();
var markerInstance = this.context.markerInstance;
if (markerInstance) {
markerInstance.removeEventListener('click', this.onClickMarker);
}
_get(InfoBox.prototype.__proto__ || Object.getPrototypeOf(InfoBox.prototype), 'componentWillUnmount', this).call(this);
}
}, {
key: 'render',
value: function render() {
return null;
}
}]);
return InfoBox;
}(_MapComponent3['default']), _class.defaultProps = {
enableAutoPan: true,
align: window.INFOBOX_AT_TOP,
show: true,
offset: window.BMap && new window.BMap.Size(0, 15),
boxClass: 'infoBox',
boxStyle: {},
closeIconMargin: '2px',
closeIconUrl: '//cdncs.101.com/v0.1/static/fish/image/close.png',
contentEvents: {}
}, _class.propTypes = {
children: _propTypes2['default'].node,
offset: _index.size,
boxClass: _propTypes2['default'].string,
boxStyle: _propTypes2['default'].object,
closeIconMargin: _propTypes2['default'].string,
closeIconUrl: _propTypes2['default'].string,
enableAutoPan: _propTypes2['default'].bool,
align: _propTypes2['default'].oneOf([window.INFOBOX_AT_TOP, window.INFOBOX_AT_BOTTOM]),
show: _propTypes2['default'].bool,
contentEvents: _propTypes2['default'].object
}, _class.contextTypes = {
map: _map2['default'],
markerInstance: _layer2['default']
}, _temp2);
exports['default'] = InfoBox;
module.exports = exports['default'];