tdt-map-vue 1.0.3 → 1.0.5

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 (2) hide show
  1. package/README.md +151 -37
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -111,10 +111,160 @@ export default {
111
111
  - `getAllMarkers()`:获取全部标注
112
112
  - `setCenterAndZoom(center, zoom)`:设置地图中心点和缩放级别
113
113
  - `getMapLngLat()`:获取当前拾取到的坐标点
114
- - `getLngLat(lnglat)`:由坐标拾取回调写入当前坐标
115
114
  - `destroyMap()`:销毁地图
116
115
  - `resizeMap()`:重新计算地图尺寸
117
116
 
117
+ ### 方法使用示例
118
+
119
+ 下面给出几个最常用的方法调用示例,方便父组件通过 `ref` 直接控制地图。
120
+
121
+ #### 1. 新增标注 `addMarkers(markers)`
122
+
123
+ `markers` 参数是一个数组,每一项的格式如下:
124
+
125
+ ```js
126
+ [
127
+ {
128
+ id: "marker-1",
129
+ lng: 116.397428,
130
+ lat: 39.90923,
131
+ option: {
132
+ content: "<div>北京</div>",
133
+ iconInfo: {
134
+ icon: "https://example.com/icon.png",
135
+ offsetX: 32,
136
+ offsetY: 32,
137
+ },
138
+ textInfo: {
139
+ text: "北京",
140
+ offsetX: 0,
141
+ offsetY: -30,
142
+ },
143
+ },
144
+ },
145
+ ]
146
+ ```
147
+
148
+ Vue 3 调用示例:
149
+
150
+ ```vue
151
+ <template>
152
+ <div>
153
+ <TiandiMap ref="mapRef" tk="your-tianditu-api-key" />
154
+ <button @click="addMarker">新增标注</button>
155
+ </div>
156
+ </template>
157
+
158
+ <script setup>
159
+ import { ref } from "vue";
160
+ import TiandiMap from "tdt-map-vue";
161
+
162
+ const mapRef = ref(null);
163
+
164
+ const addMarker = () => {
165
+ mapRef.value?.addMarkers([
166
+ {
167
+ id: "marker-1",
168
+ lng: 116.397428,
169
+ lat: 39.90923,
170
+ option: {
171
+ content: "<div>北京</div>",
172
+ },
173
+ },
174
+ ]);
175
+ };
176
+ </script>
177
+ ```
178
+
179
+
180
+ #### 2 设置中心点 `setCenterAndZoom(center, zoom)`
181
+
182
+ - `center`:数组,格式为 `[lng, lat]`
183
+ - `zoom`:缩放级别,类型为 `number`
184
+
185
+ ```vue
186
+ <template>
187
+ <div>
188
+ <TiandiMap ref="mapRef" tk="your-tianditu-api-key" />
189
+ <button @click="goToCity">定位到城市</button>
190
+ </div>
191
+ </template>
192
+
193
+ <script setup>
194
+ import { ref } from "vue";
195
+ import TiandiMap from "tdt-map-vue";
196
+
197
+ const mapRef = ref(null);
198
+
199
+ const goToCity = () => {
200
+ mapRef.value?.setCenterAndZoom([117.017362, 25.075884], 12);
201
+ };
202
+ </script>
203
+ ```
204
+
205
+ #### 3 获取拾取坐标 `getMapLngLat()`
206
+
207
+ `getMapLngLat()` 没有入参,返回值为当前拾取到的坐标对象,格式如下:
208
+
209
+ ```js
210
+ {
211
+ lng: 117.017362,
212
+ lat: 25.075884
213
+ }
214
+ ```
215
+
216
+ ```vue
217
+ <template>
218
+ <div>
219
+ <TiandiMap ref="mapRef" tk="your-tianditu-api-key" />
220
+ <button @click="getPickedPoint">获取拾取坐标</button>
221
+ </div>
222
+ </template>
223
+
224
+ <script setup>
225
+ import { ref } from "vue";
226
+ import TiandiMap from "tdt-map-vue";
227
+
228
+ const mapRef = ref(null);
229
+
230
+ const getPickedPoint = () => {
231
+ const point = mapRef.value?.getMapLngLat();
232
+ console.log("当前拾取坐标:", point);
233
+ };
234
+ </script>
235
+ ```
236
+
237
+ #### 4 隐藏标注 `hideMarkers(markers)`
238
+
239
+ `markers` 参数是一个数组,通常只需要传入要隐藏标注的 `id`。
240
+
241
+ ```js
242
+ [
243
+ { id: "marker-1" },
244
+ { id: "marker-2" },
245
+ ]
246
+ ```
247
+
248
+ ```vue
249
+ <template>
250
+ <div>
251
+ <TiandiMap ref="mapRef" tk="your-tianditu-api-key" />
252
+ <button @click="hideMarker">隐藏标注</button>
253
+ </div>
254
+ </template>
255
+
256
+ <script setup>
257
+ import { ref } from "vue";
258
+ import TiandiMap from "tdt-map-vue";
259
+
260
+ const mapRef = ref(null);
261
+
262
+ const hideMarker = () => {
263
+ mapRef.value?.hideMarkers([{ id: "marker-1" }]);
264
+ };
265
+ </script>
266
+ ```
267
+
118
268
  ### Vue 3 示例
119
269
 
120
270
  ```vue
@@ -231,42 +381,6 @@ export default {
231
381
 
232
382
  `map` 是天地图的地图实例,可以直接拿来调用原生 API。
233
383
 
234
- ### 坐标拾取说明
235
-
236
- 组件内部已经集成了坐标拾取能力:
237
-
238
- - 地图初始化时会创建 `CoordinatePickup`
239
- - 拾取到的坐标会写入组件内部状态
240
- - 父组件可以通过 `ref` 调用 `getMapLngLat()` 获取当前拾取结果
241
-
242
- 如果你需要在业务里做“点击地图获取坐标”的功能,可以在父组件中通过 `ref` 读取当前坐标,并结合自己的表单或标注逻辑进行处理。
243
-
244
- ## 标注数据格式
245
-
246
- 标注数据建议统一使用数组结构传入,每一项都可以包含坐标、唯一标识和扩展配置。`option` 中支持图标、文字标签和弹窗内容,因此既能展示基础点位,也能满足更复杂的业务展示需求。
247
-
248
- ```js
249
- [
250
- {
251
- id: "marker-1",
252
- lng: 116.397428,
253
- lat: 39.90923,
254
- option: {
255
- iconInfo: {
256
- icon: "https://example.com/icon.png",
257
- offsetX: 32,
258
- offsetY: 32,
259
- },
260
- content: "<div>北京市中心</div>",
261
- textInfo: {
262
- text: "北京",
263
- offsetX: 0,
264
- offsetY: -30,
265
- },
266
- },
267
- },
268
- ];
269
- ```
270
384
 
271
385
  ## 使用建议
272
386
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tdt-map-vue",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "基于 Vue 2/3 的天地图二次封装组件,提供地图初始化、标注管理、地理编码搜索和常用实例方法调用能力。",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.es.js",