google-maps - 如何创建 ExtJS 谷歌地图?
问题描述
我尝试了下面的代码来创建谷歌地图,但没有奏效。我正在研究 ExtJS 5.2。
这是我的代码:
{
xtype: 'mapPanel',
title: 'Google Map',
align: 'middle',
padding: 10,
pack: 'center',
items: [{
xtype: 'map',
height: 300,
width: 500,
mapConfOpts: ['enableScrollWheelZoom', 'enableDoubleClickZoom', 'enableDragging'],
mapControls: ['GSmallMapControl', 'GMapTypeControl', 'NonExistantControl'],
center: {
geoCodeAddr: '4 Yawkey Way, Boston, MA, 02215-3409, USA',
marker: {
title: 'Fenway Park'
}
},
markers: [{
lat: 42.339641,
lng: -71.094224,
title: 'Boston Museum of Fine Arts',
listeners: {
click: function (e) {
Ext.Msg.alert('It\'s fine', 'and it\'s art.');
}
}
}, {
lat: 42.339419,
lng: -71.09077,
title: 'Northeastern University'
}]
}]
}
任何帮助将不胜感激。提前致谢。
解决方案
在ExtJS 5.x
你需要使用xtype: gmappanel
.
确保在 bootstrap/microloader 之前在 index.html 中包含以下脚本标记:-
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3&sensor=false"></script>
并要求GMapPanel
:
Ext.require('Ext.ux.GMapPanel');
代码片段:
{
xtype: 'gmappanel',
center: {
lat: 22.785639,
lng: 72.549574
},
mapOptions: {
mapTypeId: google.maps.MapTypeId.TERRAIN,
zoom: 6
},
markers: [{
lat: 22.785639,
lng: 72.549574,
title: 'Ahmedabad',
listeners: {
click: function (e) {
Ext.Msg.alert('It\'s fine', 'and it\'s art.');
}
}
}, {
lat: 22.643760,
lng: 75.845472,
title: 'Indore'
}]
}
希望这会帮助/指导你。
推荐阅读
- javascript - 当您将鼠标悬停在图像上时,如何制作跟随您的显示文本效果
- reactjs - 在 REACT.js 中显示一个可回放的视频
- python - 异常类型错误类型错误:异常必须从 BaseException 派生
- python - 史派西“OSError:[E050] 找不到模型‘en_core_web_sm’。它似乎不是 Python 包或数据目录的有效路径。”
- javascript - 对象中的类构造函数可选参数
- r - 在 R 中为三种不同的后验分布添加带有 ggplot 的标签
- python - 如何编写一个在文件中收集值的 Prometheus 导出器?
- visual-studio-code - 如何使用新的 vscode.task 以编程方式创建“dependsOn”任务
- checkbox - 您如何抑制复选框和单选按钮的标准 HTML 5 外观以支持 Ext JS 7 经典中的自定义外观?
- react-native - 如果打开了其他选项卡,请关闭其他选项卡(react-native-collapsible)