v-ol-map 1.0.9 → 1.0.10
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/.eslintrc.cjs +29 -0
- package/.vscode/extensions.json +3 -0
- package/index.html +13 -0
- package/package.json +1 -2
- package/src/App.vue +13 -0
- package/src/assets/vue.svg +1 -0
- package/src/components/index.js +13 -0
- package/src/components/index.ts +16 -0
- package/src/components/layers/base.ts +48 -0
- package/src/components/layers/tile/index.js +6 -0
- package/src/components/layers/tile/index.ts +8 -0
- package/src/components/layers/tile/tile.vue +97 -0
- package/src/components/map/index.js +6 -0
- package/src/components/map/index.ts +8 -0
- package/src/components/map/map.vue +91 -0
- package/src/main.js +6 -0
- package/src/main.ts +6 -0
- package/src/style.css +82 -0
- package/src/utils/cityMap.js +2260 -0
- package/src/utils/cityMap.ts +2263 -0
- package/src/utils/index.js +59 -0
- package/src/utils/index.ts +77 -0
- package/src/vite-env.d.ts +7 -0
- package/tsconfig.json +23 -0
- package/tsconfig.node.json +9 -0
- package/vite.config.ts +40 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// ol
|
|
2
|
+
import 'ol/ol.css';
|
|
3
|
+
import { Map, View } from 'ol';
|
|
4
|
+
import { defaults as defaultControls } from 'ol/control';
|
|
5
|
+
import { defaults as defaultInteractions } from 'ol/interaction';
|
|
6
|
+
// utils
|
|
7
|
+
import { getCenterByCity } from '@/utils/cityMap';
|
|
8
|
+
// functions
|
|
9
|
+
/**
|
|
10
|
+
* 判断某key是否在对象内
|
|
11
|
+
* @param obj
|
|
12
|
+
* @param key
|
|
13
|
+
*/
|
|
14
|
+
export const validObjKey = (obj, key) => {
|
|
15
|
+
if (obj && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
16
|
+
return (obj[key] &&
|
|
17
|
+
(Object.keys(obj[key]).length > 0 || typeof obj[key] === 'function'));
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
export class OlMap {
|
|
24
|
+
static map = OlMap;
|
|
25
|
+
constructor(options) {
|
|
26
|
+
console.log(options);
|
|
27
|
+
// view
|
|
28
|
+
const viewOptDefault = {
|
|
29
|
+
center: [108.5525, 34.3227],
|
|
30
|
+
zoom: 5,
|
|
31
|
+
constrainResolution: true,
|
|
32
|
+
projection: 'EPSG:4326'
|
|
33
|
+
};
|
|
34
|
+
const viewOption = { ...viewOptDefault, ...options.view };
|
|
35
|
+
if (validObjKey(viewOption, 'city') && viewOption.city) {
|
|
36
|
+
viewOption.center =
|
|
37
|
+
getCenterByCity(viewOption.city) ||
|
|
38
|
+
viewOption.center ||
|
|
39
|
+
viewOptDefault.center;
|
|
40
|
+
}
|
|
41
|
+
const view = new View(viewOption);
|
|
42
|
+
// controls
|
|
43
|
+
console.log(options.controls);
|
|
44
|
+
const controlsDefault = {
|
|
45
|
+
zoom: false,
|
|
46
|
+
rotate: false,
|
|
47
|
+
attribution: false
|
|
48
|
+
};
|
|
49
|
+
const controlsOption = { ...controlsDefault, ...options.controls };
|
|
50
|
+
const controls = defaultControls(controlsOption).extend([]);
|
|
51
|
+
return new Map({
|
|
52
|
+
interactions: defaultInteractions(options.interaction).extend([]),
|
|
53
|
+
target: options.target,
|
|
54
|
+
view,
|
|
55
|
+
controls
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// ol
|
|
2
|
+
import 'ol/ol.css'
|
|
3
|
+
import { Map, View } from 'ol'
|
|
4
|
+
import { ViewOptions } from 'ol/View'
|
|
5
|
+
import {
|
|
6
|
+
defaults as defaultControls,
|
|
7
|
+
DefaultsOptions as ControlOptions
|
|
8
|
+
} from 'ol/control'
|
|
9
|
+
import {
|
|
10
|
+
defaults as defaultInteractions,
|
|
11
|
+
DefaultsOptions as InteractionOptions
|
|
12
|
+
} from 'ol/interaction'
|
|
13
|
+
// utils
|
|
14
|
+
import { getCenterByCity } from '@/utils/cityMap'
|
|
15
|
+
// interface
|
|
16
|
+
interface customerViewOptions extends ViewOptions {
|
|
17
|
+
city: string;
|
|
18
|
+
}
|
|
19
|
+
export interface MapOptions {
|
|
20
|
+
target: string;
|
|
21
|
+
view: customerViewOptions;
|
|
22
|
+
controls: ControlOptions;
|
|
23
|
+
interaction: InteractionOptions;
|
|
24
|
+
}
|
|
25
|
+
// functions
|
|
26
|
+
/**
|
|
27
|
+
* 判断某key是否在对象内
|
|
28
|
+
* @param obj
|
|
29
|
+
* @param key
|
|
30
|
+
*/
|
|
31
|
+
export const validObjKey = (obj: any, key: string) => {
|
|
32
|
+
if (obj && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
33
|
+
return (
|
|
34
|
+
obj[key] &&
|
|
35
|
+
(Object.keys(obj[key]).length > 0 || typeof obj[key] === 'function')
|
|
36
|
+
)
|
|
37
|
+
} else {
|
|
38
|
+
return false
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class OlMap {
|
|
43
|
+
static map = OlMap
|
|
44
|
+
constructor (options: MapOptions) {
|
|
45
|
+
console.log(options)
|
|
46
|
+
// view
|
|
47
|
+
const viewOptDefault = {
|
|
48
|
+
center: [108.5525, 34.3227],
|
|
49
|
+
zoom: 5,
|
|
50
|
+
constrainResolution: true,
|
|
51
|
+
projection: 'EPSG:4326'
|
|
52
|
+
}
|
|
53
|
+
const viewOption = { ...viewOptDefault, ...options.view }
|
|
54
|
+
if (validObjKey(viewOption, 'city') && viewOption.city) {
|
|
55
|
+
viewOption.center =
|
|
56
|
+
getCenterByCity(viewOption.city) ||
|
|
57
|
+
viewOption.center ||
|
|
58
|
+
viewOptDefault.center
|
|
59
|
+
}
|
|
60
|
+
const view = new View(viewOption)
|
|
61
|
+
// controls
|
|
62
|
+
console.log(options.controls)
|
|
63
|
+
const controlsDefault = {
|
|
64
|
+
zoom: false,
|
|
65
|
+
rotate: false,
|
|
66
|
+
attribution: false
|
|
67
|
+
}
|
|
68
|
+
const controlsOption = { ...controlsDefault, ...options.controls }
|
|
69
|
+
const controls = defaultControls(controlsOption).extend([])
|
|
70
|
+
return new Map({
|
|
71
|
+
interactions: defaultInteractions(options.interaction).extend([]),
|
|
72
|
+
target: options.target,
|
|
73
|
+
view,
|
|
74
|
+
controls
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": "./",
|
|
4
|
+
"paths": {
|
|
5
|
+
"@/*": ["src/*"]
|
|
6
|
+
},
|
|
7
|
+
"target": "ESNext",
|
|
8
|
+
"useDefineForClassFields": true,
|
|
9
|
+
"module": "ESNext",
|
|
10
|
+
"moduleResolution": "Node",
|
|
11
|
+
"strict": true,
|
|
12
|
+
"jsx": "preserve",
|
|
13
|
+
"sourceMap": true,
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"isolatedModules": true,
|
|
16
|
+
"esModuleInterop": true,
|
|
17
|
+
"lib": ["ESNext", "DOM"],
|
|
18
|
+
"skipLibCheck": true
|
|
19
|
+
},
|
|
20
|
+
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
|
|
21
|
+
"exclude": ["node_modules"],
|
|
22
|
+
"references": [{ "path": "./tsconfig.node.json" }]
|
|
23
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { resolve } from 'path'
|
|
2
|
+
import { defineConfig } from 'vite'
|
|
3
|
+
// import eslintPlugin from 'vite-plugin-eslint'
|
|
4
|
+
import vue from '@vitejs/plugin-vue'
|
|
5
|
+
|
|
6
|
+
// https://vitejs.dev/config/
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
server: {
|
|
9
|
+
host: 'localhost',
|
|
10
|
+
port: 8080,
|
|
11
|
+
open: true
|
|
12
|
+
},
|
|
13
|
+
plugins: [
|
|
14
|
+
vue()
|
|
15
|
+
// eslintPlugin({
|
|
16
|
+
// include: ['src/**/*.js', 'src/**/*.vue', 'src/**/*.jsx', 'src/**/*.ts'],
|
|
17
|
+
// cache: false
|
|
18
|
+
// })
|
|
19
|
+
],
|
|
20
|
+
resolve: {
|
|
21
|
+
alias: {
|
|
22
|
+
'@': resolve(__dirname, 'src')
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
build: {
|
|
26
|
+
lib: {
|
|
27
|
+
entry: resolve(__dirname, 'src/components/index.ts'),
|
|
28
|
+
name: 'ol-map',
|
|
29
|
+
fileName: (format) => `ol-map.${format}.js`
|
|
30
|
+
},
|
|
31
|
+
rollupOptions: {
|
|
32
|
+
external: ['vue'],
|
|
33
|
+
output: {
|
|
34
|
+
globals: {
|
|
35
|
+
vue: 'Vue'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
})
|