my-openlayer 2.4.8 → 2.4.9

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/docs/index.md CHANGED
@@ -1,78 +1,78 @@
1
- # My OpenLayers
2
-
3
- My OpenLayers 是一个基于 OpenLayers 的轻量级地图封装库,旨在简化地图开发流程,提供开箱即用的常用功能。它集成了点、线、面绘制,测量工具,选择交互,Vue 组件覆盖物等功能,特别优化了 Vue 项目的集成体验。
4
-
5
- ## 特性
6
-
7
- - **开箱即用**: 封装了常用的地图功能,减少样板代码。
8
- - **Vue 集成**: 支持使用 Vue 组件作为地图覆盖物,轻松创建复杂的交互式标记。
9
- - **TypeScript**: 完全使用 TypeScript 编写,提供完整的类型定义。
10
- - **工具丰富**: 内置测量、选择、裁剪、遮罩等实用工具。
11
- - **扩展性强**: 提供基础类和接口,方便二次封装和扩展。
12
-
13
- ## 安装
14
-
15
- ```bash
16
- npm install my-openlayer
17
- # 或者
18
- yarn add my-openlayer
19
- # 或者
20
- pnpm add my-openlayer
21
- ```
22
-
23
- ## 快速开始
24
-
25
- ```typescript
26
- import { MyOl } from 'my-openlayer';
27
- import 'ol/ol.css'; // 引入 OpenLayers 样式
28
-
29
- // 初始化地图
30
- const map = new MyOl('map-container', {
31
- center: [120.2, 30.3],
32
- zoom: 12,
33
- projection: 'EPSG:4326'
34
- });
35
-
36
- // 获取原生 Map 实例
37
- const olMap = map.map;
38
-
39
- // 添加一个点
40
- const point = map.getPoint();
41
- point.addPoint([{
42
- lgtd: 120.2,
43
- lttd: 30.3,
44
- style: {
45
- icon: 'path/to/icon.png'
46
- }
47
- }]);
48
- ```
49
-
50
- ## 核心模块
51
-
52
- - **[MyOl](./MyOl.md)**: 核心入口类,负责地图初始化和模块管理。
53
- - **[Point](./Point.md)**: 点位管理,支持图标、文本、聚合等。
54
- - **[Line](./Line.md)**: 线条绘制,支持不同样式和动画。
55
- - **[Polygon](./Polygon.md)**: 多边形绘制,支持遮罩、热力图等。
56
- - **[VueTemplatePoint](./VueTemplatePoint.md)**: 使用 Vue 组件作为地图点位覆盖物。
57
-
58
- ## 工具模块
59
-
60
- - **[MapTools](./MapTools.md)**: 通用地图工具,如裁剪、定位、导出图片等。
61
- - **[MeasureHandler](./MeasureHandler.md)**: 距离和面积测量工具。
62
- - **[SelectHandler](./SelectHandler.md)**: 要素选择交互工具。
63
- - **[MapBaseLayers](./MapBaseLayers.md)**: 底图切换和管理。
64
-
65
- ## 基础设施
66
-
67
- - **[ConfigManager](./ConfigManager.md)**: 全局配置管理。
68
- - **[EventManager](./EventManager.md)**: 统一事件管理系统。
69
- - **[ErrorHandler](./ErrorHandler.md)**: 错误处理和日志系统。
70
- - **[ValidationUtils](./ValidationUtils.md)**: 参数验证工具。
71
-
72
- ## 贡献
73
-
74
- 欢迎提交 Issue 和 Pull Request!
75
-
76
- ## 许可证
77
-
78
- MIT License
1
+ # My OpenLayers
2
+
3
+ My OpenLayers 是一个基于 OpenLayers 的轻量级地图封装库,旨在简化地图开发流程,提供开箱即用的常用功能。它集成了点、线、面绘制,测量工具,选择交互,Vue 组件覆盖物等功能,特别优化了 Vue 项目的集成体验。
4
+
5
+ ## 特性
6
+
7
+ - **开箱即用**: 封装了常用的地图功能,减少样板代码。
8
+ - **Vue 集成**: 支持使用 Vue 组件作为地图覆盖物,轻松创建复杂的交互式标记。
9
+ - **TypeScript**: 完全使用 TypeScript 编写,提供完整的类型定义。
10
+ - **工具丰富**: 内置测量、选择、裁剪、遮罩等实用工具。
11
+ - **扩展性强**: 提供基础类和接口,方便二次封装和扩展。
12
+
13
+ ## 安装
14
+
15
+ ```bash
16
+ npm install my-openlayer
17
+ # 或者
18
+ yarn add my-openlayer
19
+ # 或者
20
+ pnpm add my-openlayer
21
+ ```
22
+
23
+ ## 快速开始
24
+
25
+ ```typescript
26
+ import { MyOl } from 'my-openlayer';
27
+ import 'ol/ol.css'; // 引入 OpenLayers 样式
28
+
29
+ // 初始化地图
30
+ const map = new MyOl('map-container', {
31
+ center: [120.2, 30.3],
32
+ zoom: 12,
33
+ projection: 'EPSG:4326'
34
+ });
35
+
36
+ // 获取原生 Map 实例
37
+ const olMap = map.map;
38
+
39
+ // 添加一个点
40
+ const point = map.getPoint();
41
+ point.addPoint([{
42
+ lgtd: 120.2,
43
+ lttd: 30.3,
44
+ style: {
45
+ icon: 'path/to/icon.png'
46
+ }
47
+ }]);
48
+ ```
49
+
50
+ ## 核心模块
51
+
52
+ - **[MyOl](./MyOl.md)**: 核心入口类,负责地图初始化和模块管理。
53
+ - **[Point](./Point.md)**: 点位管理,支持图标、文本、聚合等。
54
+ - **[Line](./Line.md)**: 线条绘制,支持不同样式和动画。
55
+ - **[Polygon](./Polygon.md)**: 多边形绘制,支持遮罩、热力图等。
56
+ - **[VueTemplatePoint](./VueTemplatePoint.md)**: 使用 Vue 组件作为地图点位覆盖物。
57
+
58
+ ## 工具模块
59
+
60
+ - **[MapTools](./MapTools.md)**: 通用地图工具,如裁剪、定位、导出图片等。
61
+ - **[MeasureHandler](./MeasureHandler.md)**: 距离和面积测量工具。
62
+ - **[SelectHandler](./SelectHandler.md)**: 要素选择交互工具。
63
+ - **[MapBaseLayers](./MapBaseLayers.md)**: 底图切换和管理。
64
+
65
+ ## 基础设施
66
+
67
+ - **[ConfigManager](./ConfigManager.md)**: 全局配置管理。
68
+ - **[EventManager](./EventManager.md)**: 统一事件管理系统。
69
+ - **[ErrorHandler](./ErrorHandler.md)**: 错误处理和日志系统。
70
+ - **[ValidationUtils](./ValidationUtils.md)**: 参数验证工具。
71
+
72
+ ## 贡献
73
+
74
+ 欢迎提交 Issue 和 Pull Request!
75
+
76
+ ## 许可证
77
+
78
+ MIT License
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "my-openlayer",
3
3
  "private": false,
4
- "version": "2.4.8",
4
+ "version": "2.4.9",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "main": "index.js",
@@ -26,7 +26,6 @@
26
26
  "LICENSE",
27
27
  "README.md",
28
28
  "CHANGELOG.md",
29
- "AI_CONTEXT.md",
30
29
  "docs",
31
30
  "package.json"
32
31
  ],
package/types.d.ts CHANGED
@@ -236,6 +236,8 @@ export interface ClusterOptions extends PointOptions {
236
236
  */
237
237
  export interface TwinkleItem extends PointData {
238
238
  className?: string;
239
+ /** 自定义DOM元素,可以是HTMLElement或者返回HTMLElement的函数 */
240
+ element?: HTMLElement | ((item: TwinkleItem) => HTMLElement);
239
241
  [key: string]: any;
240
242
  }
241
243
  /**
package/AI_CONTEXT.md DELETED
@@ -1,147 +0,0 @@
1
- # AI Context for my-openlayer
2
-
3
- Use this context to understand how to use the `my-openlayer` library.
4
-
5
- ## Project Overview
6
-
7
- `my-openlayer` is a modern map component library based on OpenLayers, designed for Web GIS applications. It provides a modular, TypeScript-ready wrapper around OpenLayers features.
8
-
9
- - **Core Dependency**: `ol` (OpenLayers)
10
- - **Key Features**: Map initialization, Tianditu (天地图) support, Point/Line/Polygon management, Event handling, Selection, Measurement, Vue component markers.
11
-
12
- ## Core Architecture
13
-
14
- - **MyOl**: The main entry class. Initializes the map and provides access to sub-modules.
15
- - **Modules** (Lazy loaded via getters):
16
- - `MapBaseLayers`: Base map switching (Vector, Image, Terrain) and Annotation layers.
17
- - `Point`: Point features, clusters, DOM markers.
18
- - `Line`: Line features, river layers.
19
- - `Polygon`: Polygon features, heatmaps, image layers, masks.
20
- - `MapTools`: General tools (Zoom, Fit, Layer management).
21
- - `MeasureHandler`: Distance and Area measurement.
22
- - `SelectHandler`: Feature selection interaction.
23
- - `EventManager`: Unified event listener management.
24
- - **Utils**: `ConfigManager`, `ErrorHandler`, `ValidationUtils`.
25
-
26
- ## Quick Start (Minimal Example)
27
-
28
- ```typescript
29
- import MyOl, { MapInitType } from 'my-openlayer';
30
-
31
- // 1. Configuration
32
- const config: MapInitType = {
33
- target: 'map-container', // ID of the DIV
34
- center: [119.81, 29.969], // [Longitude, Latitude]
35
- zoom: 10,
36
- token: 'YOUR_TIANDITU_TOKEN', // Required for Tianditu base maps
37
- annotation: true // Show annotation layer by default
38
- };
39
-
40
- // 2. Initialize
41
- const map = new MyOl('map-container', config);
42
-
43
- // 3. Access Modules & Add Features
44
- map.getPoint().addPoint([{ lgtd: 119.81, lttd: 29.969, name: 'Demo' }], {
45
- layerName: 'demo-layer',
46
- img: 'marker.png'
47
- });
48
- ```
49
-
50
- ## API Reference (Condensed)
51
-
52
- ### `MyOl` (Main Class)
53
- - `constructor(id: string | HTMLElement, options?: MapInitType)`
54
- - `getPoint()`: Returns `Point` instance.
55
- - `getLine()`: Returns `Line` instance.
56
- - `getPolygon()`: Returns `Polygon` instance.
57
- - `getMapBaseLayers()`: Returns `MapBaseLayers` instance.
58
- - `getTools()`: Returns `MapTools` instance.
59
- - `getSelectHandler()`: Returns `SelectHandler` instance.
60
- - `getEventManager()`: Returns `EventManager` instance.
61
- - `locationAction(lon, lat, zoom, duration)`: Animate to location.
62
-
63
- ### `MapBaseLayers`
64
- - `switchBaseLayer(type: 'vec_c' | 'img_c' | 'ter_c')`: Switch base map.
65
- - `setAnnotationVisible(visible: boolean)`: Toggle text annotations.
66
- - `addGeoServerLayer(url, layerName, options)`: Add WMS layer.
67
-
68
- ### `Point`
69
- - `addPoint(data: PointData[], options: PointOptions)`: Add markers.
70
- - `addClusterPoint(data, options)`: Add clustered markers.
71
- - `addVueTemplatePoint(data, Component, options)`: Use Vue component as marker.
72
-
73
- ### `Line`
74
- - `addLine(geoJson, options)`: Add lines from GeoJSON.
75
- - `addLineByUrl(url, options)`: Load GeoJSON from URL.
76
-
77
- ### `Polygon`
78
- - `addPolygon(geoJson, options)`: Add polygons.
79
- - `addBorderPolygon(geoJson, options)`: Add boundary lines.
80
- - `updateFeatureColor(layerName, colorMap, options)`: Update colors dynamically.
81
- - `addHeatmap(data, options)`: Add heatmap.
82
-
83
- ### `SelectHandler`
84
- - `enableSelect(mode: 'click'|'hover', options)`: Enable selection.
85
- - `selectByIds(ids, options)`: Programmatic selection.
86
-
87
- ### `MeasureHandler`
88
- - **Important**: Must be instantiated manually if not exposed via `MyOl`.
89
- - `new MeasureHandler(map.map)`
90
- - `start('LineString' | 'Polygon')`
91
- - `end()`, `clean()`
92
-
93
- ## Key Type Definitions (TypeScript)
94
-
95
- Use these interfaces to ensure type safety.
96
-
97
- ```typescript
98
- export interface MapInitType {
99
- layers?: LayerItem[] | { [key: string]: LayerItem[] };
100
- zoom?: number;
101
- center?: number[]; // [lon, lat]
102
- minZoom?: number;
103
- maxZoom?: number;
104
- token?: string; // Tianditu Token
105
- annotation?: boolean;
106
- }
107
-
108
- export interface BaseOptions {
109
- layerName?: string;
110
- zIndex?: number;
111
- visible?: boolean;
112
- opacity?: number;
113
- }
114
-
115
- export interface PointOptions extends BaseOptions {
116
- textKey?: string; // Property key for label text
117
- img?: string; // Icon URL
118
- scale?: number;
119
- textFillColor?: string;
120
- }
121
-
122
- export interface PointData {
123
- lgtd: number;
124
- lttd: number;
125
- [key: string]: any;
126
- }
127
-
128
- export interface LineOptions extends BaseOptions {
129
- strokeColor?: string;
130
- strokeWidth?: number;
131
- lineDash?: number[];
132
- }
133
-
134
- export interface PolygonOptions extends BaseOptions {
135
- fillColor?: string;
136
- strokeColor?: string;
137
- textKey?: string;
138
- }
139
- ```
140
-
141
- ## Best Practices
142
-
143
- 1. **Use Modules**: Access functionality through `map.getPoint()`, `map.getLine()`, etc., rather than manipulating the `ol.Map` directly when possible.
144
- 2. **Layer Names**: Always provide a unique `layerName` in options to easily retrieve or remove layers later (`map.getTools().removeLayer('my-layer')`).
145
- 3. **Coordinate System**: The library defaults to `EPSG:4326` (WGS84) for input coordinates (lon/lat) and `CGCS2000` internally where applicable.
146
- 4. **Vue Integration**: Use `addVueTemplatePoint` for complex markers requiring interactivity or dynamic content.
147
- 5. **Event Handling**: Use `map.getEventManager().on('click', ...)` instead of native listeners for better management.