目录

Map Controls

Map controls are used by users to interact with the map. Map Kit provides various UI controls, including the scale, zoom slider, zoom button, compass, pan button, copyright information, and my-location icon ,as shown in the figure below.

Scale

You can use the scaleControl and scaleControlOptions attributes to specify whether to display the scale and set the scale unit, respectively. The default value of scaleControl is false, indicating that the scale is not displayed. If this attribute is set to true, the scale will be displayed in the lower right corner of the map.
var mapOptions = {};
mapOptions.center = {lat: 48.856613, lng: 2.352222};
mapOptions.zoom = 10;
// Set to display the scale.
mapOptions.scaleControl = true; 
mapOptions.scaleControlOptions = {
	// Set the scale unit to inch. 
	units: "imperial" 
};

Zoom Slider

You can use the zoomSlider attribute to specify whether to display the zoom slider. The default value is false, indicating that the zoom slider is not displayed. If the attribute is set to true, the zoom slider will be displayed in the lower right corner of the map.
var mapOptions = {};
mapOptions.center = {lat: 48.856613, lng: 2.352222};
mapOptions.zoom = 10;
// Set that the zoom slider is displayed.
mapOptions.zoomSlider = true;      

Zoom Button

You can use the zoomControl attribute to specify whether to display the zoom button. The default value is true, indicating that the zoom button is displayed in the lower right corner of the map. If this attribute is set to false, the zoom button will not be displayed.
var mapOptions = {};
mapOptions.center = {lat: 48.856613, lng: 2.352222};
mapOptions.zoom = 10;
// Set that the zoom buttons are not displayed.
mapOptions.zoomControl = false;      

Compass

You can use the rotateControl attribute to specify whether to display the compass. The default value is false, indicating that the compass is not displayed. If this attribute is set to true, the compass will be automatically displayed in the upper right corner of the map when the map does not head north.
var mapOptions = {};
mapOptions.center = {lat: 48.856613, lng: 2.352222};
mapOptions.zoom = 10;
// Set that the compass is displayed.
mapOptions.rotateControl= true;      

Pan Button

You can use the navigationControl attribute to specify whether to display the pan button. The default value is false, indicating that the pan button is not displayed. If the attribute is set to true, the pan button will be displayed in the upper right corner of the map.
var mapOptions = {};
mapOptions.center = {lat: 48.856613, lng: 2.352222};
mapOptions.zoom = 10;
// Set that the pan button is displayed. 
mapOptions.navigationControl= true;       

Copyright

You can use the copyrightControl and copyrightControlOptions attributes to specify whether to display copyright information and customize the copyright information and style. The default value of copyrightControl is false, indicating that the copyright information is not displayed.
var mapOptions = {};
mapOptions.center = {lat: 48.856613, lng: 2.352222};
mapOptions.zoom = 10;
// Set that the copyright information is displayed.
mapOptions.copyrightControl = true;    
// Set the copyright information.
mapOptions.copyrightControlOptions = {value: "<div  style='position: absolute;left:170px;bottom:32px;'><font>Huawei Search © </font><a href='https://developer.huawei.com/consumer/cn/doc/development/HMS-Guides/hms-map-js-base-map'>HMS Map</a><font> contributors</font></div>"}

My-Location Icon

You can use the locationControl attribute to specify whether to display the my-location icon. The default value is false, indicating that the my-location icon is not displayed. If the attribute is set to true, the my-location icon will be displayed in the lower right corner of the map. (This control is supported only in HTML5 browsers.)
var mapOptions = {}; 
mapOptions.center = {lat: 48.856613, lng: 2.352222}; 
mapOptions.zoom = 10; 
// Set that the my-location button is displayed.
mapOptions.locationControl= true;       

The following table describes whether the my-location control is supported on related browsers and platforms.

Browser

Platform

Support My-Location

Chrome 80

Windows

Yes

Chrome 6x

Windows

Yes

Chrome 7x

Windows

Yes

Internet Explorer 10

Windows

No

Internet Explorer 11

Windows

No

Chrome 6x

macOS

Yes

Chrome 7x

macOS

Yes

Chrome 6x

Android

Yes

Chrome 7x

Android

Yes

WeChat V7.X.X (latest version)

Android

Yes

Huawei Browser (EMUI 9.X)

Android

Yes

Huawei Browser (EMUI 10.X)

Android

Partially supported

Safari 12.x

iOS

Partially supported

Safari 13.x

iOS

Yes

Safari 13.x

macOS

Yes

You can set map controls before creating a map, or use the set method to set map controls after creating a map.