首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >诺基亚地图api

诺基亚地图api
EN

Stack Overflow用户
提问于 2014-01-14 19:40:35
回答 1查看 862关注 0票数 1

我在用诺基亚的地图。我已经看到地图上的控件按钮(切换按钮显示/隐藏流量,切换按钮显示/隐藏公共交通)如果映射位于一个小div容器中的话,就会出现这个按钮。是否有办法避免这种行为(例如,通过移动/调整控件大小)?

我使用了包含组件的基本映射的标准示例代码:https://developer.here.com/javascript-apis/enterprise-api-explorer

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

代码语言:javascript
复制
<script>
    window.onload=window.onresize=function(){
    $("#bigMapContainerTraff").width($(window).width()-50);
    $("#bigMapContainerTraff").height($(window).height()-50);};
</script>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-16 14:26:58

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

代码语言:javascript
复制
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);

简单的控件向DOM中注入一个<DIV>,并为click事件提供一个回调函数--因为您可以控制这个元素的样式,所以您可以将它放置在或者样式上。您可以很容易地复制按钮的行为,方法是为映射的状态添加一个按钮,如所述的here

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21122478

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档