我在用诺基亚的地图。我已经看到地图上的控件按钮(切换按钮显示/隐藏流量,切换按钮显示/隐藏公共交通)如果映射位于一个小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>发布于 2014-01-16 14:26:58
标准控件只是-标准控件,在灵活性方面提供的不多,但提供了跨应用程序的一致性。如果您想做其他事情,最好从头开始编写一个自定义组件:
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。
https://stackoverflow.com/questions/21122478
复制相似问题