诺基亚在这里映射 API



我在这里使用诺基亚地图。我已经看到地图上的控制按钮(切换按钮显示/隐藏交通,切换按钮显示/隐藏公共交通)如果地图在一个小的div容器内出现。有没有办法避免这种行为(例如,通过移动/调整控件大小)?

我已将标准示例代码用于带有组件的基本映射:https://developer.here.com/javascript-apis/enterprise-api-explorer

并将地图放入div中,根据屏幕宽度调整自身大小(这是我的javascript)

<script>
    window.onload=window.onresize=function(){
    $("#bigMapContainerTraff").width($(window).width()-50);
    $("#bigMapContainerTraff").height($(window).height()-50);};
</script>

标准控件就是这样 - 标准控件在灵活性方面没有提供太多,但提供了跨应用程序的一致性。如果你想做其他事情,你最好从头开始编写一个自定义组件:

function extend(B, A) {
    function I() {}
    I.prototype = A.prototype;
    B.prototype = new I();
    B.prototype.constructor = B;
}
var myCustomComponentSimple = function (callback) {
    var myNode = document.createElement("div"); 
    this.callback = callback;   
    this.getId = function() { return "MySimpleCustomComponent"; };  
    this.attach = function(display) {
var myHTML = '<div  id="myCustomComponentButton" style="position: absolute; left: 5px; top: 5px;' +
          'background: #ccc; border: 1px solid #000; padding: 10px;" />';
        myNode.innerHTML = myHTML;
        display.getUIContainer().appendChild(myNode);
        if(!this.button) {
            this.button =  nokia.maps.dom.EventTarget(
                             document.getElementById(
                                     "myCustomComponentButton"));
        }
        this.button.addListener("click", this.callback);
    };
    this.detach = function(display) {
        display.getUIContainer().removeChild(myNode);
        this.button.removeListener("click", this.callback);
    };
    // Call the "super" constructor to initialize properties
    nokia.maps.map.component.Component.call(this);
};
extend(myCustomComponentSimple, 
            nokia.maps.map.component.Component);

var customControl = new myCustomComponentSimple(function(){ 
  alert("doSomething");
    });
    map.components.add(customControl);

简单控件将单个<DIV>注入 DOM 并为 click 事件提供回调函数 - 由于您可以控制此元素的样式,因此您可以根据需要放置它或设置其样式。您可以通过为地图状态添加切换来轻松复制按钮的行为,如此处所述

最新更新