gis-common 2.1.2 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "gis-common",
3
3
  "description": "gis-common",
4
- "main": "dist/resource.min.js",
5
- "version": "2.1.2",
4
+ "main": "src/index.js",
5
+ "version": "2.2.3",
6
6
  "author": "Guo.Yan <luv02@vip.qq.com>",
7
7
  "license": "MIT",
8
8
  "private": false,
@@ -10,12 +10,14 @@
10
10
  "dev": "cross-env NODE_ENV=development webpack-dev-server --hot --port 7000",
11
11
  "build": "cross-env NODE_ENV=production webpack --progress"
12
12
  },
13
+ "files": [
14
+ "src"
15
+ ],
13
16
  "browserslist": [
14
17
  "> 1%",
15
18
  "last 2 versions",
16
19
  "not ie <= 8"
17
20
  ],
18
- "files": [],
19
21
  "devDependencies": {
20
22
  "babel-core": "^6.26.0",
21
23
  "babel-loader": "^7.1.2",
Binary file
@@ -0,0 +1,20 @@
1
+ export default {
2
+ LOGIN_EXPIRED: '登录信息过期,请重新登录',
3
+ CROSS_ERROR: '跨域访问',
4
+ UNEXIST_RESOURCE: '资源不存在',
5
+ TIMEOUT: '请求超时',
6
+ INTERNAL_ERROR: '内部错误',
7
+ NETWORK_ERROR: '请求失败,请检查网络是否已连接',
8
+ PROCESS_FAIL: '处理失败',
9
+ AUTH_VERIFY_ERROR: '权限验证失败',
10
+ NO_DATA_FOUND: '未找到数据',
11
+ DUPLICATE_INSTANCE: '实例为单例模式,不允许重复构建',
12
+ COORDINATE_ERROR: '坐标验证失败',
13
+ JSON_PARSE_ERROR: 'JSON解析失败,格式有误',
14
+ JSON_VALUE_ERROR: 'JSON无此键',
15
+ PARAMETER_ERROR: '参数验证失败',
16
+ PARAMETER_ERROR_ARRAY: '参数格式验证失败:必须是数组',
17
+ PARAMETER_ERROR_STRING: '参数格式验证失败:必须是字符',
18
+ PARAMETER_ERROR_FUNCTION: '参数格式验证失败:必须是函数',
19
+ PARAMETER_ERROR_LACK: '参数缺失',
20
+ }
@@ -0,0 +1,23 @@
1
+ export default {
2
+ MAP_RENDER: "mapRender",
3
+ MAP_READY: "mapReady",
4
+ MOUSE_CLICK: "click",
5
+ MOUSE_DOUBLE_CLICK: "dblclick",
6
+ MOUSE_MOVE: "mousemove",
7
+ MOUSE_IN: "mousein",
8
+ MOUSE_OUT: "mouseout",
9
+ MOUSE_RIGHT_CLICK: "mouseRightClick",
10
+ KEY_DOWN: "keyDown",
11
+ KEY_UP: "keyUp",
12
+ DRAW_ACTIVE: "drawActive",
13
+ DRAW_MOVE: "drawMove",
14
+ DRAW_COMPLETE: "drawComplete",
15
+ MQTT_CONNECT: "mqttConnect",
16
+ MQTT_ERROR: "mqttError",
17
+ MQTT_MESSAGE: "mqttMessage",
18
+ MQTT_CLOSE: "mqttClose",
19
+ WEB_SOCKET_CONNECT: "webSocketConnect",
20
+ WEB_SOCKET_ERROR: "webSocketError",
21
+ WEB_SOCKET_MESSAGE: "webSocketMessage",
22
+ WEB_SOCKET_CLOSE: "webSocketClose"
23
+ };
@@ -0,0 +1,16 @@
1
+ export const GraphicType = {
2
+ POINT: 'point',
3
+ POLYLINE: 'polyline',
4
+ POLYGON: 'polygon',
5
+ BILLBOARD: 'billboard',
6
+ CYLINDER: 'cylinder',
7
+ ELLIPSOID: 'ellipsoid',
8
+ LABEL: 'label',
9
+ MODEL: 'model',
10
+ WALL: 'wall',
11
+ }
12
+ export const MeasureMode = {
13
+ DISTANCE: 'distance',
14
+ AREA: 'area',
15
+ HEIGHT: 'height',
16
+ }
@@ -0,0 +1,9 @@
1
+ export default {
2
+ SUPER_MAP_IMAGES: "SuperMapImages", // 超图影像服务 栅格数据
3
+ SUPER_MAP_DATA: "SuperMapData", // 超图服务 矢量数据
4
+ ARC_GIS_MAP_IMAGES: "ArcGisMapImages", // arcGis影像图层 栅格数据
5
+ ARC_GIS_MAP_DATA: "ArcGisMapData", // arcGis图层 矢量数据
6
+ OSGB_LAYER: "OSGBLayer",
7
+ S3M_GROUP: "S3MGroup", // addS3MGroupLayer(url, options, index) 添加S3M分组图层。
8
+ TERRAIN_LAYER: "TerrainFileLayer" // 地形图层, 需要单独处理
9
+ };
@@ -0,0 +1,4 @@
1
+ export { default as EventType } from './EventTypeConstant'
2
+ export { default as ErrorType } from './ErrorTypeConstant'
3
+ export { default as LayerType } from './LayerType'
4
+ export * from './GraphicConstant'
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @description 声音播放类
3
+ * @export
4
+ * @class AudioPlayer
5
+ */
6
+ export default class AudioPlayer {
7
+ /**
8
+ * Creates an instance of AudioPlayer.
9
+ * @param {*} url
10
+ */
11
+ constructor(url) {
12
+ this.audio = new Audio()
13
+ this.audio.src = url
14
+ }
15
+ play() {
16
+ !this.muted && this.audio.play()
17
+ }
18
+ pause() {
19
+ this.audio.pause()
20
+ }
21
+ get muted() {
22
+ return this.audio.muted
23
+ }
24
+ /**
25
+ * @description 设置静音状态,如果静音,autoplay属性将失效
26
+ */
27
+ set muted(val) {
28
+ this.audio.muted = val
29
+ }
30
+ }
@@ -0,0 +1,51 @@
1
+ import CommUtils from '../utils/CommUtils'
2
+ import MathUtils from '../utils/MathUtils';
3
+ export default class CanvasDrawer {
4
+ constructor(el) {
5
+ if (CommUtils.getDataType(el) === 'String') {
6
+ el = document.querySelector('#' + el)
7
+ }
8
+ this.ctx = el.getContext('2d')
9
+ }
10
+ drawLine(startX, startY, endX, endY, options = {}) {
11
+ this.cxt.beginPath();
12
+ const width = options.width || 1
13
+ const color = options.color || '#000'
14
+ this.cxt.lineWidth = width;
15
+ this.cxt.fillStyle = color;// 经过测试不管是fillStyle还是StrokeStyle都是一样的
16
+ this.cxt.moveTo(startX, startY);
17
+ this.cxt.lineTo(endX, endY);
18
+ this.cxt.closePath();
19
+ this.cxt.fill();
20
+ }
21
+ /**
22
+ * 绘制圆弧
23
+ * @param {*} x 圆心X坐标
24
+ * @param {*} y 圆心Y坐标
25
+ * @param {*} radius 半径
26
+ * @param {*} startAngle 开始的弧度
27
+ * @param {*} endAngle 结束的弧度
28
+ * @param {*} anticlockwise true为逆时针,false为顺时针
29
+ * @param {boolean} isOnlyArc
30
+ * @param {boolean} isFill 是否是填充,false为绘制边框,true为绘制填充
31
+ * @param {*} bgColor 圆弧的颜色
32
+ * @memberof CanvasDrawer
33
+ */
34
+ drawArc(x, y, radius, startAngle, endAngle, anticlockwise, isFill, bgColor) {
35
+ if (isFill) {
36
+ //为true绘制填充圆弧
37
+ this.cxt.fillStyle = bgColor
38
+ this.cxt.beginPath()
39
+ this.cxt.arc(x, y, radius, MathUtils.degreesToRadians(startAngle), MathUtils.degreesToRadians(endAngle), anticlockwise)
40
+ this.cxt.closePath()
41
+ this.cxt.fill()
42
+ } else {
43
+ //为false绘制边框圆弧
44
+ this.cxt.strokeStyle = bgColor
45
+ this.cxt.beginPath()
46
+ this.cxt.arc(x, y, radius, MathUtils.degreesToRadians(startAngle), MathUtils.degreesToRadians(endAngle), anticlockwise)
47
+
48
+ this.cxt.stroke()
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,86 @@
1
+ export default class DevicePixelRatio {
2
+ constructor(magnification = 1) {
3
+ this.magnification = magnification
4
+ }
5
+ // 获取系统类型
6
+ _getSystem() {
7
+ // let flag = false;
8
+ var agent = navigator.userAgent.toLowerCase()
9
+ // var isMac = /macintosh|mac os x/i.test(navigator.userAgent);
10
+ // if(isMac) {
11
+ // return false;
12
+ // }
13
+ // 现只针对windows处理,其它系统暂无该情况,如有,继续在此添加
14
+ if (agent.indexOf('windows') >= 0) {
15
+ return true
16
+ }
17
+ }
18
+ // 获取页面缩放比例
19
+ // _getDevicePixelRatio() {
20
+ // let t = this;
21
+ // }
22
+ // 监听方法兼容写法
23
+ _addHandler(element, type, handler) {
24
+ if (element.addEventListener) {
25
+ element.addEventListener(type, handler, false)
26
+ } else if (element.attachEvent) {
27
+ element.attachEvent('on' + type, handler)
28
+ } else {
29
+ element['on' + type] = handler
30
+ }
31
+ }
32
+ // 校正浏览器缩放比例
33
+ _correct() {
34
+ // 配合px2rem插件进行自适应布局
35
+ let pageWidth = window.innerWidth
36
+ //为了ie也能拿到可视窗口宽度
37
+ if (typeof pageWidth != 'number') {
38
+ //标准模式
39
+ if (document.compatMode == 'CSS1Compat') {
40
+ pageWidth = document.documentElement.clientWidth
41
+ //怪异模式
42
+ } else {
43
+ pageWidth = document.body.clientWidth
44
+ }
45
+ }
46
+ if (pageWidth <= 750) {
47
+ const baseSize = 75
48
+ // 当前页面宽度相对于 750 宽的缩放比例,可根据自己需要修改。
49
+ const scale = document.documentElement.clientWidth / pageWidth
50
+ // 设置页面根节点字体大小
51
+ document.documentElement.style.fontSize = this.magnification * baseSize * Math.min(scale, 2) + 'px'
52
+ } else if (pageWidth > 750 && pageWidth <= 1200) {
53
+ const baseSize = 85
54
+ // 当前页面宽度相对于 750 宽的缩放比例,可根据自己需要修改。
55
+ const scale = document.documentElement.clientWidth / pageWidth
56
+ // 设置页面根节点字体大小
57
+ document.documentElement.style.fontSize = this.magnification * baseSize * Math.min(scale, 2) + 'px'
58
+ } else {
59
+ const baseSize = 100
60
+ // 当前页面宽度相对于 750 宽的缩放比例,可根据自己需要修改。
61
+ const scale = document.documentElement.clientWidth / 1920
62
+ // 设置页面根节点字体大小
63
+ document.documentElement.style.fontSize = this.magnification * baseSize * Math.min(scale, 2) + 'px'
64
+ }
65
+ }
66
+ // 监听页面缩放
67
+ _watch() {
68
+ let t = this
69
+ t._addHandler(window, 'resize', function () {
70
+ // 注意这个方法是解决全局有两个window.resize
71
+ // 重新校正
72
+ t._correct()
73
+ })
74
+ }
75
+ // 初始化页面比例
76
+ init() {
77
+ let t = this
78
+ if (t._getSystem()) {
79
+ // 判断设备,目前只在windows系统下校正浏览器缩放比例
80
+ // 初始化页面校正浏览器缩放比例
81
+ t._correct()
82
+ // 开启监听页面缩放
83
+ t._watch()
84
+ }
85
+ }
86
+ }
@@ -0,0 +1,88 @@
1
+ export default class ElQuery {
2
+ constructor(selector, el = document) {
3
+ if (typeof selector == 'string') {
4
+ if (selector.charAt(0) == '<' && selector.slice(-1) == '>') {
5
+ var ele = selector.slice(1, -1)
6
+ this[0] = document.createElement(ele)
7
+ this.length = 1
8
+ } else {
9
+ var all = el.querySelectorAll(selector)
10
+ for (var i = 0; i < all.length; i++) {
11
+ this[i] = all[i]
12
+ }
13
+ this.length = all.length
14
+ }
15
+ } else if (typeof selector == 'undefined') {
16
+ return this
17
+ } else if (typeof selector == 'function') {
18
+ this.ready(selector)
19
+ } else if (selector.nodeType == 1) {
20
+ this[0] = selector
21
+ this.length = 1
22
+ }
23
+ }
24
+ each(callback) {
25
+ for (var i = 0; i < this.length; i++) {
26
+ callback(this[i], i)
27
+ }
28
+ }
29
+ html(val) {
30
+ this.each(function (obj) {
31
+ obj.innerHTML = val
32
+ })
33
+ return this
34
+ }
35
+ css(attr, val) {
36
+ this.each(function (obj) {
37
+ if (typeof attr == 'object') {
38
+ for (var i in attr) {
39
+ if (i == 'width' || i == 'height' || i == 'margin' || i == 'fontSize') {
40
+ obj.style[i] = parseInt(attr[i]) + 'px'
41
+ }
42
+ obj.style[i] = attr[i]
43
+ }
44
+ } else {
45
+ obj.style[attr] = val
46
+ }
47
+ })
48
+ return this
49
+ }
50
+ ready(callback) {
51
+ document.addEventListener('DOMContentLoaded', (e) => {
52
+ callback.call(this, e)
53
+ })
54
+ }
55
+ click(callback) {
56
+ this.each(function (obj) {
57
+ obj.onclick = (e) => {
58
+ callback.call(this, e, obj)
59
+ }
60
+ })
61
+ return this
62
+ }
63
+ on(type, callback) {
64
+ this.each((obj) => {
65
+ obj.removeEventListener(type, (e) => {
66
+ callback.call(this, e)
67
+ })
68
+ obj.addEventListener(type, (e) => {
69
+ callback.call(this, e)
70
+ })
71
+ })
72
+ }
73
+ appendTo(dom) {
74
+ if (typeof dom == 'string') {
75
+ var all = document.querySelectorAll(dom)
76
+ var ele = this[0]
77
+ for (var i = 0; i < all.length; i++) {
78
+ this[i] = ele.cloneNode(true)
79
+ all[i].appendChild(this[i])
80
+ this.length = all.length
81
+ }
82
+ } else {
83
+ dom.appendChild(this[0])
84
+ }
85
+ return this
86
+ }
87
+ }
88
+ window.$ = (selector, el) => new ElQuery(selector, el)
@@ -0,0 +1,93 @@
1
+ function EventDispatcher() {}
2
+
3
+ Object.assign(EventDispatcher.prototype, {
4
+ /**
5
+ * 添加监听器
6
+ * @param type{string}
7
+ * @param listener{function}
8
+ * @param mutexStatus{boolean}
9
+ */
10
+ addEventListener(type, listener, context, mutexStatus = false) {
11
+ if (this._listeners === undefined) this._listeners = {}
12
+ this._mutex = this._mutex || {}
13
+ this._context = context
14
+ const mutex = this._mutex
15
+ const listeners = this._listeners
16
+
17
+ if (listeners[type] === undefined) {
18
+ listeners[type] = []
19
+ }
20
+
21
+ if (listeners[type].indexOf(listener) === -1) {
22
+ // 如果启用功能独占
23
+ if (mutexStatus) {
24
+ mutex[type] = listener
25
+ }
26
+ listeners[type].push(listener)
27
+ }
28
+ return this
29
+ },
30
+
31
+ hasEventListener(type, listener) {
32
+ if (this._listeners === undefined) return false
33
+
34
+ const listeners = this._listeners
35
+
36
+ return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1
37
+ },
38
+
39
+ removeEventListener(type, listener) {
40
+ if (this._listeners === undefined) return
41
+
42
+ const listeners = this._listeners
43
+ const listenerArray = listeners[type]
44
+
45
+ // 移除指定的功能独占
46
+ if (this._mutex[type] === listener) {
47
+ this._mutex[type] = null
48
+ }
49
+
50
+ if (listenerArray !== undefined) {
51
+ const index = listenerArray.map((d) => d.toString()).indexOf(listener.toString())
52
+
53
+ if (index !== -1) {
54
+ listenerArray.splice(index, 1)
55
+ }
56
+ }
57
+ },
58
+
59
+ /**
60
+ * 派发事件
61
+ * @param event{{type: string, message: {}}}
62
+ */
63
+ dispatchEvent(event) {
64
+ if (this._listeners === undefined) return
65
+
66
+ const listeners = this._listeners
67
+ const listenerArray = listeners[event.type]
68
+
69
+ if (listenerArray !== undefined) {
70
+ event.target = this
71
+
72
+ // Make a copy, in case listeners are removed while iterating.
73
+ const array = listenerArray.slice(0)
74
+ if (this._mutex[event.type]) {
75
+ const find = array.find((item) => item === this._mutex[event.type])
76
+ find.call(this._context || this, event)
77
+ return
78
+ }
79
+ for (let i = 0, l = array.length; i < l; i++) {
80
+ array[i].call(this._context || this, event)
81
+ }
82
+ }
83
+ },
84
+
85
+ removeAllListener() {
86
+ this._mutex = {}
87
+ for (const key in this._listeners) {
88
+ this._listeners[key] = []
89
+ }
90
+ },
91
+ })
92
+
93
+ export default EventDispatcher
@@ -0,0 +1,36 @@
1
+ export default class HashMap {
2
+ constructor() {
3
+ this.elements = [];
4
+ return new Map();
5
+ }
6
+ set(key, value) {
7
+ Map.prototype.set.call(this, key, value);
8
+ this.elements.push({ key, value });
9
+ }
10
+ delete(key) {
11
+ Map.prototype.delete.call(this, key);
12
+ this.elements = this.elements.filter(d => d.key !== key);
13
+ }
14
+ isEmpty() {
15
+ return this.size === 0;
16
+ }
17
+ clear() {
18
+ Map.prototype.clear.call(this);
19
+ this.elements = [];
20
+ }
21
+ /**
22
+ * 通过数组创建Map对象
23
+ *
24
+ * @static
25
+ * @param {*} array
26
+ */
27
+ static fromEntries(array = []) {
28
+ const hashMap = new HashMap();
29
+ array.forEach(element => {
30
+ if (Array.isArray(element) && element.length === 2) {
31
+ hashMap.set(element[0], element[1]);
32
+ }
33
+ });
34
+ return hashMap;
35
+ }
36
+ }
@@ -0,0 +1,108 @@
1
+ import ErrorType from "../constant/ErrorTypeConstant";
2
+ import EventType from "../constant/EventTypeConstant";
3
+ import CommUtils from "../utils/CommUtils";
4
+ import EventDispatcher from "./EventDispatcher";
5
+ import { connect } from "mqtt";
6
+ export default class MqttClient extends EventDispatcher {
7
+ /**
8
+ * Creates an instance of MqttClient.
9
+ * @param {*} config mqtt实例参数
10
+ */
11
+ constructor(config = {}) {
12
+ super();
13
+ this.context = CommUtils.extend(MqttClient.defaultContext, config);
14
+ this.options = {
15
+ connectTimeout: this.context.MQTT_TIMEOUTM,
16
+ clientId: CommUtils.generateGuid(),
17
+ username: this.context.MQTT_USERNAME,
18
+ password: this.context.MQTT_PASSWORD,
19
+ clean: true,
20
+ };
21
+ this.client = connect(this.context.MQTT_SERVICE, this.options);
22
+ this._onConnect();
23
+ this._onMessage();
24
+ MqttClient.instance = this;
25
+ }
26
+ _onConnect() {
27
+ this.client.on("connect", () => {
28
+ console.log("链接mqtt成功==>" + this.context.MQTT_SERVICE);
29
+ this.dispatchEvent({ type: EventType.MQTT_CONNECT, message: this });
30
+ });
31
+ this.client.on("error", (err) => {
32
+ console.log("链接mqtt报错", err);
33
+ this.dispatchEvent({ type: EventType.MQTT_ERROR, message: this });
34
+ this.client.end();
35
+ this.client.reconnect();
36
+ });
37
+ }
38
+ _onMessage() {
39
+ this.client.on("message", (topic, message) => {
40
+ let dataString = message;
41
+ let data = "";
42
+ if (message instanceof Uint8Array) {
43
+ dataString = message.toString();
44
+ }
45
+ try {
46
+ data = JSON.parse(dataString);
47
+ } catch (error) {
48
+ throw new Error(ErrorType.JSON_PARSE_ERROR);
49
+ }
50
+ this.dispatchEvent({
51
+ type: EventType.MQTT_MESSAGE,
52
+ message: { topic, data },
53
+ });
54
+ });
55
+ }
56
+ sendMsg(topic, msg) {
57
+ if (!this.client.connected) {
58
+ console.error("客户端未连接");
59
+ return;
60
+ }
61
+ this.client.publish(topic, msg, { qos: 1, retain: true });
62
+ }
63
+ subscribe(topic) {
64
+ this.client.subscribe(topic, { qos: 1 }, (error, res) => {
65
+ if (error instanceof Error || res.length === 0) {
66
+ console.error(`订阅失败==>${topic}`, error);
67
+ } else {
68
+ console.log(`订阅成功==>${topic}`);
69
+ }
70
+ });
71
+ return this;
72
+ }
73
+ unsubscribe(topic) {
74
+ this.client.unsubscribe(topic, { qos: 1 }, (error, res) => {
75
+ if (error instanceof Error || res.length === 0) {
76
+ console.error(`取消订阅失败==>${topic}`, error);
77
+ } else {
78
+ console.log(`取消订阅成功==>${topic}`);
79
+ }
80
+ });
81
+ return this;
82
+ }
83
+ unconnect() {
84
+ this.client.end();
85
+ this.client = null;
86
+ this.dispatchEvent({ type: EventType.MQTT_CLOSE, message: null });
87
+ console.log("断开mqtt成功==>" + this.context.MQTT_SERVICE);
88
+ }
89
+ /**
90
+ * @description 获取并冻结mqtt实例
91
+ * @static
92
+ * @param {*} [config={}]
93
+ * @returns {MqttClient}
94
+ */
95
+ static getInstance(config = {}) {
96
+ if (MqttClient.instance) {
97
+ return Object.freeze(MqttClient.instance);
98
+ } else {
99
+ return Object.freeze(new MqttClient(config));
100
+ }
101
+ }
102
+ }
103
+ MqttClient.defaultContext = {
104
+ MQTT_TIMEOUTM: 20000,
105
+ MQTT_USERNAME: "iRVMS-WEB",
106
+ MQTT_PASSWORD: "novasky888",
107
+ MQTT_SERVICE: `ws://${window.document.domain}:20007/mqtt`,
108
+ };