gpt4 book ai didi

javascript - Sencha Touch : Can't add Marker to Map. 请帮忙?

转载 作者:行者123 更新时间:2023-12-02 20:11:24 25 4
gpt4 key购买 nike

我学习 Sencha Touch 很开心,但在我看来,有些东西应该更简单,否则就会有问题。我现在想做的是添加一个标记以在 map 上显示当前位置

我有一个带有顶部工具栏和选项卡面板的视口(viewport),第一个卡片(选项卡)上有一个 map ,我可以毫无问题地获取当前位置。我遇到的问题是创建指示我所在位置的标记。

我已经在 map 及其父容器上尝试了事件监听器,但仍然无法使其工作。也许是范围问题?!任何帮助将不胜感激...

代码:

Ext.setup({
...
onReady: function() {

var TopBar, Tabs, MapHome, Viewport, Homecard;

/*
* HOME
*/

MapHome = new Ext.Map({
title: 'Map',
useCurrentLocation: true
});


Homecard = new Ext.Panel({
title: "home",
iconCls: "home",
items: [MapHome],
listeners: {
activate: function() {
var marker = new google.maps.Marker({
position: MapHome.map.center,
title : 'testing',
map: MapHome.map
});
}
}
});

/*
* MAIN
*/

TopBar = new Ext.Toolbar({
dock: 'top',
xtype: "toolbar",
title: "<img class='titleLogo' src='css/images/logo.png' />",
items: [

{ xtype: 'spacer' },
{
iconCls: 'settings9',
iconMask: true,
text: 'options'
}
]
});

Tabs = new Ext.TabPanel({
id: 'tabs',
//fullscreen:true,
dock: 'bottom',
flex: 1,
tabBar: {
dock: 'bottom',
layout: {
pack: 'center'
}
},
items: [ Homecard]
});

Viewport = new Ext.Panel({
fullscreen:true,
layout:{type:'vbox',align: 'stretch'},
useLoadMask:true,
ui:'dark',
items: [TopBar,Tabs],
});
}
});

最佳答案

centerchange 的事件监听器是我发现的最佳解决方案。由于我的 map 没有任何交互,这似乎对我有用。

代码如下:

Ext.setup({
fullscreen: true,
tabletStartupScreen: 'splash.png',
phoneStartupScreen: 'splash.png',
icon: 'icon.png',
glossOnIcon: true,
onReady: function() {

var refreshMap = function(themap){
// It should clear all markers first, but that is not important right now since the map has all interaction disabled
var marker = new google.maps.Marker({
position: themap.center,
title : 'testing',
map: themap
});
}


var TopBar, Tabs, MapHome, Viewport, Homecard;

/*
* HOME
*/

MapHome = new Ext.Map({
title: 'Map',
useCurrentLocation: true,
listeners: {
centerchange : function(comp, map){
refreshMap(map);
}
},
mapOptions : {
mapTypeControl : false,
navigationControl : false,
streetViewControl : false,
backgroundColor: 'transparent',
disableDoubleClickZoom: true,
zoom: 17,
draggable: false,
keyboardShortcuts: false,
scrollwheel: false,
mapTypeId: google.maps.MapTypeId.HYBRID
}
});



Homecard = new Ext.Panel({
title: "home",
iconCls: "home",
items: [MapHome]
});

/*
* MAIN
*/

TopBar = new Ext.Toolbar({
dock: 'top',
xtype: "toolbar",
title: "<img class='titleLogo' src='css/images/logo.png' />",
items: [

{ xtype: 'spacer' },
{
iconCls: 'settings9',
iconMask: true,
text: 'options'
}
]
});

Tabs = new Ext.TabPanel({
id: 'tabs',
//fullscreen:true,
dock: 'bottom',
flex: 1,
tabBar: {
dock: 'bottom',
layout: {
pack: 'center'
}
},
items: [ Homecard, Nearbycard, Waypointscard, Shopcard, Searchcard]
});


Viewport = new Ext.Panel({
fullscreen:true,
layout:{type:'vbox',align: 'stretch'},
useLoadMask:true,
ui:'dark',
items: [TopBar,Tabs],
});
}
});

关于javascript - Sencha Touch : Can't add Marker to Map. 请帮忙?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6916904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com