Here api 这里是Map UI JS-如何向Map UI添加自定义按钮?

Here api 这里是Map UI JS-如何向Map UI添加自定义按钮?,here-api,Here Api,我试图在HERE JS文档中找到关于如何向HERE JS 3.0地图用户界面添加自定义按钮的指导 该按钮将把地图移动到客户当前位置的中心位置(我们提供“此处之外的位置”功能并手动传递)。但是,这需要通过HERE映射本身上的按钮触发。但我不知道如何将按钮附加到地图上(到目前为止,文档只是关于如何自定义现有的UI按钮或如何添加信息气泡): 这可能吗?非常感谢您的帮助 类H.ui.ui应该可以帮助您到达想要到达的地方,特别是addControl(name,control)方法。使用HERE UI k

我试图在HERE JS文档中找到关于如何向HERE JS 3.0地图用户界面添加自定义按钮的指导

该按钮将把地图移动到客户当前位置的中心位置(我们提供“此处之外的位置”功能并手动传递)。但是,这需要通过HERE映射本身上的按钮触发。但我不知道如何将按钮附加到地图上(到目前为止,文档只是关于如何自定义现有的UI按钮或如何添加信息气泡):


这可能吗?非常感谢您的帮助

类H.ui.ui应该可以帮助您到达想要到达的地方,特别是addControl(name,control)方法。使用HERE UI kit可以很容易地按照您想要的方式设计UI元素(即按钮)

我已经编写了以下代码来帮助您实现所需的功能(我假设)

    //#region add new UI element

    inherits = function (childCtor, parentCtor) {
        function tempCtor() { } tempCtor.prototype = parentCtor.prototype; childCtor.superClass_ = parentCtor.prototype; childCtor.prototype = new tempCtor(); childCtor.prototype.constructor = childCtor; childCtor.base = function (me, methodName, var_args) {
            var args = new Array(arguments.length - 2);
            for (var i = 2; i < arguments.length; i++) {
                args[i - 2] = arguments[i];
            }
            return parentCtor.prototype[methodName].apply(me, args);
        };
    };

    var customUI = function (opt_options) {
        'use strict'; var options = opt_options || {};

        H.ui.Control.call(this);
        this.onButtonClick = this.onButtonClick.bind(this);

        // create a button element   
        this.increaseBtn_ = new H.ui.base.Button({
            'label': '<svg class="H_icon H_icon" viewBox="0 0 25 25">' +
                '<path d="M 18.5,11 H 14 V 6.5 c 0,-.8 -.7,-1.5 -1.5,-1.5 -.8,0 -1.5,.7 -1.5,1.5 V 11 H 6' +
                '.5 C 5.7,11 5,11.7 5,12.5 5,13.3 5.7,14 6.5,14 H 11 v 4.5 c 0,.8 .7,1.5 1.5,1.5 .8,0 1.5,' +
                '-.7 1.5,-1.5 V 14 h 4.5 C 19.3,14 20,13.3 20,12.5 20,11.7 19.3,11 18.5,11 z" />' +
                '</svg>',
            'onStateChange': this.onButtonClick
        });

        //add the buttons as this control's children   
        this.addChild(this.increaseBtn_);

        this.setAlignment(options['alignment'] || 'top-right');

        this.options_ = options;
    };
    inherits(customUI, H.ui.Control);

    customUI.prototype.onButtonClick = function (evt) {
        'use strict'; if (evt.currentTarget.getState() === 'down') {
            console.log('Hollla, I am the new custom UI element.');
        }
    };

    var WaliedCheetos_CustomUI = new customUI();
    ui.addControl('WaliedCheetos_CustomUI', WaliedCheetos_CustomUI);

    //#endregion