诺基亚这里是API-V3中的OverlayPanel

时间:2015-03-30 18:33:28

标签: here-api

Nokia-Here API-V3文档告诉我,可以在地图上创建和实现自定义UI控件,如“Button”,“Element”,“Container”等...... 我试了一下,除了H.ui.base.OverlayPanel之外什么都适合我。 我将创建一个由地图上的信息按钮触发的小信息面板。 信息按钮不是问题。 api告诉我,有一个方法(OverlayPanel.pointToControl(control)) 但是对我来说不起作用。有谁能够帮我?谢谢你的回答,对不起我的英文......

1 个答案:

答案 0 :(得分:2)

基本的UI系统没有很好地记录,但根据你想要做什么,你将不得不创建一个控件并将其添加到UI。我摆弄它并找出以下方法来做到这一点:



//Usual setup lines...
var platform = new H.service.Platform({
  app_id: 'DemoAppId01082013GAL',
  app_code: 'AJKnXv84fjrb0KIHawS0Tg',
  useCIT: true
});
var defaultLayers = platform.createDefaultLayers();
//Usual setup lines...
var platform = new H.service.Platform({
  app_id: 'DemoAppId01082013GAL',
  app_code: 'AJKnXv84fjrb0KIHawS0Tg',
  useCIT: true
});
var defaultLayers = platform.createDefaultLayers();
var map = new H.Map(document.getElementById('map'), defaultLayers.normal.map);
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
var ui = H.ui.UI.createDefault(map, defaultLayers);

//OK, so now we have a UI.
//Next thing we'll need is a control
var myCustomControl = new H.ui.Control();
//Also an overlay panel
var myCustomPanel = new H.ui.base.OverlayPanel();
//When the panel is rendered, we add some stuff to it
myCustomPanel.renderInternal = function(el, doc) {
  el.innerHTML = "Oh, hi there!";
  el.style.color = "white";
};

//Also a button that opens the overlay panel on click
// and closes on next click
var myCustomButton = new H.ui.base.PushButton({
  label: "clickme!",
  onStateChange: function(evt) {
    //OK, button state changed... if it's currently down
    if (myCustomButton.getState() == "down") { //or: H.ui.base.Button.State.DOWN)
      //Make sure the panel is positioned right
      myCustomPanel.pointToControl(myCustomControl);
      //... and open
      myCustomPanel.setState("open"); //or: H.ui.base.OverlayPanel.OPEN
    } else {
      //... or close when button is not down
      myCustomPanel.setState("closed"); //or: H.ui.base.OverlayPanel.CLOSED
    }
  }
});
//Add the button and the panel to the control
myCustomControl.addChild(myCustomButton);
myCustomControl.addChild(myCustomPanel);
//Set the position of the control in the UI's layout
myCustomControl.setAlignment("top-right");

//And tadaah
ui.addControl("myCustomControl", myCustomControl);