pass_b_map_vue2 0.0.1

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.
Files changed (103) hide show
  1. package/.eslintrc.js +22 -0
  2. package/.github/ISSUE_TEMPLATE.md +7 -0
  3. package/.travis.yml +26 -0
  4. package/CONTRIBUTING.md +27 -0
  5. package/LICENSE +21 -0
  6. package/README.md +52 -0
  7. package/build/compiler.js +127 -0
  8. package/build/webpack.docs.config.js +86 -0
  9. package/build/webpack.prod.config.js +24 -0
  10. package/build/webpack.test.config.js +27 -0
  11. package/components/base/bindEvent.js +11 -0
  12. package/components/base/events.js +120 -0
  13. package/components/base/factory.js +39 -0
  14. package/components/base/mixins/abstract.js +13 -0
  15. package/components/base/mixins/common.js +81 -0
  16. package/components/base/util.js +6 -0
  17. package/components/context-menu/Item.vue +62 -0
  18. package/components/context-menu/Menu.vue +52 -0
  19. package/components/controls/CityList.vue +43 -0
  20. package/components/controls/Control.vue +37 -0
  21. package/components/controls/Copyright.vue +52 -0
  22. package/components/controls/Geolocation.vue +59 -0
  23. package/components/controls/MapType.vue +39 -0
  24. package/components/controls/Navigation.vue +55 -0
  25. package/components/controls/OverviewMap.vue +56 -0
  26. package/components/controls/Panorama.vue +29 -0
  27. package/components/controls/Scale.vue +36 -0
  28. package/components/extra/CurveLine.vue +101 -0
  29. package/components/extra/Heatmap.vue +78 -0
  30. package/components/extra/Lushu.vue +125 -0
  31. package/components/extra/MarkerClusterer.vue +93 -0
  32. package/components/index.js +98 -0
  33. package/components/layers/Tile.vue +53 -0
  34. package/components/layers/Traffic.vue +34 -0
  35. package/components/map/Map.vue +287 -0
  36. package/components/map/MapView.vue +9 -0
  37. package/components/others/AutoComplete.vue +70 -0
  38. package/components/others/Boundary.vue +60 -0
  39. package/components/overlays/Circle.vue +170 -0
  40. package/components/overlays/Ground.vue +65 -0
  41. package/components/overlays/Icon.vue +0 -0
  42. package/components/overlays/InfoWindow.vue +137 -0
  43. package/components/overlays/Label.vue +99 -0
  44. package/components/overlays/Marker.vue +163 -0
  45. package/components/overlays/Overlay.vue +55 -0
  46. package/components/overlays/PointCollection.vue +76 -0
  47. package/components/overlays/Polygon.vue +105 -0
  48. package/components/overlays/Polyline.vue +86 -0
  49. package/components/overlays/Symblo.vue +0 -0
  50. package/components/search/Bus.vue +102 -0
  51. package/components/search/Driving.vue +177 -0
  52. package/components/search/LocalSearch.vue +152 -0
  53. package/components/search/Transit.vue +126 -0
  54. package/components/search/Walking.vue +115 -0
  55. package/index.d.ts +3 -0
  56. package/index.js +1 -0
  57. package/karma.conf.js +44 -0
  58. package/package.json +69 -0
  59. package/test/map.js +37 -0
  60. package/test/util/BMap.mock/Map.js +82 -0
  61. package/test/util/BMap.mock/create-class.js +9 -0
  62. package/test/util/BMap.mock/index.js +5 -0
  63. package/test/util/BMap.mock/spy.js +2 -0
  64. package/test/util/util.js +12 -0
  65. package/types/auto-complete.d.ts +21 -0
  66. package/types/base/base-control.d.ts +12 -0
  67. package/types/base/common.d.ts +127 -0
  68. package/types/boundary.d.ts +40 -0
  69. package/types/bus.d.ts +27 -0
  70. package/types/circle.d.ts +46 -0
  71. package/types/city-list.d.ts +3 -0
  72. package/types/control.d.ts +3 -0
  73. package/types/copyright.d.ts +7 -0
  74. package/types/curve-line.d.ts +36 -0
  75. package/types/driving.d.ts +47 -0
  76. package/types/geolocation.d.ts +18 -0
  77. package/types/ground.d.ts +24 -0
  78. package/types/heatmap.d.ts +29 -0
  79. package/types/index.d.ts +93 -0
  80. package/types/info-window.d.ts +51 -0
  81. package/types/item.d.ts +25 -0
  82. package/types/label.d.ts +35 -0
  83. package/types/local-search.d.ts +62 -0
  84. package/types/lushu.d.ts +53 -0
  85. package/types/map-type.d.ts +13 -0
  86. package/types/map-view.d.ts +3 -0
  87. package/types/map.d.ts +87 -0
  88. package/types/marker-clusterer.d.ts +25 -0
  89. package/types/marker.d.ts +78 -0
  90. package/types/menu.d.ts +7 -0
  91. package/types/navigation.d.ts +18 -0
  92. package/types/overlay.d.ts +16 -0
  93. package/types/overview-map.d.ts +14 -0
  94. package/types/panorama.d.ts +3 -0
  95. package/types/point-collection.d.ts +26 -0
  96. package/types/polygon.d.ts +46 -0
  97. package/types/polyline.d.ts +37 -0
  98. package/types/scale.d.ts +3 -0
  99. package/types/tile.d.ts +21 -0
  100. package/types/traffic.d.ts +8 -0
  101. package/types/transit.d.ts +39 -0
  102. package/types/tsconfig.json +17 -0
  103. package/types/walking.d.ts +35 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,22 @@
1
+ module.exports = {
2
+ root: true,
3
+ parser: 'babel-eslint',
4
+ parserOptions: {
5
+ sourceType: 'module'
6
+ },
7
+ // https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
8
+ extends: 'standard',
9
+ // required to lint *.vue files
10
+ plugins: [
11
+ 'html'
12
+ ],
13
+ // add your custom rules here
14
+ 'rules': {
15
+ // allow paren-less arrow functions
16
+ 'arrow-parens': 0,
17
+ // allow async-await
18
+ 'generator-star-spacing': 0,
19
+ // allow debugger during development
20
+ 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
21
+ }
22
+ }
@@ -0,0 +1,7 @@
1
+ <!--
2
+
3
+ 注意:请使用 [ISSUE 生成器](https://dafrok.github.io/vue-baidu-map/#/issues) 创建新 ISSUE,不符合条件的 ISSUE 将被机器人自动关闭!
4
+
5
+ Attention: Please create issues according to [issue generator](https://dafrok.github.io/vue-baidu-map/#/issues), or bot will close it.
6
+
7
+ -->
package/.travis.yml ADDED
@@ -0,0 +1,26 @@
1
+ language: node_js
2
+ node_js:
3
+ - "6.7.0"
4
+ addons:
5
+ apt:
6
+ packages:
7
+ - xvfb
8
+ install:
9
+ - export DISPLAY=':99.0'
10
+ - Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
11
+ - npm install
12
+ branches:
13
+ only: master
14
+ script:
15
+ - npm run lint
16
+ # - npm test
17
+ - npm run build:docs
18
+ after_script:
19
+ - cp ./docs/favicon.png ./dist/
20
+ - cd dist
21
+ - git init
22
+ - git config user.name "Dafrok"
23
+ - git config user.email "o.o@mug.dog"
24
+ - git add .
25
+ - git commit -m "Travis build docs"
26
+ - git push --force --quiet "https://${GITHUB_TOKEN}@github.com/Dafrok/vue-baidu-map.git" master:gh-pages
@@ -0,0 +1,27 @@
1
+ # CONTRIBUTING
2
+
3
+ ## Development
4
+
5
+ ```bash
6
+ # Dev server run at http://locahost:8080
7
+ $ npm i
8
+ $ npm run dev
9
+ ```
10
+
11
+ ## Test
12
+
13
+ ```bash
14
+ $ npm test
15
+ ```
16
+
17
+ ## Build
18
+
19
+ ```
20
+ $ npm run build
21
+ ```
22
+
23
+ ## Build docs
24
+
25
+ ```
26
+ $ npm run build:docs
27
+ ```
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 马金花儿
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # PASS_B_MAP_VUE2
2
+
3
+
4
+ ## 开始
5
+
6
+ ### 安装
7
+
8
+ ```bash
9
+ npm i --save pass_b_map_vue2
10
+ ```
11
+
12
+ ### 初始化
13
+
14
+ ```javascript
15
+ import Vue from 'vue'
16
+ import BaiduMap from 'pass_b_map_vue2'
17
+
18
+ Vue.use(BaiduMap, {
19
+ ak: 'YOUR_KEY'
20
+ })
21
+ ```
22
+
23
+ ### 使用
24
+ ```vue
25
+ <template>
26
+ <baidu-map class="map">
27
+ </baidu-map>
28
+ </template>
29
+
30
+ <style>
31
+ /* 地图容器必须设置宽和高属性 */
32
+ .map {
33
+ width: 400px;
34
+ height: 300px;
35
+ }
36
+ </style>
37
+ ```
38
+
39
+ ## This project is based on vue-baidu-map and is licensed under the MIT License.
40
+
41
+ ## 贡献
42
+
43
+ [贡献指南](https://github.com/Dafrok/vue-baidu-map/blob/master/CONTRIBUTING.md)
44
+
45
+
46
+ ## 协议
47
+
48
+ [MIT 许可证](https://opensource.org/licenses/MIT)
49
+
50
+ 版权所有 (c) 2016至今, Dafrok <o.o@mug.dog>
51
+
52
+
@@ -0,0 +1,127 @@
1
+ /**
2
+ * @file compile & output regular vue component files
3
+ */
4
+ const compiler = require('vue-template-compiler')
5
+ const path = require('path')
6
+ const fs = require('fs')
7
+ const pug = require('pug')
8
+ const babel = require('babel-core')
9
+ const rmdir = require('rmdir')
10
+
11
+ const rootPath = path.resolve(__dirname, '../src')
12
+
13
+ const isArray = Array.isArray
14
+
15
+ function attrsToString (attrs) {
16
+ let ret = ''
17
+ for (const name in attrs) {
18
+ const value = attrs[name]
19
+ if (value === true) {
20
+ ret += `${name} `
21
+ } else if (value) {
22
+ ret += `${name}="${value}" `
23
+ }
24
+ }
25
+ return ret
26
+ }
27
+
28
+ function tagToString (tag) {
29
+ return tag ? `<${tag.type} ${attrsToString(tag.attrs)}>${tag.content}</${tag.type}>` : ''
30
+ }
31
+
32
+ function reverseToComponent (componentObj) {
33
+ let ret = ''
34
+ for (const key in componentObj) {
35
+ const tag = componentObj[key]
36
+ if (isArray(tag)) {
37
+ ret += tag.map(tagToString).join('')
38
+ } else {
39
+ ret += tagToString(tag)
40
+ }
41
+ }
42
+ return ret
43
+ }
44
+
45
+ function transformAlias (content, level) {
46
+ return babel.transform(content, {
47
+ plugins: [
48
+ [
49
+ 'module-alias', [
50
+ {src: '../'.repeat(level), expose: '@'}
51
+ ]
52
+ ]
53
+ ]
54
+ }).code
55
+ }
56
+
57
+ function transformES (content) {
58
+ return babel.transform(content, {
59
+ presets: [
60
+ 'es2015'
61
+ ]
62
+ }).code
63
+ }
64
+
65
+ function walkComponents (rootPath, level = 0, pathName = '.', result = []) {
66
+ const files = fs.readdirSync(rootPath)
67
+ files.forEach(file => {
68
+ const filePath = path.resolve(rootPath, file)
69
+ const extName = path.extname(filePath)
70
+ const isDirectory = fs.lstatSync(filePath).isDirectory()
71
+ if (isDirectory) {
72
+ walkComponents(filePath, level + 1, path.join(pathName, file), result)
73
+ } else if (extName === '.vue') {
74
+ const componentFile = fs.readFileSync(filePath).toString()
75
+ const component = compiler.parseComponent(componentFile)
76
+ const baseName = path.basename(filePath)
77
+ if (component.template) {
78
+ component.template.content = pug.render(component.template.content)
79
+ if (component.template.attrs) {
80
+ component.template.attrs.lang = false
81
+ }
82
+ }
83
+ if (component.script) {
84
+ component.script.content = transformAlias(component.script.content, level)
85
+ }
86
+ result.push({
87
+ content: reverseToComponent(component),
88
+ path: pathName,
89
+ name: baseName
90
+ })
91
+ } else if (extName === '.js') {
92
+ const content = fs.readFileSync(filePath).toString()
93
+ const baseName = path.basename(filePath)
94
+ result.push({
95
+ content: transformES(transformAlias(content, level)),
96
+ path: pathName,
97
+ name: baseName
98
+ })
99
+ }
100
+ })
101
+ return result
102
+ }
103
+
104
+ function mkdirp (filepath) {
105
+ var dirname = path.dirname(filepath)
106
+
107
+ if (!fs.existsSync(dirname)) {
108
+ mkdirp(dirname)
109
+ }
110
+ if (!fs.existsSync(filepath)) {
111
+ fs.mkdirSync(filepath)
112
+ }
113
+ }
114
+
115
+ const compiledFiles = walkComponents(rootPath)
116
+
117
+ const componentDir = path.resolve(__dirname, '../components')
118
+ rmdir(componentDir, () => {
119
+ mkdirp(componentDir)
120
+ compiledFiles.forEach(file => {
121
+ const pathName = path.resolve(componentDir, file.path)
122
+ mkdirp(pathName)
123
+ const fd = fs.openSync(path.resolve(pathName, file.name), 'w')
124
+ fs.writeSync(fd, file.content)
125
+ fs.closeSync(fd)
126
+ })
127
+ })
@@ -0,0 +1,86 @@
1
+ const path = require('path')
2
+ const HtmlWebpackPlugin = require('html-webpack-plugin')
3
+ const InlineManifestWebpackPlugin = require('inline-manifest-webpack-plugin')
4
+ const webpack = require('webpack')
5
+
6
+ module.exports = {
7
+ entry: {
8
+ main: 'docs/main.js',
9
+ libs: [
10
+ 'vue',
11
+ 'vue-router',
12
+ 'prismjs',
13
+ 'vue-material'
14
+ ],
15
+ resource: [
16
+ 'prismjs/themes/prism-tomorrow.css',
17
+ 'docs/fonts/iconfont.css'
18
+ ],
19
+ vendor: [
20
+ 'docs/components/App.vue',
21
+ 'docs/components/CateView.vue',
22
+ 'docs/components/DocPreview.vue',
23
+ 'docs/components/Navigator.vue',
24
+ 'docs/components/RootFrame.vue'
25
+ ]
26
+ },
27
+ output: {
28
+ path: path.resolve(__dirname, '../dist'),
29
+ filename: '[name].[hash:8].bundle.js',
30
+ chunkFilename: '[name].[chunkhash:8].js'
31
+ },
32
+ module: {
33
+ rules: [
34
+ {
35
+ test: /\.vue$/,
36
+ use: ['vue-loader', 'eslint-loader'],
37
+ exclude: [/_cache/]
38
+ },
39
+ {
40
+ test: /\.js$/,
41
+ use: ['babel-loader', 'eslint-loader'],
42
+ exclude: [/node_modules/, /md/]
43
+ },
44
+ {
45
+ test: /\.md$/,
46
+ use: ['vue-markdown-loader'],
47
+ exclude: [/node_modules/]
48
+ },
49
+ {
50
+ test: /\.css$/,
51
+ use: ['style-loader', 'css-loader']
52
+ },
53
+ {
54
+ test: /\.styl$/,
55
+ use: ['style-loader', 'css-loader', 'stylus-loader']
56
+ },
57
+ {
58
+ test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
59
+ use: ['url-loader']
60
+ },
61
+ {
62
+ test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
63
+ use: ['url-loader']
64
+ }
65
+ ]
66
+ },
67
+ resolve: {
68
+ alias: {
69
+ docs: path.resolve(__dirname, '../docs')
70
+ }
71
+ },
72
+ plugins: [
73
+ new webpack.HashedModuleIdsPlugin(),
74
+ new HtmlWebpackPlugin({
75
+ template: path.resolve(__dirname, '../docs/template/index.html'),
76
+ chunks: ['libs', 'vendor', 'resource', 'main']
77
+ }),
78
+ new webpack.optimize.CommonsChunkPlugin({
79
+ names: ['vendor', 'libs', 'resource', 'manifest'],
80
+ minChunks: Infinity
81
+ }),
82
+ new InlineManifestWebpackPlugin({
83
+ name: 'webpackManifest'
84
+ })
85
+ ]
86
+ }
@@ -0,0 +1,24 @@
1
+ const path = require('path')
2
+
3
+ module.exports = {
4
+ entry: './components/index.js',
5
+ output: {
6
+ path: path.resolve(__dirname, './'),
7
+ filename: '../index.js',
8
+ library: 'VueBaiduMap',
9
+ libraryTarget: 'umd'
10
+ },
11
+ module: {
12
+ rules: [
13
+ {
14
+ test: /\.vue$/,
15
+ loader: 'vue-loader'
16
+ },
17
+ {
18
+ test: /\.js$/,
19
+ loader: 'babel-loader',
20
+ exclude: /node_modules/
21
+ }
22
+ ]
23
+ }
24
+ }
@@ -0,0 +1,27 @@
1
+ module.exports = {
2
+ // entry: './src/index.js',
3
+ // output: {
4
+ // path: path.resolve(__dirname, './'),
5
+ // filename: '../index.js',
6
+ // library: 'VueBaiduMap',
7
+ // libraryTarget: 'umd'
8
+ // },
9
+ module: {
10
+ rules: [
11
+ {
12
+ test: /\.vue$/,
13
+ loader: 'vue-loader'
14
+ },
15
+ {
16
+ test: /\.js$/,
17
+ loader: 'babel-loader',
18
+ exclude: /node_modules/
19
+ }
20
+ ]
21
+ },
22
+ resolve: {
23
+ alias: {
24
+ vue: 'vue/dist/vue.js'
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,11 @@
1
+ import events from './events.js'
2
+
3
+ export default function (instance, eventList) {
4
+ const ev = eventList || events[this.$options.name]
5
+ ev && ev.forEach(event => {
6
+ const hasOn = event.slice(0, 2) === 'on'
7
+ const eventName = hasOn ? event.slice(2) : event
8
+ const listener = this.$listeners[eventName]
9
+ listener && instance.addEventListener(event, listener.fns)
10
+ })
11
+ }
@@ -0,0 +1,120 @@
1
+ export default {
2
+ 'bm-map': [
3
+ 'click',
4
+ 'dblclick',
5
+ 'rightclick',
6
+ 'rightdblclick',
7
+ 'maptypechange',
8
+ 'mousemove',
9
+ 'mouseover',
10
+ 'mouseout',
11
+ 'movestart',
12
+ 'moving',
13
+ 'moveend',
14
+ 'zoomstart',
15
+ 'zoomend',
16
+ 'addoverlay',
17
+ 'addcontrol',
18
+ 'removecontrol',
19
+ 'removeoverlay',
20
+ 'clearoverlays',
21
+ 'dragstart',
22
+ 'dragging',
23
+ 'dragend',
24
+ 'addtilelayer',
25
+ 'removetilelayer',
26
+ 'load',
27
+ 'resize',
28
+ 'hotspotclick',
29
+ 'hotspotover',
30
+ 'hotspotout',
31
+ 'tilesloaded',
32
+ 'touchstart',
33
+ 'touchmove',
34
+ 'touchend',
35
+ 'longpress'
36
+ ],
37
+ 'bm-geolocation': [
38
+ 'locationSuccess',
39
+ 'locationError'
40
+ ],
41
+ 'bm-overview-map': [
42
+ 'viewchanged',
43
+ 'viewchanging'
44
+ ],
45
+ 'bm-marker': [
46
+ 'click',
47
+ 'dblclick',
48
+ 'mousedown',
49
+ 'mouseup',
50
+ 'mouseout',
51
+ 'mouseover',
52
+ 'remove',
53
+ 'infowindowclose',
54
+ 'infowindowopen',
55
+ 'dragstart',
56
+ 'dragging',
57
+ 'dragend',
58
+ 'rightclick'
59
+ ],
60
+ 'bm-polyline': [
61
+ 'click',
62
+ 'dblclick',
63
+ 'mousedown',
64
+ 'mouseup',
65
+ 'mouseout',
66
+ 'mouseover',
67
+ 'remove',
68
+ 'lineupdate'
69
+ ],
70
+ 'bm-polygon': [
71
+ 'click',
72
+ 'dblclick',
73
+ 'mousedown',
74
+ 'mouseup',
75
+ 'mouseout',
76
+ 'mouseover',
77
+ 'remove',
78
+ 'lineupdate'
79
+ ],
80
+ 'bm-circle': [
81
+ 'click',
82
+ 'dblclick',
83
+ 'mousedown',
84
+ 'mouseup',
85
+ 'mouseout',
86
+ 'mouseover',
87
+ 'remove',
88
+ 'lineupdate'
89
+ ],
90
+ 'bm-label': [
91
+ 'click',
92
+ 'dblclick',
93
+ 'mousedown',
94
+ 'mouseup',
95
+ 'mouseout',
96
+ 'mouseover',
97
+ 'remove',
98
+ 'rightclick'
99
+ ],
100
+ 'bm-info-window': [
101
+ 'close',
102
+ 'open',
103
+ 'maximize',
104
+ 'restore',
105
+ 'clickclose'
106
+ ],
107
+ 'bm-ground': [
108
+ 'click',
109
+ 'dblclick'
110
+ ],
111
+ 'bm-autocomplete': [
112
+ 'onconfirm',
113
+ 'onhighlight'
114
+ ],
115
+ 'bm-point-collection': [
116
+ 'click',
117
+ 'mouseover',
118
+ 'mouseout'
119
+ ]
120
+ }
@@ -0,0 +1,39 @@
1
+ export function createPoint (BMap, options = {}) {
2
+ const {lng, lat} = options
3
+ return new BMap.Point(lng, lat)
4
+ }
5
+
6
+ export function createPixel (BMap, options = {}) {
7
+ const {x, y} = options
8
+ return new BMap.Pixel(x, y)
9
+ }
10
+
11
+ export function createBounds (BMap, options = {}) {
12
+ const {sw, ne} = options
13
+ return new BMap.Bounds(createPoint(BMap, sw), createPoint(BMap, ne))
14
+ }
15
+
16
+ export function createSize (BMap, options = {}) {
17
+ const {width, height} = options
18
+ return new BMap.Size(width, height)
19
+ }
20
+
21
+ export function createIcon (BMap, options = {}) {
22
+ const {url, size, opts = {}} = options
23
+ return new BMap.Icon(url, createSize(BMap, size), {
24
+ anchor: opts.anchor && createSize(BMap, opts.anchor),
25
+ imageSize: opts.imageSize && createSize(BMap, opts.imageSize),
26
+ imageOffset: opts.imageOffset && createSize(BMap, opts.imageOffset),
27
+ infoWindowAnchor: opts.infoWindowAnchor && createSize(BMap, opts.infoWindowAnchor),
28
+ printImageUrl: opts.printImageUrl
29
+ })
30
+ }
31
+
32
+ export function createLabel (BMap, options = {}) {
33
+ const {content, opts} = options
34
+ return new BMap.Label(content, {
35
+ offset: opts.offset && createSize(BMap, opts.offset),
36
+ position: opts.position && createPoint(BMap, opts.position),
37
+ enableMassClear: opts.enableMassClear
38
+ })
39
+ }
@@ -0,0 +1,13 @@
1
+ class Mixin {
2
+ constructor ({component, props, events, extraProps, exceptProps}) {
3
+ this.render = function (h) {
4
+ return h(component, {
5
+ props: props.reduce((obj, key) => Object.assign(obj, {[key]: this[key]}), {}),
6
+ on: events.reduce((obj, key) => Object.assign(obj, {[key]: this.transmitEvent}), {})
7
+ })
8
+ }
9
+ this.props = [...extraProps, ...props.filter(prop => exceptProps.indexOf(prop))]
10
+ }
11
+ }
12
+
13
+ export default prop => new Mixin(prop)
@@ -0,0 +1,81 @@
1
+ const types = {
2
+ control: {
3
+ unload: 'removeControl'
4
+ },
5
+ layer: {
6
+ unload: 'removeTileLayer'
7
+ },
8
+ overlay: {
9
+ unload: 'removeOverlay'
10
+ },
11
+ contextMenu: {
12
+ unload: 'removeContextMenu'
13
+ }
14
+ }
15
+
16
+ const getParent = $component => ($component.abstract || $component.$el === $component.$children[0].$el) ? getParent($component.$parent) : $component
17
+
18
+ function destroyInstance () {
19
+ const {unload, renderByParent, $parent} = this
20
+ if (renderByParent) {
21
+ $parent.reload()
22
+ }
23
+ unload()
24
+ }
25
+
26
+ class Mixin {
27
+ constructor (prop) {
28
+ this.methods = {
29
+ ready () {
30
+ const $parent = getParent(this.$parent)
31
+ const BMap = this.BMap = $parent.BMap
32
+ const map = this.map = $parent.map
33
+ this.load()
34
+ this.$emit('ready', {
35
+ BMap,
36
+ map
37
+ })
38
+ },
39
+ transmitEvent (e) {
40
+ this.$emit(e.type.replace(/^on/, ''), e)
41
+ },
42
+ reload () {
43
+ this && this.BMap && this.$nextTick(() => {
44
+ this.unload()
45
+ this.$nextTick(this.load)
46
+ })
47
+ },
48
+ unload () {
49
+ const {map, originInstance} = this
50
+ try {
51
+ switch (prop.type) {
52
+ case 'search':
53
+ return originInstance.clearResults()
54
+ case 'autoComplete':
55
+ case 'lushu':
56
+ return originInstance.dispose()
57
+ case 'markerClusterer':
58
+ return originInstance.clearMarkers()
59
+ default:
60
+ map[types[prop.type].unload](originInstance)
61
+ }
62
+ } catch (e) {}
63
+ }
64
+ }
65
+ this.computed = {
66
+ renderByParent () {
67
+ return this.$parent.preventChildrenRender
68
+ }
69
+ }
70
+ this.mounted = function () {
71
+ const $parent = getParent(this.$parent)
72
+ const map = $parent.map
73
+ const {ready} = this
74
+ map ? ready() : $parent.$on('ready', ready)
75
+ }
76
+ this.destroyed = destroyInstance
77
+ this.beforeDestroy = destroyInstance
78
+ }
79
+ }
80
+
81
+ export default type => new Mixin({type})