浏览代码

feat:add lib

wumu 5 年之前
父节点
当前提交
f504b8545f
共有 6 个文件被更改,包括 410 次插入1 次删除
  1. 1 1
      .gitignore
  2. 94 0
      lib/Circle.js
  3. 72 0
      lib/Geolocation.js
  4. 110 0
      lib/InfoWindow.js
  5. 122 0
      lib/LayerTraffic.js
  6. 11 0
      lib/index.js

+ 1 - 1
.gitignore

@@ -8,7 +8,7 @@
 
 # production
 /build
-/lib
+
 
 # misc
 .DS_Store

+ 94 - 0
lib/Circle.js

@@ -0,0 +1,94 @@
+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; }; }();
+
+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; }
+
+import React, { Component, PureComponent } from 'react';
+import PropTypes from 'prop-types';
+import { createCircle, updateCircle } from './api';
+var __com__ = 'Circle';
+//const debug = console.log;
+var debug = function debug() {};
+
+export var Circle = function (_Component) {
+  _inherits(Circle, _Component);
+
+  function Circle() {
+    _classCallCheck(this, Circle);
+
+    var _this = _possibleConstructorReturn(this, (Circle.__proto__ || Object.getPrototypeOf(Circle)).call(this));
+
+    _this.refElement = null;
+    _this._entity = null;
+    return _this;
+  }
+
+  _createClass(Circle, [{
+    key: 'componentDidMount',
+    value: function componentDidMount() {
+      var _props = this.props,
+          __map__ = _props.__map__,
+          options = _props.options,
+          events = _props.events,
+          children = _props.children;
+
+      var opts = _extends({}, options || {}, { map: __map__ });
+      this._entity = createCircle(opts, events);
+      if (this._entity) {
+        if (this.props.refer) this.props.refer(this._entity);
+      }
+    }
+  }, {
+    key: 'componentDidUpdate',
+    value: function componentDidUpdate(prevProps) {
+      var _props2 = this.props,
+          __map__ = _props2.__map__,
+          options = _props2.options,
+          events = _props2.events,
+          children = _props2.children;
+
+      var opts = _extends({}, options || {}, { map: __map__ });
+      if (!this._entity) {
+        this._entity = createCircle(opts, events);
+        if (this._entity) {
+          if (this.props.refer) this.props.refer(this._entity);
+        }
+        return;
+      }
+
+      // need check props changes, then update.
+      var oldOpts = _extends({}, prevProps.options || {}, {
+        map: prevProps.__map__
+      });
+      updateCircle(this._entity, opts, events, oldOpts, prevProps.events);
+    }
+  }, {
+    key: 'componentWillUnmount',
+    value: function componentWillUnmount() {
+      if (this._entity) {
+        this._entity.setMap(null);
+        this._entity = null;
+        if (this.props.refer) this.props.refer(this._entity);
+      }
+    }
+  }, {
+    key: 'render',
+    value: function render() {
+      return null;
+    }
+  }]);
+
+  return Circle;
+}(Component);
+
+Circle.propTypes = {
+  __map__: PropTypes.object,
+  options: PropTypes.object,
+  events: PropTypes.object
+};
+export default Circle;

+ 72 - 0
lib/Geolocation.js

@@ -0,0 +1,72 @@
+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; }; }();
+
+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; }
+
+import React, { Component } from "react";
+import PropTypes from "prop-types";
+import { getLocation } from "./api";
+var debug = function debug() {};
+
+var Geolocation = function (_Component) {
+  _inherits(Geolocation, _Component);
+
+  function Geolocation(props) {
+    _classCallCheck(this, Geolocation);
+
+    var _this = _possibleConstructorReturn(this, (Geolocation.__proto__ || Object.getPrototypeOf(Geolocation)).call(this, props));
+
+    _this._entity = null;
+    return _this;
+  }
+
+  _createClass(Geolocation, [{
+    key: "componentDidMount",
+    value: function componentDidMount() {
+      var _props = this.props,
+          __map__ = _props.__map__,
+          options = _props.options,
+          events = _props.events,
+          children = _props.children;
+
+      var opts = _extends({}, options || {}, { map: __map__ });
+      var evts = events || {};
+
+      this._entity = getLocation(opts, evts);
+    }
+  }, {
+    key: "componentDidUpdate",
+    value: function componentDidUpdate(prevProps) {
+      var _props2 = this.props,
+          __map__ = _props2.__map__,
+          options = _props2.options,
+          events = _props2.events;
+
+      var opts = _extends({}, options || {}, { map: __map__ });
+      var evts = events || {};
+      if (!this._entity) {
+        this._entity = getLocation(opts, evts);
+        return;
+      }
+    }
+  }, {
+    key: "render",
+    value: function render() {
+      return null;
+    }
+  }]);
+
+  return Geolocation;
+}(Component);
+
+Geolocation.propTypes = {
+  __map__: PropTypes.object,
+  options: PropTypes.object,
+  events: PropTypes.object
+};
+export default Geolocation;

+ 110 - 0
lib/InfoWindow.js

@@ -0,0 +1,110 @@
+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; }; }();
+
+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; }
+
+import React, { Component, PureComponent } from 'react';
+import PropTypes from 'prop-types';
+import { createInfoWindow, updateInfoWindow } from './api';
+var __com__ = 'InfoWindow';
+//const debug = console.log;
+var debug = function debug() {};
+
+// https://lbs.amap.com/api/javascript-api/reference/infowindow
+export var InfoWindow = function (_Component) {
+  _inherits(InfoWindow, _Component);
+
+  function InfoWindow() {
+    _classCallCheck(this, InfoWindow);
+
+    var _this = _possibleConstructorReturn(this, (InfoWindow.__proto__ || Object.getPrototypeOf(InfoWindow)).call(this));
+
+    _this.refElement = null;
+    _this._entity = null;
+    debug(__com__, 'constructor', _this._entity);
+    return _this;
+  }
+
+  _createClass(InfoWindow, [{
+    key: 'componentDidMount',
+    value: function componentDidMount() {
+      debug(__com__, 'componentDidMount', this._entity);
+      var _props = this.props,
+          __map__ = _props.__map__,
+          options = _props.options,
+          events = _props.events,
+          children = _props.children;
+      //let opts = { ...(options || {}), map: __map__, content: children };
+
+      var opts = _extends({}, options || {}, { map: __map__ });
+      this._entity = createInfoWindow(opts, events);
+      if (this._entity) {
+        if (this.props.refer) this.props.refer(this._entity);
+      }
+    }
+  }, {
+    key: 'componentDidUpdate',
+    value: function componentDidUpdate(prevProps) {
+      debug(__com__, 'componentDidUpdate', this._entity);
+      var _props2 = this.props,
+          __map__ = _props2.__map__,
+          options = _props2.options,
+          events = _props2.events,
+          children = _props2.children;
+      //let opts = { ...(options || {}), map: __map__, content: children };
+
+      var opts = _extends({}, options || {}, { map: __map__ });
+      if (!this._entity) {
+        this._entity = createInfoWindow(opts, events);
+        if (this._entity) {
+          if (this.props.refer) this.props.refer(this._entity);
+        }
+        return;
+      }
+
+      // need check props changes, then update.
+      var oldOpts = _extends({}, prevProps.options || {}, {
+        map: prevProps.__map__
+      });
+      updateInfoWindow(this._entity, opts, events, oldOpts, prevProps.events);
+    }
+  }, {
+    key: 'componentWillUnmount',
+    value: function componentWillUnmount() {
+      debug(__com__, 'componentWillUnmount', this._entity);
+      if (this._entity) {
+        //   this._entity.clearMap();
+        this._entity.setMap(null);
+        // delete this._entity;
+        this._entity = null;
+        if (this.props.refer) this.props.refer(this._entity);
+      }
+    }
+
+    // shouldComponentUpdate(nextProps, nextState) {
+    //   debug(__com__, 'shouldComponentUpdate', this._entity);
+    //   return false;
+    // }
+
+  }, {
+    key: 'render',
+    value: function render() {
+      debug(__com__, 'render', this._entity);
+      return null;
+    }
+  }]);
+
+  return InfoWindow;
+}(Component);
+
+InfoWindow.propTypes = {
+  __map__: PropTypes.object,
+  options: PropTypes.object,
+  events: PropTypes.object
+};
+export default InfoWindow;

+ 122 - 0
lib/LayerTraffic.js

@@ -0,0 +1,122 @@
+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; }; }();
+
+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; }
+
+import React, { Component, PureComponent } from 'react';
+import PropTypes from 'prop-types';
+import { createTraffic, updateTraffic } from './api';
+var __com__ = 'Traffic';
+//const debug = console.log;
+var debug = function debug() {};
+
+export var Traffic = function (_Component) {
+  _inherits(Traffic, _Component);
+
+  function Traffic() {
+    _classCallCheck(this, Traffic);
+
+    var _this = _possibleConstructorReturn(this, (Traffic.__proto__ || Object.getPrototypeOf(Traffic)).call(this));
+
+    _this.refElement = null;
+    _this._entity = null;
+    debug(__com__, 'constructor', _this._entity);
+    return _this;
+  }
+
+  _createClass(Traffic, [{
+    key: 'componentWillMount',
+    value: function componentWillMount() {
+      debug(__com__, 'componentWillMount', this.props, this._entity);
+    }
+  }, {
+    key: 'componentDidMount',
+    value: function componentDidMount() {
+      debug(__com__, 'componentDidMount', this.props, this._entity);
+      var _props = this.props,
+          __map__ = _props.__map__,
+          options = _props.options,
+          events = _props.events,
+          children = _props.children;
+      //let opts = { ...(options || {}), map: __map__, content: children };
+
+      var opts = _extends({}, options || {}, { map: __map__ });
+      this._entity = createTraffic(opts, events);
+      if (this._entity) {
+        if (this.props.refer) this.props.refer(this._entity);
+      }
+    }
+  }, {
+    key: 'componentWillReceiveProps',
+    value: function componentWillReceiveProps(nextProps) {
+      debug(__com__, 'componentWillReceiveProps', this.props, this._entity);
+    }
+  }, {
+    key: 'componentWillUpdate',
+    value: function componentWillUpdate() {
+      debug(__com__, 'componentWillUpdate', this.props, this._entity);
+    }
+  }, {
+    key: 'componentDidUpdate',
+    value: function componentDidUpdate(prevProps) {
+      debug(__com__, 'componentDidUpdate', this.props, this._entity);
+      var _props2 = this.props,
+          __map__ = _props2.__map__,
+          options = _props2.options,
+          events = _props2.events;
+
+      var opts = _extends({}, options || {}, { map: __map__ });
+      if (!this._entity) {
+        debug(__com__, 'componentDidUpdate', opts, events);
+        this._entity = createTraffic(opts, events);
+        if (this._entity) {
+          if (this.props.refer) this.props.refer(this._entity);
+        }
+        return;
+      }
+
+      // need check props changes, then update.
+      var oldOpts = _extends({}, prevProps.options || {}, {
+        map: prevProps.__map__
+      });
+      updateTraffic(this._entity, opts, events, oldOpts, prevProps.events);
+    }
+  }, {
+    key: 'componentWillUnmount',
+    value: function componentWillUnmount() {
+      debug(__com__, 'componentWillUnmount', this.props, this._entity);
+      if (this._entity) {
+        this._entity.setMap(null);
+        // delete this._entity;
+        this._entity = null;
+        if (this.props.refer) this.props.refer(this._entity);
+      }
+    }
+
+    // shouldComponentUpdate(nextProps, nextState) {
+    //   debug(__com__, 'shouldComponentUpdate', this._entity);
+    //   return false;
+    // }
+
+  }, {
+    key: 'render',
+    value: function render() {
+      debug(__com__, 'render', this._entity);
+      return null;
+    }
+  }]);
+
+  return Traffic;
+}(Component);
+
+Traffic.propTypes = {
+  __map__: PropTypes.object,
+  options: PropTypes.object,
+  events: PropTypes.object
+};
+export default Traffic;

+ 11 - 0
lib/index.js

@@ -0,0 +1,11 @@
+import Map from './Map';
+import Circle from './Circle';
+import Geolocation from './Geolocation';
+import InfoWindow from './InfoWindow';
+import LayerTraffic from './LayerTraffic';
+import Marker from './Marker';
+import MassMarks from './MassMarks';
+import Polygon from './Polygon';
+import Polyline from './Polyline';
+
+export { Map, Circle, Geolocation, InfoWindow, LayerTraffic, Marker, MassMarks, Polygon, Polyline };