Skip to content

Commit

Permalink
fix: Fix map.remove report errors. #11
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Sep 29, 2020
1 parent dae3d4f commit cc4d59d
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/BezierCurve/useBezierCurve.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const useBezierCurve = (props = {} as UseBezierCurve) => {
setBezierCurve(instance);
return () => {
if (instance) {
map && map.remove(instance);
map && map.removeLayer(instance);
setBezierCurve(undefined);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/CircleMarker/useCircleMarker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const useCircleMarker = (props = {} as UseCircleMarker) => {
setCircleMarker(instance);
return () => {
if (instance) {
map && map.remove(instance);
map && map.removeLayer(instance);
setCircleMarker(undefined);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ellipse/useEllipse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const useEllipse = (props = {} as UseEllipse) => {
setEllipse(instance);
return () => {
if (instance) {
map && map.remove(instance);
map && map.removeLayer(instance);
setEllipse(undefined);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/HawkEyeControl/useHawkEyeControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ export function useHawkEyeControl(props = {} as UseHawkEyeControl) {
});

return () => {
if (instance && map && map.remove) {
map.remove(instance);
if (instance && map) {
map.removeLayer(instance);
setHawkEyeControl(undefined);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Map/useMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const useMap = (props: UseMap = {}) => {
}
return () => {
if (instance) {
instance.destroy();
setMap(undefined);
// instance.destroy();
}
}
}, [container]);
Expand Down
23 changes: 13 additions & 10 deletions src/Polygon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,19 @@ const Example = () => {
</button>
<div style={{ width: '100%', height: '500px' }}>
<Map zoom={14} center={[116.400274, 39.905812]}>
<Polygon
visiable={show}
path={path}
strokeColor="#FF33FF"
strokeWeight={6}
strokeOpacity={0.2}
fillOpacity={0.4}
fillColor="#1791fc"
zIndex={50}
/>
{show && (

<Polygon
// visiable={show}
path={path}
strokeColor="#FF33FF"
strokeWeight={6}
strokeOpacity={0.2}
fillOpacity={0.4}
fillColor="#1791fc"
zIndex={50}
/>
)}
</Map>
</div>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/Polygon/usePolygon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const usePolygon = (props = {} as UsePolygon) => {
setPolygon(instance);
return () => {
if (instance) {
map && map.remove(instance);
map && map.removeLayer(instance);
setPolygon(undefined);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Polyline/usePolyline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function usePolyline(props = {} as UsePolyline) {
setPolyline(instance);
return () => {
if (instance) {
map && map.remove(instance);
map && map.removeLayer(instance);
setPolyline(undefined);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rectangle/useRectangle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const useRectangle = (props = {} as UseRectangle) => {
setRectangle(instance);
return () => {
if (instance) {
map && map.remove(instance);
map && map.removeLayer(instance);
setRectangle(undefined);
}
}
Expand Down
34 changes: 23 additions & 11 deletions src/types/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,6 @@ declare namespace AMap {
* @param duration 如果使用动画过度,动画过度的时长控制,单位 ms,默认值是内部自动计算的一个动态值。
*/
panBy(x: number, y: number, duration?: number): void;
/**
* 从地图上移除图层
* @param layer 地图图层
*/
removeLayer(layer: TileLayer | Satellite | Traffic | RoadNet): void;
/**
* 将多个图层一次替代地图上原有图层,会移除地图原有图层
* @param layers 地图图层数组
*/
setLayers(layers:Array<TileLayer | Satellite | Traffic | RoadNet>): void;
/**
* 获取地图图层数组,数组为一个或多个图层
* @returns 地图图层数组
Expand All @@ -130,6 +120,28 @@ declare namespace AMap {
* @param cursor 设置鼠标指针默认样式,参数cursor应符合CSS的cursor属性规范。可为CSS标注中的光标样式, 如:setCursor(“pointer”)等;或者自定义的光标样式, 如:setCursor("url(' https://lbs.amap.com/webapi/static/Images//0.png' ),pointer")
*/
setDefaultCursor(cursor): void;
/**
* 从地图上移除图层
* @param layer 地图图层
*/
removeLayer(layer:
TileLayer |
Polygon |
Polyline |
BezierCurve |
Satellite |
Rectangle |
Traffic |
Ellipse |
HawkEye |
CircleMarker |
RoadNet
): void;
/**
* 将多个图层一次替代地图上原有图层,会移除地图原有图层
* @param layers 地图图层数组
*/
setLayers(layers:Array<TileLayer | Satellite | Traffic | RoadNet>): void;
/**
* 添加覆盖物/图层。参数为单个覆盖物/图层,或覆盖物/图层的数组。
* @param features 覆盖物对象或者数组 VectorOverlay | Array<any>
Expand All @@ -139,7 +151,7 @@ declare namespace AMap {
* 删除覆盖物/图层。参数为单个覆盖物/图层,或覆盖物/图层的数组。
* @param features Array<any> | VectorOverlay
*/
remove(features: Array<any> | TileLayer | Polyline | HawkEye | Marker | Rectangle | Polygon | InfoWindow | Ellipse | BezierCurve | CircleMarker | Circle): void;
remove(features: Array<any> | TileLayer | HawkEye | Marker | InfoWindow | Circle): void;
/**
* 注销地图对象,并清空地图容器
*/
Expand Down

0 comments on commit cc4d59d

Please sign in to comment.