Skip to content

Commit

Permalink
Merge pull request #11562 from toddWang23/feat-locationpicker-hide-co…
Browse files Browse the repository at this point in the history
…ntrol

feat: location picker 增加隐藏控件的参数
  • Loading branch information
allenve authored Feb 7, 2025
2 parents 42b0d75 + b0d74eb commit ccc4744
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
11 changes: 7 additions & 4 deletions packages/amis-ui/src/components/BaiduMapPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface MapPickerProps {
onlySelectCurrentLoc?: boolean;
showSug?: boolean;
showGeoLoc?: boolean;
hideViewControl?: boolean;
mapStyle?: React.CSSProperties;
}

Expand Down Expand Up @@ -138,10 +139,12 @@ export class BaiduMapPicker extends React.Component<
map.centerAndZoom(point, zoom);
}

map.addControl(
// @ts-ignore
new BMap.NavigationControl({type: BMAP_NAVIGATION_CONTROL_SMALL})
);
if (!this.props.hideViewControl) {
map.addControl(
// @ts-ignore
new BMap.NavigationControl({type: BMAP_NAVIGATION_CONTROL_SMALL})
);
}

const geolocationControl = new BMap.GeolocationControl();
geolocationControl.addEventListener('locationSuccess', (e: any) => {
Expand Down
7 changes: 6 additions & 1 deletion packages/amis-ui/src/components/LocationPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface LocationProps extends ThemeProps, LocaleProps {
popOverContainer?: any;
autoSelectCurrentLoc?: boolean;
onlySelectCurrentLoc?: boolean;
hideViewControl?: boolean; // 隐藏地图控件,默认为false,即显示控件
}

export interface LocationState {
Expand Down Expand Up @@ -167,7 +168,8 @@ export class LocationPicker extends React.Component<
ak,
mobileUI,
autoSelectCurrentLoc,
onlySelectCurrentLoc
onlySelectCurrentLoc,
hideViewControl = false
} = this.props;
const __ = this.props.translate;
const {isFocused, isOpened} = this.state;
Expand All @@ -183,6 +185,7 @@ export class LocationPicker extends React.Component<
autoSelectCurrentLoc={autoSelectCurrentLoc}
onlySelectCurrentLoc={onlySelectCurrentLoc}
onChange={this.handleChange}
hideViewControl={hideViewControl}
/>
);
case 'gaode':
Expand Down Expand Up @@ -254,6 +257,7 @@ export class LocationPicker extends React.Component<
autoSelectCurrentLoc={autoSelectCurrentLoc}
onlySelectCurrentLoc={onlySelectCurrentLoc}
onChange={this.handleTempChange}
hideViewControl={hideViewControl}
/>
) : (
<Alert2>{__('{{vendor}} 地图控件不支持', {vendor})}</Alert2>
Expand Down Expand Up @@ -282,6 +286,7 @@ export class LocationPicker extends React.Component<
autoSelectCurrentLoc={autoSelectCurrentLoc}
onlySelectCurrentLoc={onlySelectCurrentLoc}
onChange={this.handleChange}
hideViewControl={hideViewControl}
/>
) : (
<Alert2>{__('{{vendor}} 地图控件不支持', {vendor})}</Alert2>
Expand Down
9 changes: 8 additions & 1 deletion packages/amis/src/renderers/Form/LocationPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export interface LocationControlSchema extends FormBaseControlSchema {
* 备注:区分下现有的placeholder(“请选择位置”)
*/
getLocationPlaceholder?: string;

/**
* 是否隐藏地图控制组件,默认为false
*/
hideViewControl?: boolean;
}

export interface LocationControlProps
Expand Down Expand Up @@ -144,7 +149,8 @@ export class LocationControl extends React.Component<LocationControlProps> {
value,
staticSchema,
ak,
coordinatesType
coordinatesType,
hideViewControl = false
} = this.props;
const __ = this.props.translate;

Expand Down Expand Up @@ -173,6 +179,7 @@ export class LocationControl extends React.Component<LocationControlProps> {
showSug={false}
showGeoLoc={staticSchema.showGeoLoc}
mapStyle={staticSchema.mapStyle}
hideViewControl={hideViewControl}
/>
</>
) : (
Expand Down

0 comments on commit ccc4744

Please sign in to comment.