提交 a34d87f8 编写于 作者: 染小白's avatar 染小白

feat(map): add event

上级 493aa077
...@@ -9176,7 +9176,14 @@ const MapPolyline = /* @__PURE__ */ defineSystemComponent({ ...@@ -9176,7 +9176,14 @@ const MapPolyline = /* @__PURE__ */ defineSystemComponent({
function addPolyline(option) { function addPolyline(option) {
const path = []; const path = [];
option.points.forEach((point) => { option.points.forEach((point) => {
const pointPosition = getIsAMap() ? [point.longitude, point.latitude] : new maps.LatLng(point.latitude, point.longitude); let pointPosition;
if (getIsAMap()) {
pointPosition = [point.longitude, point.latitude];
} else if (getIsBMap()) {
pointPosition = new maps.Point(point.longitude, point.latitude);
} else {
pointPosition = new maps.LatLng(point.latitude, point.longitude);
}
path.push(pointPosition); path.push(pointPosition);
}); });
const strokeWeight = Number(option.width) || 1; const strokeWeight = Number(option.width) || 1;
...@@ -9221,7 +9228,12 @@ const MapPolyline = /* @__PURE__ */ defineSystemComponent({ ...@@ -9221,7 +9228,12 @@ const MapPolyline = /* @__PURE__ */ defineSystemComponent({
if (borderWidth) { if (borderWidth) {
polylineBorder = new maps.Polyline(polylineBorderOptions); polylineBorder = new maps.Polyline(polylineBorderOptions);
} }
polyline = new maps.Polyline(polylineOptions); if (getIsBMap()) {
polyline = new maps.Polyline(polylineOptions.path, polylineOptions);
map.addOverlay(polyline);
} else {
polyline = new maps.Polyline(polylineOptions);
}
} }
addPolyline(props2); addPolyline(props2);
vue.watch(props2, updatePolyline); vue.watch(props2, updatePolyline);
...@@ -9278,7 +9290,7 @@ const MapCircle = /* @__PURE__ */ defineSystemComponent({ ...@@ -9278,7 +9290,7 @@ const MapCircle = /* @__PURE__ */ defineSystemComponent({
addCircle(option); addCircle(option);
} }
function addCircle(option) { function addCircle(option) {
const center = getIsAMap() ? [option.longitude, option.latitude] : new maps.LatLng(option.latitude, option.longitude); const center = getIsAMap() || getIsBMap() ? [option.longitude, option.latitude] : new maps.LatLng(option.latitude, option.longitude);
const circleOptions = { const circleOptions = {
map, map,
center, center,
...@@ -9287,7 +9299,7 @@ const MapCircle = /* @__PURE__ */ defineSystemComponent({ ...@@ -9287,7 +9299,7 @@ const MapCircle = /* @__PURE__ */ defineSystemComponent({
strokeWeight: Number(option.strokeWidth) || 1, strokeWeight: Number(option.strokeWidth) || 1,
strokeDashStyle: "solid" strokeDashStyle: "solid"
}; };
if (getIsAMap()) { if (getIsAMap() || getIsBMap()) {
circleOptions.strokeColor = option.color; circleOptions.strokeColor = option.color;
circleOptions.fillColor = option.fillColor || "#000"; circleOptions.fillColor = option.fillColor || "#000";
circleOptions.fillOpacity = 1; circleOptions.fillOpacity = 1;
...@@ -9314,9 +9326,20 @@ const MapCircle = /* @__PURE__ */ defineSystemComponent({ ...@@ -9314,9 +9326,20 @@ const MapCircle = /* @__PURE__ */ defineSystemComponent({
circleOptions.strokeOpacity = sa; circleOptions.strokeOpacity = sa;
} }
} }
circle = new maps.Circle(circleOptions); if (getIsBMap()) {
if (getIsAMap()) { let pt = new maps.Point(
map.add(circle); // @ts-ignore
circleOptions.center[0],
// @ts-ignore
circleOptions.center[1]
);
circle = new maps.Circle(pt, circleOptions.radius, circleOptions);
map.addOverlay(circle);
} else {
circle = new maps.Circle(circleOptions);
if (getIsAMap()) {
map.add(circle);
}
} }
} }
addCircle(props2); addCircle(props2);
...@@ -9458,7 +9481,13 @@ const MapPolygon = /* @__PURE__ */ defineSystemComponent({ ...@@ -9458,7 +9481,13 @@ const MapPolygon = /* @__PURE__ */ defineSystemComponent({
latitude, latitude,
longitude longitude
} = item; } = item;
return getIsAMap() ? [longitude, latitude] : new maps.LatLng(latitude, longitude); if (getIsAMap()) {
return [longitude, latitude];
} else if (getIsBMap()) {
return new maps.Point(longitude, latitude);
} else {
return new maps.LatLng(latitude, longitude);
}
}); });
const { const {
r: fcR, r: fcR,
...@@ -9510,7 +9539,12 @@ const MapPolygon = /* @__PURE__ */ defineSystemComponent({ ...@@ -9510,7 +9539,12 @@ const MapPolygon = /* @__PURE__ */ defineSystemComponent({
polygonIns.setOptions(polygonOptions); polygonIns.setOptions(polygonOptions);
return; return;
} }
polygonIns = new maps.Polygon(polygonOptions); if (getIsBMap()) {
polygonIns = new maps.Polygon(polygonOptions.path, polygonOptions);
map.addOverlay(polygonIns);
} else {
polygonIns = new maps.Polygon(polygonOptions);
}
} }
drawPolygon(); drawPolygon();
vue.watch(props2, drawPolygon); vue.watch(props2, drawPolygon);
...@@ -9616,6 +9650,9 @@ function getLat(latLng) { ...@@ -9616,6 +9650,9 @@ function getLat(latLng) {
if ("getLat" in latLng) { if ("getLat" in latLng) {
return latLng.getLat(); return latLng.getLat();
} else { } else {
if (getIsBMap()) {
return latLng.lat;
}
return latLng.lat(); return latLng.lat();
} }
} }
...@@ -9623,6 +9660,9 @@ function getLng(latLng) { ...@@ -9623,6 +9660,9 @@ function getLng(latLng) {
if ("getLng" in latLng) { if ("getLng" in latLng) {
return latLng.getLng(); return latLng.getLng();
} else { } else {
if (getIsBMap()) {
return latLng.lng;
}
return latLng.lng(); return latLng.lng();
} }
} }
......
...@@ -17625,7 +17625,14 @@ const MapPolyline = /* @__PURE__ */ defineSystemComponent({ ...@@ -17625,7 +17625,14 @@ const MapPolyline = /* @__PURE__ */ defineSystemComponent({
function addPolyline(option) { function addPolyline(option) {
const path = []; const path = [];
option.points.forEach((point) => { option.points.forEach((point) => {
const pointPosition = getIsAMap() ? [point.longitude, point.latitude] : new maps2.LatLng(point.latitude, point.longitude); let pointPosition;
if (getIsAMap()) {
pointPosition = [point.longitude, point.latitude];
} else if (getIsBMap()) {
pointPosition = new maps2.Point(point.longitude, point.latitude);
} else {
pointPosition = new maps2.LatLng(point.latitude, point.longitude);
}
path.push(pointPosition); path.push(pointPosition);
}); });
const strokeWeight = Number(option.width) || 1; const strokeWeight = Number(option.width) || 1;
...@@ -17670,7 +17677,12 @@ const MapPolyline = /* @__PURE__ */ defineSystemComponent({ ...@@ -17670,7 +17677,12 @@ const MapPolyline = /* @__PURE__ */ defineSystemComponent({
if (borderWidth) { if (borderWidth) {
polylineBorder = new maps2.Polyline(polylineBorderOptions); polylineBorder = new maps2.Polyline(polylineBorderOptions);
} }
polyline = new maps2.Polyline(polylineOptions); if (getIsBMap()) {
polyline = new maps2.Polyline(polylineOptions.path, polylineOptions);
map.addOverlay(polyline);
} else {
polyline = new maps2.Polyline(polylineOptions);
}
} }
addPolyline(props2); addPolyline(props2);
watch(props2, updatePolyline); watch(props2, updatePolyline);
...@@ -17728,7 +17740,7 @@ const MapCircle = /* @__PURE__ */ defineSystemComponent({ ...@@ -17728,7 +17740,7 @@ const MapCircle = /* @__PURE__ */ defineSystemComponent({
addCircle(option); addCircle(option);
} }
function addCircle(option) { function addCircle(option) {
const center = getIsAMap() ? [option.longitude, option.latitude] : new maps2.LatLng(option.latitude, option.longitude); const center = getIsAMap() || getIsBMap() ? [option.longitude, option.latitude] : new maps2.LatLng(option.latitude, option.longitude);
const circleOptions = { const circleOptions = {
map, map,
center, center,
...@@ -17737,7 +17749,7 @@ const MapCircle = /* @__PURE__ */ defineSystemComponent({ ...@@ -17737,7 +17749,7 @@ const MapCircle = /* @__PURE__ */ defineSystemComponent({
strokeWeight: Number(option.strokeWidth) || 1, strokeWeight: Number(option.strokeWidth) || 1,
strokeDashStyle: "solid" strokeDashStyle: "solid"
}; };
if (getIsAMap()) { if (getIsAMap() || getIsBMap()) {
circleOptions.strokeColor = option.color; circleOptions.strokeColor = option.color;
circleOptions.fillColor = option.fillColor || "#000"; circleOptions.fillColor = option.fillColor || "#000";
circleOptions.fillOpacity = 1; circleOptions.fillOpacity = 1;
...@@ -17764,9 +17776,20 @@ const MapCircle = /* @__PURE__ */ defineSystemComponent({ ...@@ -17764,9 +17776,20 @@ const MapCircle = /* @__PURE__ */ defineSystemComponent({
circleOptions.strokeOpacity = sa; circleOptions.strokeOpacity = sa;
} }
} }
circle = new maps2.Circle(circleOptions); if (getIsBMap()) {
if (getIsAMap()) { let pt = new maps2.Point(
map.add(circle); // @ts-ignore
circleOptions.center[0],
// @ts-ignore
circleOptions.center[1]
);
circle = new maps2.Circle(pt, circleOptions.radius, circleOptions);
map.addOverlay(circle);
} else {
circle = new maps2.Circle(circleOptions);
if (getIsAMap()) {
map.add(circle);
}
} }
} }
addCircle(props2); addCircle(props2);
...@@ -23149,7 +23172,13 @@ const MapPolygon = /* @__PURE__ */ defineSystemComponent({ ...@@ -23149,7 +23172,13 @@ const MapPolygon = /* @__PURE__ */ defineSystemComponent({
latitude, latitude,
longitude longitude
} = item; } = item;
return getIsAMap() ? [longitude, latitude] : new maps2.LatLng(latitude, longitude); if (getIsAMap()) {
return [longitude, latitude];
} else if (getIsBMap()) {
return new maps2.Point(longitude, latitude);
} else {
return new maps2.LatLng(latitude, longitude);
}
}); });
const { const {
r: fcR, r: fcR,
...@@ -23201,7 +23230,12 @@ const MapPolygon = /* @__PURE__ */ defineSystemComponent({ ...@@ -23201,7 +23230,12 @@ const MapPolygon = /* @__PURE__ */ defineSystemComponent({
polygonIns.setOptions(polygonOptions); polygonIns.setOptions(polygonOptions);
return; return;
} }
polygonIns = new maps2.Polygon(polygonOptions); if (getIsBMap()) {
polygonIns = new maps2.Polygon(polygonOptions.path, polygonOptions);
map.addOverlay(polygonIns);
} else {
polygonIns = new maps2.Polygon(polygonOptions);
}
} }
drawPolygon(); drawPolygon();
watch(props2, drawPolygon); watch(props2, drawPolygon);
...@@ -23310,6 +23344,9 @@ function getLat(latLng) { ...@@ -23310,6 +23344,9 @@ function getLat(latLng) {
if ("getLat" in latLng) { if ("getLat" in latLng) {
return latLng.getLat(); return latLng.getLat();
} else { } else {
if (getIsBMap()) {
return latLng.lat;
}
return latLng.lat(); return latLng.lat();
} }
} }
...@@ -23317,6 +23354,9 @@ function getLng(latLng) { ...@@ -23317,6 +23354,9 @@ function getLng(latLng) {
if ("getLng" in latLng) { if ("getLng" in latLng) {
return latLng.getLng(); return latLng.getLng();
} else { } else {
if (getIsBMap()) {
return latLng.lng;
}
return latLng.lng(); return latLng.lng();
} }
} }
...@@ -23425,7 +23465,6 @@ function useMap(props2, rootRef, emit2) { ...@@ -23425,7 +23465,6 @@ function useMap(props2, rootRef, emit2) {
const mapEl = mapRef.value; const mapEl = mapRef.value;
const center = getMapPosition(maps2, state2.latitude, state2.longitude); const center = getMapPosition(maps2, state2.latitude, state2.longitude);
const event = maps2.event || maps2.Event; const event = maps2.event || maps2.Event;
console.log("event:", event);
const map2 = new maps2.Map(mapEl, { const map2 = new maps2.Map(mapEl, {
center, center,
zoom: Number(props2.scale), zoom: Number(props2.scale),
...@@ -23457,7 +23496,22 @@ function useMap(props2, rootRef, emit2) { ...@@ -23457,7 +23496,22 @@ function useMap(props2, rootRef, emit2) {
} }
}); });
if (getIsBMap()) { if (getIsBMap()) {
console.log("bmap的事件绑定是on??"); map2.addEventListener("click", () => {
trigger("tap", {}, {});
trigger("click", {}, {});
});
map2.addEventListener("dragstart", () => {
trigger("regionchange", {}, {
type: "begin",
causedBy: "gesture"
});
});
map2.addEventListener("dragend", () => {
trigger("regionchange", {}, extend({
type: "end",
causedBy: "drag"
}, getMapInfo2()));
});
} else { } else {
const boundsChangedEvent = event.addListener(map2, "bounds_changed", () => { const boundsChangedEvent = event.addListener(map2, "bounds_changed", () => {
boundsChangedEvent.remove(); boundsChangedEvent.remove();
......
...@@ -160,6 +160,9 @@ function getLat(latLng: LatLng) { ...@@ -160,6 +160,9 @@ function getLat(latLng: LatLng) {
if ('getLat' in latLng) { if ('getLat' in latLng) {
return latLng.getLat() return latLng.getLat()
} else { } else {
if (getIsBMap()) {
return latLng.lat
}
return latLng.lat() return latLng.lat()
} }
} }
...@@ -168,6 +171,9 @@ function getLng(latLng: LatLng) { ...@@ -168,6 +171,9 @@ function getLng(latLng: LatLng) {
if ('getLng' in latLng) { if ('getLng' in latLng) {
return latLng.getLng() return latLng.getLng()
} else { } else {
if (getIsBMap()) {
return latLng.lng
}
return latLng.lng() return latLng.lng()
} }
} }
...@@ -300,7 +306,7 @@ function useMap( ...@@ -300,7 +306,7 @@ function useMap(
const center = getMapPosition(maps, state.latitude, state.longitude) const center = getMapPosition(maps, state.latitude, state.longitude)
const event = const event =
(maps as QQMaps | GoogleMaps).event || (maps as AMap.NameSpace).Event (maps as QQMaps | GoogleMaps).event || (maps as AMap.NameSpace).Event
console.log('event:', event) // console.log('event:', event)
const map = new maps.Map(mapEl, { const map = new maps.Map(mapEl, {
center: center as any, center: center as any,
zoom: Number(props.scale), zoom: Number(props.scale),
...@@ -340,7 +346,32 @@ function useMap( ...@@ -340,7 +346,32 @@ function useMap(
}) })
// 需在 bounds_changed 后触发 BoundsReady // 需在 bounds_changed 后触发 BoundsReady
if (getIsBMap()) { if (getIsBMap()) {
console.log('bmap的事件绑定是on??') // @ts-ignore
map.addEventListener('click', () => {
trigger('tap', {} as Event, {})
trigger('click', {} as Event, {})
})
// @ts-ignore
map.addEventListener('dragstart', () => {
trigger('regionchange', {} as Event, {
type: 'begin',
causedBy: 'gesture',
})
})
// @ts-ignore
map.addEventListener('dragend', () => {
trigger(
'regionchange',
{} as Event,
extend(
{
type: 'end',
causedBy: 'drag',
},
getMapInfo()
)
)
})
} else { } else {
const boundsChangedEvent = event.addListener( const boundsChangedEvent = event.addListener(
map, map,
......
...@@ -127,7 +127,6 @@ export default /*#__PURE__*/ defineSystemComponent({ ...@@ -127,7 +127,6 @@ export default /*#__PURE__*/ defineSystemComponent({
return return
} }
if (getIsBMap()) { if (getIsBMap()) {
console.log('polygon options:', polygonOptions)
// @ts-ignore // @ts-ignore
polygonIns = new maps.Polygon(polygonOptions.path, polygonOptions) polygonIns = new maps.Polygon(polygonOptions.path, polygonOptions)
// @ts-ignore // @ts-ignore
......
lockfileVersion: '6.0' lockfileVersion: '6.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
overrides: overrides:
'@babel/plugin-transform-block-scoping': 7.19.4 '@babel/plugin-transform-block-scoping': 7.19.4
...@@ -10917,7 +10921,3 @@ packages: ...@@ -10917,7 +10921,3 @@ packages:
optionalDependencies: optionalDependencies:
commander: 9.5.0 commander: 9.5.0
dev: true dev: true
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册