rc-tile-map
Version:
116 lines (96 loc) • 5.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports['default'] = undefined;
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, _temp;
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _MapComponent2 = require('../MapComponent');
var _MapComponent3 = _interopRequireDefault(_MapComponent2);
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; }
var Icon = (_temp = _class = function (_MapComponent) {
_inherits(Icon, _MapComponent);
function Icon() {
_classCallCheck(this, Icon);
return _possibleConstructorReturn(this, (Icon.__proto__ || Object.getPrototypeOf(Icon)).apply(this, arguments));
}
_createClass(Icon, [{
key: 'createComponentInstance',
value: function createComponentInstance(props) {
var label = new window.BMap.Icon(props.imageUrl, props.size, this.getOptions(props));
if (props.imageSize) {
label.setImageSize(props.imageSize);
}
if (!props.show) {
label.hide();
}
return label;
}
}, {
key: 'updateComponentInstance',
value: function updateComponentInstance(fromProps, toProps) {
this.updatePropsByBoolFun('show', 'hide', fromProps.show, toProps.show);
this.updatePropsBySetFun('setImageUrl', fromProps.imageUrl, toProps.imageUrl);
this.updatePropsBySetFun('setSize', fromProps.size, toProps.size);
this.updatePropsBySetFun('setImageSize', fromProps.imageSize, toProps.imageSize);
this.updatePropsBySetFun('setAnchor', fromProps.anchor, toProps.anchor);
this.updatePropsBySetFun('setImageOffset', fromProps.imageOffset, toProps.imageOffset);
this.updatePropsBySetFun('setInfoWindowAnchor', fromProps.infoWindowAnchor, toProps.infoWindowAnchor);
var markerInstance = this.context.markerInstance;
if (markerInstance) {
markerInstance.setIcon(this.componentInstance);
}
}
}, {
key: 'componentWillMount',
value: function componentWillMount() {
_get(Icon.prototype.__proto__ || Object.getPrototypeOf(Icon.prototype), 'componentWillMount', this).call(this);
this.componentInstance = this.createComponentInstance(this.props);
}
}, {
key: 'componentDidMount',
value: function componentDidMount() {
var markerInstance = this.context.markerInstance;
if (markerInstance) {
markerInstance.setIcon(this.componentInstance);
}
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate(prevProps) {
this.updateComponentInstance(prevProps, this.props);
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
_get(Icon.prototype.__proto__ || Object.getPrototypeOf(Icon.prototype), 'componentWillUnmount', this).call(this);
}
}, {
key: 'render',
value: function render() {
return null;
}
}]);
return Icon;
}(_MapComponent3['default']), _class.defaultProps = {
show: true
}, _class.propTypes = {
imageUrl: _propTypes2['default'].string,
imageSize: _index.size,
size: _index.size,
anchor: _index.size,
imageOffset: _index.size,
infoWindowAnchor: _index.size,
show: _propTypes2['default'].bool
}, _class.contextTypes = {
markerInstance: _index.layer
}, _temp);
exports['default'] = Icon;
module.exports = exports['default'];