From e2b65a3a0be5bd61d1dba2da1f00811957eb6b17 Mon Sep 17 00:00:00 2001 From: qiang Date: Wed, 3 Aug 2022 17:47:59 +0800 Subject: [PATCH] chore: build --- packages/uni-h5/dist/uni-h5.cjs.js | 260 +++++++++++---- packages/uni-h5/dist/uni-h5.es.js | 486 +++++++++++++++++++++-------- 2 files changed, 558 insertions(+), 188 deletions(-) diff --git a/packages/uni-h5/dist/uni-h5.cjs.js b/packages/uni-h5/dist/uni-h5.cjs.js index 547831268..506312a85 100644 --- a/packages/uni-h5/dist/uni-h5.cjs.js +++ b/packages/uni-h5/dist/uni-h5.cjs.js @@ -7924,6 +7924,42 @@ var index$d = /* @__PURE__ */ defineBuiltInComponent({ } }); const ICON_PATH_ORIGIN = "data:image/png;base64,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"; +function getMapInfo() { + if (__uniConfig.qqMapKey) { + return { + type: "qq", + key: __uniConfig.qqMapKey + }; + } + if (__uniConfig.googleMapKey) { + return { + type: "google", + key: __uniConfig.googleMapKey + }; + } + if (__uniConfig.aMapKey) { + return { + type: "AMap", + key: __uniConfig.aMapKey, + securityJsCode: __uniConfig.aMapSecurityJsCode, + serviceHost: __uniConfig.aMapServiceHost + }; + } + return { + type: "", + key: "" + }; +} +let IS_AMAP = false; +let hasGetIsAMap = false; +const getIsAMap = () => { + if (hasGetIsAMap) { + return IS_AMAP; + } else { + hasGetIsAMap = true; + return IS_AMAP = getMapInfo().type === "AMap"; + } +}; const props$7 = { id: { type: [Number, String], @@ -8013,10 +8049,17 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({ const onMapReady = vue.inject("onMapReady"); const updateMarkerLabelStyle = useMarkerLabelStyle(id); let marker; + function removeMarkerCallout(callout) { + if (getIsAMap()) { + callout.removeAMapText(); + } else { + callout.setMap(null); + } + } onMapReady((map, maps, trigger) => { function updateMarker(option) { const title = option.title; - const position = new maps.LatLng(option.latitude, option.longitude); + const position = getIsAMap() ? new maps.LngLat(option.longitude, option.latitude) : new maps.LatLng(option.latitude, option.longitude); const img = new Image(); img.onload = () => { const anchor = option.anchor || {}; @@ -8036,6 +8079,13 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({ top = h - (h - y * h); if ("MarkerImage" in maps) { icon = new maps.MarkerImage(img.src, null, null, new maps.Point(x * w, y * h), new maps.Size(w, h)); + } else if ("Icon" in maps) { + icon = new maps.Icon({ + image: img.src, + size: new maps.Size(w, h), + imageSize: new maps.Size(w, h), + imageOffset: new maps.Pixel(x * w, y * h) + }); } else { icon = { url: img.src, @@ -8077,13 +8127,33 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({ }); marker.label = label; } else if ("setLabel" in marker) { - const className = updateMarkerLabelStyle(labelStyle); - marker.setLabel({ - text: labelOpt.content, - color: labelStyle.color, - fontSize: labelStyle.fontSize, - className - }); + if (getIsAMap()) { + const content = `
+ ${labelOpt.content} +
`; + marker.setLabel({ + content, + direction: "bottom-right" + }); + } else { + const className = updateMarkerLabelStyle(labelStyle); + marker.setLabel({ + text: labelOpt.content, + color: labelStyle.color, + fontSize: labelStyle.fontSize, + className + }); + } } } const calloutOpt = option.callout || {}; @@ -8095,6 +8165,7 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({ position, map, top, + offsetY: -option.height / 2, content: calloutOpt.content, color: calloutOpt.color, fontSize: calloutOpt.fontSize, @@ -8107,26 +8178,38 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({ position, map, top, + offsetY: -option.height / 2, content: title, boxShadow }; if (callout) { callout.setOption(calloutStyle); } else { - callout = marker.callout = new maps.Callout(calloutStyle); - callout.div.onclick = function($event) { - if (id !== "") { - trigger("callouttap", $event, { - markerId: Number(id) - }); - } - $event.stopPropagation(); - $event.preventDefault(); - }; + if (getIsAMap()) { + const callback = (id2) => { + if (id2 !== "") { + trigger("callouttap", {}, { + markerId: Number(id2) + }); + } + }; + callout = marker.callout = new maps.Callout(calloutStyle, callback); + } else { + callout = marker.callout = new maps.Callout(calloutStyle); + callout.div.onclick = function($event) { + if (id !== "") { + trigger("callouttap", $event, { + markerId: Number(id) + }); + } + $event.stopPropagation(); + $event.preventDefault(); + }; + } } } else { if (callout) { - callout.setMap(null); + removeMarkerCallout(callout); delete marker.callout; } } @@ -8144,17 +8227,25 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({ autoRotation: false }); updateMarker(props3); - maps.event.addListener(marker, "click", () => { + const MapsEvent = maps.event || maps.Event; + MapsEvent.addListener(marker, "click", () => { const callout = marker.callout; - if (callout) { - const div = callout.div; - const parent = div.parentNode; - if (!callout.alwaysVisible) { + if (callout && !callout.alwaysVisible) { + if (getIsAMap()) { + callout.visible = !callout.visible; + if (callout.visible) { + marker.callout.createAMapText(); + } else { + marker.callout.removeAMapText(); + } + } else { callout.set("visible", !callout.visible); - } - if (callout.visible) { - parent.removeChild(div); - parent.appendChild(div); + if (callout.visible) { + const div = callout.div; + const parent = div.parentNode; + parent.removeChild(div); + parent.appendChild(div); + } } } if (id) { @@ -8189,7 +8280,8 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({ const distance = maps.geometry.spherical.computeDistanceBetween(a, b) / 1e3; const time = (typeof duration === "number" ? duration : 1e3) / (1e3 * 60 * 60); const speed = distance / time; - const movingEvent = maps.event.addListener(marker, "moving", (e2) => { + const MapsEvent = maps.event || maps.Event; + const movingEvent = MapsEvent.addListener(marker, "moving", (e2) => { const latLng = e2.latLng; const label = marker.label; if (label) { @@ -8200,7 +8292,7 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({ callout.setPosition(latLng); } }); - const event = maps.event.addListener(marker, "moveend", () => { + const event = MapsEvent.addListener(marker, "moveend", () => { event.remove(); movingEvent.remove(); marker.lastPosition = a; @@ -8232,7 +8324,7 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({ marker.moveTo(b, speed); } else { marker.setPosition(b); - maps.event.trigger(marker, "moveend", {}); + MapsEvent.trigger(marker, "moveend", {}); } }); } @@ -8345,7 +8437,8 @@ var MapPolyline = /* @__PURE__ */ defineSystemComponent({ function addPolyline(option) { const path = []; option.points.forEach((point) => { - path.push(new maps.LatLng(point.latitude, point.longitude)); + const pointPosition = getIsAMap() ? [point.longitude, point.latitude] : new maps.LatLng(point.latitude, point.longitude); + path.push(pointPosition); }); const strokeWeight = Number(option.width) || 1; const { @@ -8446,7 +8539,7 @@ var MapCircle = /* @__PURE__ */ defineSystemComponent({ addCircle(option); } function addCircle(option) { - const center = new maps.LatLng(option.latitude, option.longitude); + const center = getIsAMap() ? [option.longitude, option.latitude] : new maps.LatLng(option.latitude, option.longitude); const circleOptions = { map, center, @@ -8455,28 +8548,37 @@ var MapCircle = /* @__PURE__ */ defineSystemComponent({ strokeWeight: Number(option.strokeWidth) || 1, strokeDashStyle: "solid" }; - const { - r: fr, - g: fg, - b: fb, - a: fa - } = hexToRgba(option.fillColor); - const { - r: sr, - g: sg, - b: sb, - a: sa - } = hexToRgba(option.color); - if ("Color" in maps) { - circleOptions.fillColor = new maps.Color(fr, fg, fb, fa); - circleOptions.strokeColor = new maps.Color(sr, sg, sb, sa); + if (getIsAMap()) { + circleOptions.strokeColor = option.color; + circleOptions.fillColor = option.fillColor || "#000"; + circleOptions.fillOpacity = 1; } else { - circleOptions.fillColor = `rgb(${fr}, ${fg}, ${fb})`; - circleOptions.fillOpacity = fa; - circleOptions.strokeColor = `rgb(${sr}, ${sg}, ${sb})`; - circleOptions.strokeOpacity = sa; + const { + r: fr, + g: fg, + b: fb, + a: fa + } = hexToRgba(option.fillColor); + const { + r: sr, + g: sg, + b: sb, + a: sa + } = hexToRgba(option.color); + if ("Color" in maps) { + circleOptions.fillColor = new maps.Color(fr, fg, fb, fa); + circleOptions.strokeColor = new maps.Color(sr, sg, sb, sa); + } else { + circleOptions.fillColor = `rgb(${fr}, ${fg}, ${fb})`; + circleOptions.fillOpacity = fa; + circleOptions.strokeColor = `rgb(${sr}, ${sg}, ${sb})`; + circleOptions.strokeOpacity = sa; + } } circle = new maps.Circle(circleOptions); + if (getIsAMap()) { + map.add(circle); + } } addCircle(props2); vue.watch(props2, updateCircle); @@ -8502,6 +8604,10 @@ const props$4 = { clickable: { type: [Boolean, String], default: "" + }, + rootRef: { + type: Object, + default: null } }; var MapControl = /* @__PURE__ */ defineSystemComponent({ @@ -8529,6 +8635,8 @@ var MapControl = /* @__PURE__ */ defineSystemComponent({ style.position = "absolute"; style.width = "0"; style.height = "0"; + style.top = "0"; + style.left = "0"; img.onload = () => { if (option.position.width) { img.width = option.position.width; @@ -8550,7 +8658,11 @@ var MapControl = /* @__PURE__ */ defineSystemComponent({ }); } }; - map.controls[maps.ControlPosition.TOP_LEFT].push(control); + if (getIsAMap()) { + props2.rootRef.value && props2.rootRef.value.appendChild(control); + } else { + map.controls[maps.ControlPosition.TOP_LEFT].push(control); + } } addControl(props2); vue.watch(props2, updateControl); @@ -8629,7 +8741,7 @@ var MapPolygon = /* @__PURE__ */ defineSystemComponent({ latitude, longitude } = item; - return new maps.LatLng(latitude, longitude); + return getIsAMap() ? [longitude, latitude] : new maps.LatLng(latitude, longitude); }); const { r: fcR, @@ -8753,6 +8865,15 @@ function getPoints(points) { } return newPoints; } +function getAMapPosition(maps, latitude, longitude) { + return new maps.LngLat(longitude, latitude); +} +function getGoogleOrQQMapPosition(maps, latitude, longitude) { + return new maps.LatLng(latitude, longitude); +} +function getMapPosition(maps, latitude, longitude) { + return getIsAMap() ? getAMapPosition(maps, latitude, longitude) : getGoogleOrQQMapPosition(maps, latitude, longitude); +} function getLat(latLng) { if ("getLat" in latLng) { return latLng.getLat(); @@ -8802,15 +8923,24 @@ function useMap(props2, rootRef, emit2) { deep: true }); function updateBounds() { - const bounds = new maps.LatLngBounds(); - state.includePoints.forEach(({ - latitude, - longitude - }) => { - const latLng = new maps.LatLng(latitude, longitude); - bounds.extend(latLng); - }); - map.fitBounds(bounds); + if (getIsAMap()) { + const points = []; + state.includePoints.forEach((point) => { + points.push([point.longitude, point.latitude]); + }); + const bounds = new maps.Bounds(...points); + map.setBounds(bounds); + } else { + const bounds = new maps.LatLngBounds(); + state.includePoints.forEach(({ + latitude, + longitude + }) => { + const latLng = new maps.LatLng(latitude, longitude); + bounds.extend(latLng); + }); + map.fitBounds(bounds); + } } try { const id = useContextInfo(); @@ -8932,7 +9062,9 @@ var index$c = /* @__PURE__ */ defineBuiltInComponent({ "style": "width: 100%; height: 100%; position: relative; overflow: hidden" }, null, 512), props2.markers.map((item) => vue.createVNode(MapMarker, vue.mergeProps({ "key": item.id - }, item), null, 16)), props2.polyline.map((item) => vue.createVNode(MapPolyline, item, null, 16)), props2.circles.map((item) => vue.createVNode(MapCircle, item, null, 16)), props2.controls.map((item) => vue.createVNode(MapControl, item, null, 16)), props2.showLocation && vue.createVNode(MapLocation, null, null), props2.polygons.map((item) => vue.createVNode(MapPolygon, item, null, 16)), vue.createVNode("div", { + }, item), null, 16)), props2.polyline.map((item) => vue.createVNode(MapPolyline, item, null, 16)), props2.circles.map((item) => vue.createVNode(MapCircle, item, null, 16)), props2.controls.map((item) => vue.createVNode(MapControl, vue.mergeProps(item, { + "rootRef": rootRef + }), null, 16, ["rootRef"])), props2.showLocation && vue.createVNode(MapLocation, null, null), props2.polygons.map((item) => vue.createVNode(MapPolygon, item, null, 16)), vue.createVNode("div", { "style": "position: absolute;top: 0;width: 100%;height: 100%;overflow: hidden;pointer-events: none;" }, [slots.default && slots.default()])], 8, ["id"]); }; diff --git a/packages/uni-h5/dist/uni-h5.es.js b/packages/uni-h5/dist/uni-h5.es.js index 41462a85a..d69d41b2c 100644 --- a/packages/uni-h5/dist/uni-h5.es.js +++ b/packages/uni-h5/dist/uni-h5.es.js @@ -15387,26 +15387,47 @@ const ICON_PATH_TARGET = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAACc var MapType = /* @__PURE__ */ ((MapType2) => { MapType2["QQ"] = "qq"; MapType2["GOOGLE"] = "google"; + MapType2["AMAP"] = "AMap"; MapType2["UNKNOWN"] = ""; return MapType2; })(MapType || {}); function getMapInfo() { - let type = ""; - let key = ""; if (__uniConfig.qqMapKey) { - type = "qq"; - key = __uniConfig.qqMapKey; - } else if (__uniConfig.googleMapKey) { - type = "google"; - key = __uniConfig.googleMapKey; + return { + type: "qq", + key: __uniConfig.qqMapKey + }; + } + if (__uniConfig.googleMapKey) { + return { + type: "google", + key: __uniConfig.googleMapKey + }; + } + if (__uniConfig.aMapKey) { + return { + type: "AMap", + key: __uniConfig.aMapKey, + securityJsCode: __uniConfig.aMapSecurityJsCode, + serviceHost: __uniConfig.aMapServiceHost + }; } return { - type, - key + type: "", + key: "" }; } +let IS_AMAP = false; +let hasGetIsAMap = false; +const getIsAMap = () => { + if (hasGetIsAMap) { + return IS_AMAP; + } else { + hasGetIsAMap = true; + return IS_AMAP = getMapInfo().type === "AMap"; + } +}; function createCallout(maps2) { - const overlay = new (maps2.OverlayView || maps2.Overlay)(); function onAdd() { const div = this.div; const panes = this.getPanes(); @@ -15418,46 +15439,71 @@ function createCallout(maps2) { parentNode.removeChild(this.div); } } + function createAMapText() { + const option = this.option; + this.Text = new maps2.Text({ + text: option.content, + anchor: "bottom-center", + offset: new maps2.Pixel(0, option.offsetY), + style: { + "margin-bottom": "1rem", + padding: (option.padding || 8) + "px", + "line-height": (option.fontSize || 14) + "px", + "border-radius": (option.borderRadius || 0) + "px", + "border-color": `${option.bgColor || "#fff"} transparent transparent`, + "background-color": option.bgColor || "#fff", + "box-shadow": "0 2px 6px 0 rgba(114, 124, 245, .5)", + "text-align": "center", + "font-size": (option.fontSize || 14) + "px", + color: option.color || "#000" + }, + position: option.position + }); + const event = maps2.event || maps2.Event; + event.addListener(this.Text, "click", () => { + this.callback(); + }); + this.Text.setMap(option.map); + } + function removeAMapText() { + if (this.Text) { + this.option.map.remove(this.Text); + } + } class Callout { - constructor(option = {}) { - this.setMap = overlay.setMap; - this.getMap = overlay.getMap; - this.getPanes = overlay.getPanes; - this.getProjection = overlay.getProjection; - this.map_changed = overlay.map_changed; - this.set = overlay.set; - this.get = overlay.get; - this.setOptions = overlay.setValues; - this.bindTo = overlay.bindTo; - this.bindsTo = overlay.bindsTo; - this.notify = overlay.notify; - this.setValues = overlay.setValues; - this.unbind = overlay.unbind; - this.unbindAll = overlay.unbindAll; - this.addListener = overlay.addListener; + constructor(option = {}, callback) { + this.createAMapText = createAMapText; + this.removeAMapText = removeAMapText; this.onAdd = onAdd; this.construct = onAdd; this.onRemove = onRemove; this.destroy = onRemove; this.option = option || {}; - const map = option.map; - this.position = option.position; - this.index = 1; const visible = this.visible = this.alwaysVisible = option.display === "ALWAYS"; - const div = this.div = document.createElement("div"); - const divStyle = div.style; - divStyle.position = "absolute"; - divStyle.whiteSpace = "nowrap"; - divStyle.transform = "translateX(-50%) translateY(-100%)"; - divStyle.zIndex = "1"; - divStyle.boxShadow = option.boxShadow || "none"; - divStyle.display = visible ? "block" : "none"; - const triangle = this.triangle = document.createElement("div"); - triangle.setAttribute("style", "position: absolute;white-space: nowrap;border-width: 4px;border-style: solid;border-color: #fff transparent transparent;border-image: initial;font-size: 12px;padding: 0px;background-color: transparent;width: 0px;height: 0px;transform: translate(-50%, 100%);left: 50%;bottom: 0;"); - this.setStyle(option); - div.appendChild(triangle); - if (map) { - this.setMap(map); + if (getIsAMap()) { + this.callback = callback; + if (this.visible) { + this.createAMapText(); + } + } else { + const map = option.map; + this.position = option.position; + this.index = 1; + const div = this.div = document.createElement("div"); + const divStyle = div.style; + divStyle.position = "absolute"; + divStyle.whiteSpace = "nowrap"; + divStyle.transform = "translateX(-50%) translateY(-100%)"; + divStyle.zIndex = "1"; + divStyle.boxShadow = option.boxShadow || "none"; + divStyle.display = visible ? "block" : "none"; + const triangle = this.triangle = document.createElement("div"); + triangle.setAttribute("style", "position: absolute;white-space: nowrap;border-width: 4px;border-style: solid;border-color: #fff transparent transparent;border-image: initial;font-size: 12px;padding: 0px;background-color: transparent;width: 0px;height: 0px;transform: translate(-50%, 100%);left: 50%;bottom: 0;"); + this.setStyle(option); + div.appendChild(triangle); + if (map) { + this.setMap(map); + } } } set onclick(callback) { @@ -15468,13 +15514,19 @@ function createCallout(maps2) { } setOption(option) { this.option = option; - this.setPosition(option.position); if (option.display === "ALWAYS") { this.alwaysVisible = this.visible = true; } else { this.alwaysVisible = false; } - this.setStyle(option); + if (getIsAMap()) { + if (this.visible) { + this.createAMapText(); + } + } else { + this.setPosition(option.position); + this.setStyle(option); + } } setStyle(option) { const div = this.div; @@ -15508,6 +15560,24 @@ function createCallout(maps2) { divStyle.display = this.visible ? "block" : "none"; } } + if (!getIsAMap()) { + const overlay = new (maps2.OverlayView || maps2.Overlay)(); + Callout.prototype.setMap = overlay.setMap; + Callout.prototype.getMap = overlay.getMap; + Callout.prototype.getPanes = overlay.getPanes; + Callout.prototype.getProjection = overlay.getProjection; + Callout.prototype.map_changed = overlay.map_changed; + Callout.prototype.set = overlay.set; + Callout.prototype.get = overlay.get; + Callout.prototype.setOptions = overlay.setValues; + Callout.prototype.bindTo = overlay.bindTo; + Callout.prototype.bindsTo = overlay.bindsTo; + Callout.prototype.notify = overlay.notify; + Callout.prototype.setValues = overlay.setValues; + Callout.prototype.unbind = overlay.unbind; + Callout.prototype.unbindAll = overlay.unbindAll; + Callout.prototype.addListener = overlay.addListener; + } return Callout; } let maps; @@ -15523,7 +15593,7 @@ function loadMaps(libraries, callback) { if (maps) { callback(maps); } else if (window[mapInfo.type] && window[mapInfo.type].maps) { - maps = window[mapInfo.type].maps; + maps = getIsAMap() ? window[mapInfo.type] : window[mapInfo.type].maps; maps.Callout = maps.Callout || createCallout(maps); callback(maps); } else if (callbacks2.length) { @@ -15534,13 +15604,16 @@ function loadMaps(libraries, callback) { const callbackName = GOOGLE_MAP_CALLBACKNAME + mapInfo.type; globalExt[callbackName] = function() { delete globalExt[callbackName]; - maps = window[mapInfo.type].maps; + maps = getIsAMap() ? window[mapInfo.type] : window[mapInfo.type].maps; maps.Callout = createCallout(maps); callbacks2.forEach((callback2) => callback2(maps)); callbacks2.length = 0; }; + if (getIsAMap()) { + handleAMapSecurityPolicy(mapInfo); + } const script = document.createElement("script"); - let src = mapInfo.type === MapType.GOOGLE ? "https://maps.googleapis.com/maps/api/js?" : "https://map.qq.com/api/js?v=2.exp&"; + let src = getScriptBaseUrl(mapInfo.type); if (mapInfo.type === MapType.QQ) { libraries.push("geometry"); } @@ -15554,6 +15627,20 @@ function loadMaps(libraries, callback) { document.body.appendChild(script); } } +const getScriptBaseUrl = (mapType) => { + const urlMap = { + qq: "https://map.qq.com/api/js?v=2.exp&", + google: "https://maps.googleapis.com/maps/api/js?", + AMap: "https://webapi.amap.com/maps?v=2.0&" + }; + return urlMap[mapType]; +}; +function handleAMapSecurityPolicy(mapInfo) { + window._AMapSecurityConfig = { + securityJsCode: mapInfo.securityJsCode || "", + serviceHost: mapInfo.serviceHost || "" + }; +} const props$e = { id: { type: [Number, String], @@ -15652,15 +15739,22 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({ marker.label.setMap(null); } if (marker.callout) { - marker.callout.setMap(null); + removeMarkerCallout(marker.callout); } marker.setMap(null); } } + function removeMarkerCallout(callout) { + if (getIsAMap()) { + callout.removeAMapText(); + } else { + callout.setMap(null); + } + } onMapReady((map, maps2, trigger) => { function updateMarker(option) { const title = option.title; - const position = new maps2.LatLng(option.latitude, option.longitude); + const position = getIsAMap() ? new maps2.LngLat(option.longitude, option.latitude) : new maps2.LatLng(option.latitude, option.longitude); const img = new Image(); img.onload = () => { const anchor = option.anchor || {}; @@ -15680,6 +15774,13 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({ top = h2 - (h2 - y * h2); if ("MarkerImage" in maps2) { icon = new maps2.MarkerImage(img.src, null, null, new maps2.Point(x * w, y * h2), new maps2.Size(w, h2)); + } else if ("Icon" in maps2) { + icon = new maps2.Icon({ + image: img.src, + size: new maps2.Size(w, h2), + imageSize: new maps2.Size(w, h2), + imageOffset: new maps2.Pixel(x * w, y * h2) + }); } else { icon = { url: img.src, @@ -15721,13 +15822,33 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({ }); marker.label = label; } else if ("setLabel" in marker) { - const className = updateMarkerLabelStyle(labelStyle); - marker.setLabel({ - text: labelOpt.content, - color: labelStyle.color, - fontSize: labelStyle.fontSize, - className - }); + if (getIsAMap()) { + const content = `
+ ${labelOpt.content} +
`; + marker.setLabel({ + content, + direction: "bottom-right" + }); + } else { + const className = updateMarkerLabelStyle(labelStyle); + marker.setLabel({ + text: labelOpt.content, + color: labelStyle.color, + fontSize: labelStyle.fontSize, + className + }); + } } } const calloutOpt = option.callout || {}; @@ -15739,6 +15860,7 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({ position, map, top, + offsetY: -option.height / 2, content: calloutOpt.content, color: calloutOpt.color, fontSize: calloutOpt.fontSize, @@ -15751,26 +15873,38 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({ position, map, top, + offsetY: -option.height / 2, content: title, boxShadow }; if (callout) { callout.setOption(calloutStyle); } else { - callout = marker.callout = new maps2.Callout(calloutStyle); - callout.div.onclick = function($event) { - if (id2 !== "") { - trigger("callouttap", $event, { - markerId: Number(id2) - }); - } - $event.stopPropagation(); - $event.preventDefault(); - }; + if (getIsAMap()) { + const callback = (id3) => { + if (id3 !== "") { + trigger("callouttap", {}, { + markerId: Number(id3) + }); + } + }; + callout = marker.callout = new maps2.Callout(calloutStyle, callback); + } else { + callout = marker.callout = new maps2.Callout(calloutStyle); + callout.div.onclick = function($event) { + if (id2 !== "") { + trigger("callouttap", $event, { + markerId: Number(id2) + }); + } + $event.stopPropagation(); + $event.preventDefault(); + }; + } } } else { if (callout) { - callout.setMap(null); + removeMarkerCallout(callout); delete marker.callout; } } @@ -15788,17 +15922,25 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({ autoRotation: false }); updateMarker(props3); - maps2.event.addListener(marker, "click", () => { + const MapsEvent = maps2.event || maps2.Event; + MapsEvent.addListener(marker, "click", () => { const callout = marker.callout; - if (callout) { - const div = callout.div; - const parent = div.parentNode; - if (!callout.alwaysVisible) { + if (callout && !callout.alwaysVisible) { + if (getIsAMap()) { + callout.visible = !callout.visible; + if (callout.visible) { + marker.callout.createAMapText(); + } else { + marker.callout.removeAMapText(); + } + } else { callout.set("visible", !callout.visible); - } - if (callout.visible) { - parent.removeChild(div); - parent.appendChild(div); + if (callout.visible) { + const div = callout.div; + const parent = div.parentNode; + parent.removeChild(div); + parent.appendChild(div); + } } } if (id2) { @@ -15833,7 +15975,8 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({ const distance2 = maps2.geometry.spherical.computeDistanceBetween(a2, b) / 1e3; const time = (typeof duration === "number" ? duration : 1e3) / (1e3 * 60 * 60); const speed = distance2 / time; - const movingEvent = maps2.event.addListener(marker, "moving", (e2) => { + const MapsEvent = maps2.event || maps2.Event; + const movingEvent = MapsEvent.addListener(marker, "moving", (e2) => { const latLng = e2.latLng; const label = marker.label; if (label) { @@ -15844,7 +15987,7 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({ callout.setPosition(latLng); } }); - const event = maps2.event.addListener(marker, "moveend", () => { + const event = MapsEvent.addListener(marker, "moveend", () => { event.remove(); movingEvent.remove(); marker.lastPosition = a2; @@ -15876,7 +16019,7 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({ marker.moveTo(b, speed); } else { marker.setPosition(b); - maps2.event.trigger(marker, "moveend", {}); + MapsEvent.trigger(marker, "moveend", {}); } }); } @@ -15991,7 +16134,8 @@ var MapPolyline = /* @__PURE__ */ defineSystemComponent({ function addPolyline(option) { const path = []; option.points.forEach((point) => { - path.push(new maps2.LatLng(point.latitude, point.longitude)); + const pointPosition = getIsAMap() ? [point.longitude, point.latitude] : new maps2.LatLng(point.latitude, point.longitude); + path.push(pointPosition); }); const strokeWeight = Number(option.width) || 1; const { @@ -16093,7 +16237,7 @@ var MapCircle = /* @__PURE__ */ defineSystemComponent({ addCircle(option); } function addCircle(option) { - const center = new maps2.LatLng(option.latitude, option.longitude); + const center = getIsAMap() ? [option.longitude, option.latitude] : new maps2.LatLng(option.latitude, option.longitude); const circleOptions = { map, center, @@ -16102,28 +16246,37 @@ var MapCircle = /* @__PURE__ */ defineSystemComponent({ strokeWeight: Number(option.strokeWidth) || 1, strokeDashStyle: "solid" }; - const { - r: fr, - g: fg, - b: fb, - a: fa - } = hexToRgba(option.fillColor); - const { - r: sr, - g: sg, - b: sb, - a: sa - } = hexToRgba(option.color); - if ("Color" in maps2) { - circleOptions.fillColor = new maps2.Color(fr, fg, fb, fa); - circleOptions.strokeColor = new maps2.Color(sr, sg, sb, sa); + if (getIsAMap()) { + circleOptions.strokeColor = option.color; + circleOptions.fillColor = option.fillColor || "#000"; + circleOptions.fillOpacity = 1; } else { - circleOptions.fillColor = `rgb(${fr}, ${fg}, ${fb})`; - circleOptions.fillOpacity = fa; - circleOptions.strokeColor = `rgb(${sr}, ${sg}, ${sb})`; - circleOptions.strokeOpacity = sa; + const { + r: fr, + g: fg, + b: fb, + a: fa + } = hexToRgba(option.fillColor); + const { + r: sr, + g: sg, + b: sb, + a: sa + } = hexToRgba(option.color); + if ("Color" in maps2) { + circleOptions.fillColor = new maps2.Color(fr, fg, fb, fa); + circleOptions.strokeColor = new maps2.Color(sr, sg, sb, sa); + } else { + circleOptions.fillColor = `rgb(${fr}, ${fg}, ${fb})`; + circleOptions.fillOpacity = fa; + circleOptions.strokeColor = `rgb(${sr}, ${sg}, ${sb})`; + circleOptions.strokeOpacity = sa; + } } circle = new maps2.Circle(circleOptions); + if (getIsAMap()) { + map.add(circle); + } } addCircle(props2); watch(props2, updateCircle); @@ -16150,6 +16303,10 @@ const props$b = { clickable: { type: [Boolean, String], default: "" + }, + rootRef: { + type: Object, + default: null } }; var MapControl = /* @__PURE__ */ defineSystemComponent({ @@ -16177,6 +16334,8 @@ var MapControl = /* @__PURE__ */ defineSystemComponent({ style.position = "absolute"; style.width = "0"; style.height = "0"; + style.top = "0"; + style.left = "0"; img.onload = () => { if (option.position.width) { img.width = option.position.width; @@ -16198,7 +16357,11 @@ var MapControl = /* @__PURE__ */ defineSystemComponent({ }); } }; - map.controls[maps2.ControlPosition.TOP_LEFT].push(control); + if (getIsAMap()) { + props2.rootRef.value && props2.rootRef.value.appendChild(control); + } else { + map.controls[maps2.ControlPosition.TOP_LEFT].push(control); + } } addControl(props2); watch(props2, updateControl); @@ -18250,6 +18413,21 @@ const getLocation = /* @__PURE__ */ defineAsyncApi(API_GET_LOCATION, ({ type, al reject2(new Error("network error")); } }); + } else if (mapInfo.type === MapType.AMAP) { + window.AMap.plugin("AMap.Geolocation", function() { + var geolocation = new window.AMap.Geolocation({}); + geolocation.getCurrentPosition(function(status, res) { + if (status === "complete") { + resolve2({ + latitude: res.position.lat, + longitude: res.position.lng, + accuracy: res.accuracy + }); + } else { + reject2(new Error(res.message || JSON.stringify(res))); + } + }); + }); } else { reject2(error); } @@ -18368,6 +18546,11 @@ var LocationView = /* @__PURE__ */ defineSystemComponent({ } else if (mapInfo.type === MapType.QQ) { const fromcoord = state2.location.latitude ? `&fromcoord=${state2.location.latitude}%2C${state2.location.longitude}` : ""; url = `https://apis.map.qq.com/uri/v1/routeplan?type=drive${fromcoord}&tocoord=${props2.latitude}%2C${props2.longitude}&from=${encodeURIComponent("\u6211\u7684\u4F4D\u7F6E")}&to=${encodeURIComponent(props2.name || "\u76EE\u7684\u5730")}&ref=${mapInfo.key}`; + } else if (mapInfo.type === MapType.AMAP) { + url = `https://m.amap.com/navi/?dest=${props2.longitude},${props2.latitude}&key=${mapInfo.key}`; + if (props2.name) { + url += `&destName=${props2.name}`; + } } window.open(url); } @@ -18508,7 +18691,7 @@ function useList(state2) { list2.push({ name: item.title, address: item.address, - distance: item._distance, + distance: item._distance || item.distance, latitude: item.location.lat, longitude: item.location.lng }); @@ -18574,6 +18757,37 @@ function useList(state2) { }, () => { listState.loading = false; }); + } else if (mapInfo.type === MapType.AMAP) { + window.AMap.plugin("AMap.PlaceSearch", function() { + var autoOptions = { + city: "\u5168\u56FD", + pageSize: 10, + pageIndex: listState.pageIndex + }; + var placeSearch = new window.AMap.PlaceSearch(autoOptions); + if (state2.searching) { + placeSearch.searchNearBy(state2.keyword, [state2.longitude, state2.latitude], 5e4, function(status, result) { + if (status === "error") { + console.error(result); + } else if (status === "no_data") { + listState.hasNextPage = false; + } else { + pushData(result.poiList.pois); + } + }); + } else { + placeSearch.searchNearBy("", [state2.longitude, state2.latitude], 5e3, function(status, result) { + if (status === "error") { + console.error(result); + } else if (status === "no_data") { + listState.hasNextPage = false; + } else { + pushData(result.poiList.pois); + } + }); + } + listState.loading = false; + }); } } function loadMore() { @@ -20554,7 +20768,7 @@ var MapPolygon = /* @__PURE__ */ defineSystemComponent({ latitude, longitude } = item; - return new maps2.LatLng(latitude, longitude); + return getIsAMap() ? [longitude, latitude] : new maps2.LatLng(latitude, longitude); }); const { r: fcR, @@ -20681,6 +20895,15 @@ function getPoints(points) { } return newPoints; } +function getAMapPosition(maps2, latitude, longitude) { + return new maps2.LngLat(longitude, latitude); +} +function getGoogleOrQQMapPosition(maps2, latitude, longitude) { + return new maps2.LatLng(latitude, longitude); +} +function getMapPosition(maps2, latitude, longitude) { + return getIsAMap() ? getAMapPosition(maps2, latitude, longitude) : getGoogleOrQQMapPosition(maps2, latitude, longitude); +} function getLat(latLng) { if ("getLat" in latLng) { return latLng.getLat(); @@ -20742,7 +20965,8 @@ function useMap(props2, rootRef, emit2) { state2.latitude = latitude; state2.longitude = longitude; if (map) { - map.setCenter(new maps2.LatLng(latitude, longitude)); + const centerPosition = getMapPosition(maps2, state2.latitude, state2.longitude); + map.setCenter(centerPosition); } } }); @@ -20770,22 +20994,33 @@ function useMap(props2, rootRef, emit2) { }; } function updateCenter() { - map.setCenter(new maps2.LatLng(state2.latitude, state2.longitude)); + const centerPosition = getMapPosition(maps2, state2.latitude, state2.longitude); + map.setCenter(centerPosition); } function updateBounds() { - const bounds = new maps2.LatLngBounds(); - state2.includePoints.forEach(({ - latitude, - longitude - }) => { - const latLng = new maps2.LatLng(latitude, longitude); - bounds.extend(latLng); - }); - map.fitBounds(bounds); + if (getIsAMap()) { + const points = []; + state2.includePoints.forEach((point) => { + points.push([point.longitude, point.latitude]); + }); + const bounds = new maps2.Bounds(...points); + map.setBounds(bounds); + } else { + const bounds = new maps2.LatLngBounds(); + state2.includePoints.forEach(({ + latitude, + longitude + }) => { + const latLng = new maps2.LatLng(latitude, longitude); + bounds.extend(latLng); + }); + map.fitBounds(bounds); + } } function initMap() { const mapEl = mapRef.value; - const center = new maps2.LatLng(state2.latitude, state2.longitude); + const center = getMapPosition(maps2, state2.latitude, state2.longitude); + const event = maps2.event || maps2.Event; const map2 = new maps2.Map(mapEl, { center, zoom: Number(props2.scale), @@ -20810,34 +21045,34 @@ function useMap(props2, rootRef, emit2) { updateCenter(); } }); - const boundsChangedEvent = maps2.event.addListener(map2, "bounds_changed", () => { + const boundsChangedEvent = event.addListener(map2, "bounds_changed", () => { boundsChangedEvent.remove(); emitBoundsReady(); }); - maps2.event.addListener(map2, "click", () => { + event.addListener(map2, "click", () => { trigger("tap", {}, {}); trigger("click", {}, {}); }); - maps2.event.addListener(map2, "dragstart", () => { + event.addListener(map2, "dragstart", () => { trigger("regionchange", {}, { type: "begin", causedBy: "gesture" }); }); - maps2.event.addListener(map2, "dragend", () => { + event.addListener(map2, "dragend", () => { trigger("regionchange", {}, extend({ type: "end", causedBy: "drag" }, getMapInfo2())); }); - maps2.event.addListener(map2, "zoom_changed", () => { + event.addListener(map2, "zoom_changed", () => { emit2("update:scale", map2.getZoom()); trigger("regionchange", {}, extend({ type: "end", causedBy: "scale" }, getMapInfo2())); }); - maps2.event.addListener(map2, "center_changed", () => { + event.addListener(map2, "center_changed", () => { const center2 = map2.getCenter(); const latitude = getLat(center2); const longitude = getLng(center2); @@ -20875,7 +21110,8 @@ function useMap(props2, rootRef, emit2) { state2.latitude = latitude; state2.longitude = longitude; if (map) { - map.setCenter(new maps2.LatLng(latitude, longitude)); + const centerPosition = getMapPosition(maps2, latitude, longitude); + map.setCenter(centerPosition); } onMapReady(() => { callOptions(data, `${type}:ok`); @@ -20976,7 +21212,9 @@ var Map$1 = /* @__PURE__ */ defineBuiltInComponent({ "style": "width: 100%; height: 100%; position: relative; overflow: hidden" }, null, 512), props2.markers.map((item) => createVNode(MapMarker, mergeProps({ "key": item.id - }, item), null, 16)), props2.polyline.map((item) => createVNode(MapPolyline, item, null, 16)), props2.circles.map((item) => createVNode(MapCircle, item, null, 16)), props2.controls.map((item) => createVNode(MapControl, item, null, 16)), props2.showLocation && createVNode(MapLocation, null, null), props2.polygons.map((item) => createVNode(MapPolygon, item, null, 16)), createVNode("div", { + }, item), null, 16)), props2.polyline.map((item) => createVNode(MapPolyline, item, null, 16)), props2.circles.map((item) => createVNode(MapCircle, item, null, 16)), props2.controls.map((item) => createVNode(MapControl, mergeProps(item, { + "rootRef": rootRef + }), null, 16, ["rootRef"])), props2.showLocation && createVNode(MapLocation, null, null), props2.polygons.map((item) => createVNode(MapPolygon, item, null, 16)), createVNode("div", { "style": "position: absolute;top: 0;width: 100%;height: 100%;overflow: hidden;pointer-events: none;" }, [slots.default && slots.default()])], 8, ["id"]); }; -- GitLab