提交 de8bd5b5 编写于 作者: D DCloud_LXH

chore(App): Map

上级 cfcd3324
...@@ -24,7 +24,7 @@ const operateMapWrap = ( ...@@ -24,7 +24,7 @@ const operateMapWrap = (
id: string, id: string,
pageId: number, pageId: number,
type: string, type: string,
options?: Data options?: any
) => { ) => {
operateMap(id, pageId, type, options, (res) => { operateMap(id, pageId, type, options, (res) => {
options && operateMapCallback(options, res) options && operateMapCallback(options, res)
...@@ -41,8 +41,9 @@ export class MapContext implements UniApp.MapContext { ...@@ -41,8 +41,9 @@ export class MapContext implements UniApp.MapContext {
getCenterLocation(options: any) { getCenterLocation(options: any) {
operateMapWrap(this.id, this.pageId, 'getCenterLocation', options) operateMapWrap(this.id, this.pageId, 'getCenterLocation', options)
} }
moveToLocation() { // @ts-expect-error
operateMapWrap(this.id, this.pageId, 'moveToLocation') moveToLocation(options: any) {
operateMapWrap(this.id, this.pageId, 'moveToLocation', options)
} }
getScale(options: any) { getScale(options: any) {
operateMapWrap(this.id, this.pageId, 'getScale', options) operateMapWrap(this.id, this.pageId, 'getScale', options)
...@@ -73,6 +74,7 @@ export class MapContext implements UniApp.MapContext { ...@@ -73,6 +74,7 @@ export class MapContext implements UniApp.MapContext {
openMapApp() {} openMapApp() {}
} }
// @ts-expect-error
export const createMapContext = <API_TYPE_CREATE_MAP_CONTEXT>defineSyncApi( export const createMapContext = <API_TYPE_CREATE_MAP_CONTEXT>defineSyncApi(
API_CREATE_MAP_CONTEXT, API_CREATE_MAP_CONTEXT,
(id, context) => { (id, context) => {
......
...@@ -18,6 +18,7 @@ import { ...@@ -18,6 +18,7 @@ import {
import { useNativeAttrs, useNative } from '../../../helpers/useNative' import { useNativeAttrs, useNative } from '../../../helpers/useNative'
import { getCurrentPageId } from '@dcloudio/uni-core' import { getCurrentPageId } from '@dcloudio/uni-core'
import { getRealPath } from '../../../platform/getRealPath' import { getRealPath } from '../../../platform/getRealPath'
import CoverImage from '../cover-image'
interface Coordinate { interface Coordinate {
latitude: number latitude: number
...@@ -83,7 +84,6 @@ type Control = { ...@@ -83,7 +84,6 @@ type Control = {
} }
interface Map extends PlusMapsMap { interface Map extends PlusMapsMap {
__markers__: Markers __markers__: Markers
__markers_map__: Record<string, PlusMapsMarker>
__lines__: Lines __lines__: Lines
__circles__: Circles __circles__: Circles
} }
...@@ -152,11 +152,24 @@ export default /*#__PURE__*/ defineBuiltInComponent({ ...@@ -152,11 +152,24 @@ export default /*#__PURE__*/ defineBuiltInComponent({
map = extend( map = extend(
plus.maps.create( plus.maps.create(
getCurrentPageId() + '-map-' + (props.id || Date.now()), getCurrentPageId() + '-map-' + (props.id || Date.now()),
Object.assign({}, attrs.value, position) Object.assign(
{},
attrs.value,
position,
(() => {
if (props.latitude && props.longitude) {
return {
center: new plus.maps.Point!(
Number(props.longitude),
Number(props.latitude)
),
}
}
})()
)
), ),
{ {
__markers__: [], __markers__: [],
__markers_map__: {},
__lines__: [], __lines__: [],
__circles__: [], __circles__: [],
} }
...@@ -187,12 +200,9 @@ export default /*#__PURE__*/ defineBuiltInComponent({ ...@@ -187,12 +200,9 @@ export default /*#__PURE__*/ defineBuiltInComponent({
(position) => map && map.setStyles(position), (position) => map && map.setStyles(position),
{ deep: true } { deep: true }
) )
watch( watch(hidden, (val) => {
() => hidden.value, map && map[val ? 'hide' : 'show']()
(val) => { })
map && map[val ? 'hide' : 'show']()
}
)
watch( watch(
() => props.scale, () => props.scale,
(val) => { (val) => {
...@@ -212,19 +222,22 @@ export default /*#__PURE__*/ defineBuiltInComponent({ ...@@ -212,19 +222,22 @@ export default /*#__PURE__*/ defineBuiltInComponent({
() => props.markers, () => props.markers,
(val) => { (val) => {
_addMarkers(val as Markers, true) _addMarkers(val as Markers, true)
} },
{ deep: true }
) )
watch( watch(
() => props.polyline, () => props.polyline,
(val) => { (val) => {
_addMapLines(val as Lines) _addMapLines(val as Lines)
} },
{ deep: true }
) )
watch( watch(
() => props.circles, () => props.circles,
(val) => { (val) => {
_addMapCircles(val as Circles) _addMapCircles(val as Circles)
} },
{ deep: true }
) )
}) })
...@@ -240,6 +253,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({ ...@@ -240,6 +253,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({
id: control.id, id: control.id,
iconPath: getRealPath(control.iconPath), iconPath: getRealPath(control.iconPath),
position: position, position: position,
clickable: control.clickable,
} }
}) })
) )
...@@ -256,12 +270,14 @@ export default /*#__PURE__*/ defineBuiltInComponent({ ...@@ -256,12 +270,14 @@ export default /*#__PURE__*/ defineBuiltInComponent({
<uni-map ref={rootRef} id={props.id}> <uni-map ref={rootRef} id={props.id}>
<div ref={containerRef} class="uni-map-container" /> <div ref={containerRef} class="uni-map-container" />
{mapControls.value.map((control, index) => ( {mapControls.value.map((control, index) => (
<v-uni-cover-image <CoverImage
key={index} key={index}
src={control.iconPath} src={control.iconPath}
style={control.position} style={control.position}
auto-size auto-size
// @ts-expect-error
onClick={() => onClick={() =>
control.clickable &&
trigger('controltap', {} as Event, { controlId: control.id }) trigger('controltap', {} as Event, { controlId: control.id })
} }
/> />
...@@ -278,10 +294,7 @@ function useMapMethods(props: Props, trigger: CustomEventTrigger) { ...@@ -278,10 +294,7 @@ function useMapMethods(props: Props, trigger: CustomEventTrigger) {
let map: Map | null let map: Map | null
function moveToLocation( function moveToLocation(
resolve: Callback, resolve: Callback,
{ { longitude, latitude }: Partial<Coordinate> = {}
longitude,
latitude,
}: { longitude?: Props['longitude']; latitude?: Props['latitude'] } = {}
) { ) {
if (!map) return if (!map) return
map.setCenter( map.setCenter(
...@@ -310,7 +323,7 @@ function useMapMethods(props: Props, trigger: CustomEventTrigger) { ...@@ -310,7 +323,7 @@ function useMapMethods(props: Props, trigger: CustomEventTrigger) {
const rect = map.getBounds() const rect = map.getBounds()
resolve({ resolve({
southwest: rect.getSouthWest(), southwest: rect.getSouthWest(),
northeast: rect.getNorthEast(), // 5plus API 名字写错了 northeast: rect.getNorthEast(),
errMsg: 'getRegion:ok', errMsg: 'getRegion:ok',
}) })
} }
...@@ -373,7 +386,6 @@ function useMapMethods(props: Props, trigger: CustomEventTrigger) { ...@@ -373,7 +386,6 @@ function useMapMethods(props: Props, trigger: CustomEventTrigger) {
// 此处5+文档中PlusMapsMarker对象只有方法,没有属性 // 此处5+文档中PlusMapsMarker对象只有方法,没有属性
// @ts-expect-error // @ts-expect-error
map.__markers__.push(nativeMarker) map.__markers__.push(nativeMarker)
map && (map.__markers_map__[id + ''] = nativeMarker)
}) })
} }
function _clearMarkers() { function _clearMarkers() {
...@@ -383,7 +395,6 @@ function useMapMethods(props: Props, trigger: CustomEventTrigger) { ...@@ -383,7 +395,6 @@ function useMapMethods(props: Props, trigger: CustomEventTrigger) {
map?.removeOverlay(marker as unknown as PlusMapsOverlay) map?.removeOverlay(marker as unknown as PlusMapsOverlay)
}) })
map.__markers__ = [] map.__markers__ = []
map.__markers_map__ = {}
} }
function _addMarkers(markers: Markers, clear?: boolean) { function _addMarkers(markers: Markers, clear?: boolean) {
if (clear) { if (clear) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册