Extjs 百度地图扩展
var bmapps;
Bsprint.EditMapInfoWindow = Ext.extend(Ext.Window, {
form: null,
constructor: function () {
this.form = new Ext.form.FormPanel({
plain: true,
baseCls: "x-plain",
labelWidth: 90,
defaults: { allowBlank: false, anchor: "92%", xtype: "textfield" },
keys: [{
key: 13,
fn: this.OnSubmit,
scope: this
}],
items: [{
xtype: "panel",
baseCls: "x-plain",
defaults: { border: false, anchor: "100%", plain: true, baseCls: "x-plain", style: "margin:0px 0px 10px 0px;" },
plain: true,
layout: "table",
layoutConfig: {
columns: 2
},
items: [{
html: "地图精度:",
style: 'text-align:right;margin:0px 0px 10px 0px'
}, {
xtype: "textfield",
allowBlank: false,
id: "TxtLng",
name: "TxtLng",
width: 180
}, {
html: "地图纬度:",
style: 'text-align:right;margin:0px 0px 10px 0px'
}, {
xtype: "textfield",
allowBlank: false,
id: "TxtLat",
name: "TxtLat",
width: 180
}, {
html: "选择公司:",
style: 'text-align:right;margin:0px 0px 10px 0px'
}, {
colspan: "2",
layout: "column",
items: [{
xtype: "textfield",
allowBlank: true,
id: "MapComapny",
blankText: "公司不能为空",
columnWidth: .8
}, {
xtype: "button",
text: "选择",
handler: this.SelectCompany,
scope: this,
width: 48,
columnsWidth: .2
}, { xtype: "hidden", id: "HdMapMemberID"}],
width: 180
},
{
html: "公司名称:",
style: 'text-align:right;margin:0px 0px 10px 0px'
}, {
xtype: "textfield",
allowBlank: false,
id: "TxtCompanyName",
name: "TxtCompanyName",
width: 180
}, {
html: "公司主营:",
style: 'text-align:right;margin:0px 0px 10px 0px'
}, {
xtype: "textarea",
allowBlank: false,
id: "TxtStype",
name: "TxtStype",
height: 40,
width: 194
},
{
html: "公司地址:",
style: 'text-align:right;margin:0px 0px 10px 0px'
}, {
xtype: "textfield",
allowBlank: false,
id: "TxtAddress",
name: "TxtAddress",
width: 180
}, {
html: "联系电话:",
style: 'text-align:right;margin:0px 0px 10px 0px'
}, {
xtype: "textfield",
allowBlank: false,
id: "TxtPhone",
name: "TxtPhone",
width: 180
},
{
html: "联系人:",
style: 'text-align:right;margin:0px 0px 10px 0px'
}, {
xtype: "textfield",
allowBlank: false,
id: "TxtLinkMan",
name: "TxtLinkMan",
width: 180
} ]
}]
});
Bsprint.EditMapInfoWindow.superclass.constructor.call(this, {
title: "编辑标注信息",
modal: true,
collapsible: true,
closeAction: "hide",
width: 400,
shadow: false,
height: 350,
resizable: false,
bodyStyle: "padding:10px",
frame: true,
items: [this.form],
buttons: [{
text: "保存",
icon: "Ext/icon/37.png",
handler: this.OnSubmit,
scope: this
}] });
},
OnLoad: function () {
var record = this["record"];
if (record != undefined && record != null) {
Ext.getCmp("TxtLng").setValue(record.lng);
Ext.getCmp("TxtLat").setValue(record.lat);
}
},
SelectCompany: function () {
if (_selMemberWindow == null) {
_selMemberWindow = new Bsprint.PublicSelMemberWindow(EditMapWindows);
}
_selMemberWindow.show();
},
ReturnData: function () {
var form = this.form.getForm();
var record = this["recordq"];
Ext.getCmp("MapComapny").setValue(record.get("companyname"));
Ext.getCmp("HdMapMemberID").setValue(record.get("id"));
Ext.getCmp("TxtStype").setValue(record.get("stype"));
Ext.getCmp("TxtAddress").setValue(record.get("address"));
Ext.getCmp("TxtPhone").setValue(record.get("phone"));
Ext.getCmp("TxtLinkMan").setValue(record.get("linkman"));
Ext.getCmp("TxtCompanyName").setValue(record.get("companyname"));
},
OnSubmit: function () {
var w = this;
var form = this.form.getForm();
var Lat = Ext.getCmp("TxtLat").getValue(),
Lng = Ext.getCmp("TxtLng").getValue(),
Mid = Ext.getCmp("HdMapMemberID").getValue(),
ise = 0,
Stype = Ext.getCmp("TxtStype").getValue(),
Address = Ext.getCmp("TxtAddress").getValue(),
Phone = Ext.getCmp("TxtPhone").getValue(),
LinkMan = Ext.getCmp("TxtLinkMan").getValue(),
CompanyName = Ext.getCmp("TxtCompanyName").getValue();
var params = {
lat: Lat,
lng: Lng,
mid: Mid,
ise: ise,
stype: Stype,
address: Address,
phone: Phone,
linkman: LinkMan,
companyname:CompanyName
};
loadMask.show();
if (form.isValid()) {
Ext.Ajax.request({
url: "DATA/MapAdd.ashx",
params: params,
success: function (response, options) {
loadMask.hide();
if (response.responseText == "1") {
Ext.Msg.alert("提示", "坐标存入成功!");
w.hide();
}
else if (response.responseText == "-1") {
Ext.Msg.confirm("提示", "已经存在\""+CompanyName+"\"的坐标,数据将会替换数据库原有数据,是否继续?", function (_btn) {//重新请求
if (_btn == "yes") {
options.params.ise = 1;
Ext.Ajax.request(options);
}
}, this);
}
},
failure: function (form, options) {
loadMask.hide();
Ext.Msg.confirm("错误", "验证失败,是否重新验证?", function (_btn) {//重新请求
if (_btn == "yes") {
Ext.Ajax.request(options);
}
}, this);
}
});
} }
});
Bsprint.MapPanel = Ext.extend(Ext.Panel, {
constructor: function () {
Bsprint.MapPanel.superclass.constructor.call(this, {
tbar: ["<font color='red'>步骤:1.右键标注,点击红点完善信息 2.右键点击搜索地址,再完善信息</font>"],
id: "BMAP"
});
},
initComponent: function () {
//测试配置
var defConfig = {
width: 300,
height: 400,
plain: true,
border: false,
zoomLevel: 15,
gmapType: 'map',
ContextMenus: ['放大', '缩小', '放置到最大级', '查看全国', '在此添加标注', { setZoom: '缩小' }, "搜索"],
mapControls: ['NavigationControl', 'ScaleControl', 'OverviewMapControl', 'MapTypeControl'],
x: 104.072206,
y: 30.665474
};
Ext.applyIf(this, defConfig);
Bsprint.MapPanel.superclass.initComponent.call(this);
}
, afterRender: function () {
Bsprint.MapPanel.superclass.afterRender.call(this); //实例地图
this.bmap = new BMap.Map(this.body.dom);
//设置中心位置
this.bmap.centerAndZoom(new BMap.Point(this.x, this.y), this.zoomLevel);
//地图加载完成后加载控件和菜单
this.bmap.addEventListener("tilesloaded", this.onMapReady()); }
, getMap: function () {
return this.bmap;
}
, onMapReady: function () {
//添加地图控件
this.addMapControls();
//添加标注
// this.addMarkers(this.markers);
//添加右击菜单
this.addContextMenus();
this.getMap().enableScrollWheelZoom(); }
, addMapControls: function () {
//根据配置设置地图默认控件
if (this.gmapType === 'map') {
if (Ext.isArray(this.mapControls)) {
for (var i = 0; i < this.mapControls.length; i++) {
this.addMapControl(this.mapControls[i]);
}
} else if (typeof this.mapControls === 'string') {
this.addMapControl(this.mapControls);
} else if (typeof this.mapControls === 'object') {
this.getMap().addControl(this.mapControls);
}
}
}
, addMapControl: function (mc) {
//Check是否是百度地图的事件
var mcf = BMap[mc];
if (typeof mcf === 'function') {
this.getMap().addControl(new mcf());
} }
, addContextMenus: function () {
var contextMenu = new BMap.ContextMenu();
//根据配置设置地图右击菜单
if (Ext.isArray(this.ContextMenus)) {
for (i = 0; i < this.ContextMenus.length; i++) {
contextMenu.addItem(this.addContextMenu(this.ContextMenus[i]));
}
}
this.bmap.addContextMenu(contextMenu);
}
, addContextMenu: function (Menu) {
//var mcf = BMap[mc];
if (typeof Menu === 'string') {
switch (Menu) {
case '放大': return new BMap.MenuItem(Menu, function () { this._map.zoomIn() }, 100)
case '缩小': return new BMap.MenuItem(Menu, function () { this._map.zoomOut() }, 100)
case '放置到最大级': return new BMap.MenuItem(Menu, function () { this._map.setZoom(18) }, 100)
case '查看全国': return new BMap.MenuItem(Menu, function () { this._map.setZoom(4) }, 100)
case '在此添加标注':
return new BMap.MenuItem(Menu, function (p) {
var marker = new BMap.Marker(p), px = this._map.pointToPixel(p);
this._map.addOverlay(marker);
//启动标注可移动
marker.enableDragging(true);
//取得标记坐标
var nPosition = marker.getPosition();
//创建信息窗口)
// var infoWindow = new BMap.InfoWindow(nPosition.lat + ',' + nPosition.lng);
//绑定click事件
marker.addEventListener("click", function () { if (EditMapWindows == null) {
EditMapWindows = new Bsprint.EditMapInfoWindow();
}
var data = { lat: nPosition.lat, lng: nPosition.lng };
//这里的弹出框与我自己定义的Window相关,可以自定义其他方法....
EditMapWindows["record"] = data;
EditMapWindows.show();
EditMapWindows.OnLoad();
// this.openInfoWindow(infoWindow);
//Ext.Msg.alert("提示", nPosition.lng);
});
//移动标注后取坐标
marker.addEventListener("dragend", function () {
nPosition = marker.getPosition();
infoWindow = new BMap.InfoWindow(nPosition.lat + ',' + nPosition.lng);
})
}, 100)
case '搜索':
return new BMap.MenuItem(Menu, function (p) {
bmapps = this;
Ext.MessageBox.prompt("输入框", "请输入详细地址:", function (bu, txt) {
if (bu == "ok") {
var myGeo = new BMap.Geocoder();
myGeo.getPoint(txt, function (point) {
if (point) {
bmapps._map.clearOverlays();
var marker = new BMap.Marker(point);
bmapps._map.centerAndZoom(point, 19);
bmapps._map.addOverlay(marker);
var nPosition = marker.getPosition();
marker.addEventListener("click", function () { if (EditMapWindows == null) {
EditMapWindows = new Bsprint.EditMapInfoWindow();
}
var data = { lat: nPosition.lat, lng: nPosition.lng };
EditMapWindows["record"] = data;
EditMapWindows.show();
EditMapWindows.OnLoad();
// this.openInfoWindow(infoWindow);
//Ext.Msg.alert("提示", nPosition.lng);
});
} else {
Ext.Msg.alert("提示", "无法定位到地址!");
}
}, "");
}
}); });
}
}
}
,
addMarkers: function (markers) {
if (Ext.isArray(markers)) {
for (var i = 0; i < markers.length; i++) {
var mkr_point = new BMap.Point(markers[i].lat, markers[i].lng);
var markerS = new BMap.Marker(mkr_point);
this.addMarker(mkr_point, markerS, false, true, markers[i].listeners);
}
} },
addMarker: function (point, markerS, clear, center, listeners) {
// Ext.applyIf(marker, G_DEFAULT_ICON);
if (clear === true) {
this.getMap().clearOverlays();
}
if (center === true) {
this.getMap().setCenter(point, this.zoomLevel);
}
if (typeof listeners === 'object') {
for (evt in listeners) {
markerS.addEventListener(evt, listeners[evt]);
}
}
this.getMap().addOverlay(markerS);
},
OnSearch: function () {
var tbar = this.getTopToolbar().items;
var text = tbar.itemAt(1).getValue();
var myGeo = new BMap.Geocoder();
myGeo.getPoint(text, function (point) {
if (point) {
var bmap = new BMap.Map(this.body);
this.bmap.clearOverlays(); initlng = point.lng;
initlat = point.lat;
var newPoint;
var myIcon = new BMap.Icon("http://google-maps-icons.googlecode.com/files/walking-tour.png", new BMap.Size(30, 35), {
offset: new BMap.Size(10, 25),
imageOffset: new BMap.Size(0, 0 - 0 * 25)
});
if (initlng == "" || initlat == "") {
newPoint = map.getCenter();
} else {
newPoint = new BMap.Point(newlng, newlat);
}
this.bmap.centerAndZoom(newPoint, bili);
var marker = new BMap.Marker(newPoint, { icon: myIcon });
this.bmap.addOverlay(marker);
} else {
Ext.Msg.alert("提示", "无法定位到地址!");
}
}, "");
}
});
Ext.reg('bmappanel', Ext.ux.BMapPanel);
Extjs 百度地图扩展的更多相关文章
- EChart系列:在echart3中使用百度地图扩展之后,如何获取到百度地图对象
最近做项目想要在百度地图上叠加显示echart的散点图,然后根据地图的缩放等级和区域范围要显示不同的散点图,这中间折腾了好久.功能要求包括: (1)底图使用百度地图: (2)可以在地图上叠加显示ech ...
- sencha touch百度地图扩展
扩展代码如下: Ext.define('ux.BMap', { alternateClassName: 'bMap', extend: 'Ext.Container', xtype: 'bMap', ...
- sencha touch 百度地图扩展(2014-12-17)
上个版本http://www.cnblogs.com/mlzs/p/3666466.html,新增了一些功能,修复了一些bug 扩展代码如下: Ext.define('ux.BMap', { alte ...
- sencha touch 百度地图扩展(2014-6-24)(废弃 仅参考)
扩展代码如下: Ext.define('ux.BMap', { alternateClassName: 'bMap', extend: 'Ext.Container', xtype: 'bMap', ...
- 百度地图结合echarts并添加行政区块
作者:LJaer链接:https://www.zhihu.com/question/49251513/answer/125728764来源:知乎<!DOCTYPE html> <ht ...
- MVC项目中使用百度地图
已经很久没更新博客了,因为最近一直在学习前端的知识,没那么多时间,写博客或者写文章不但没有钱,写得好还好说,如果写得不好,一些吃瓜群众,不仅要喷你,搞不好还要人身攻击就不好了.所以写博客的人,脸皮得厚 ...
- Echarts3.0 引入百度地图(转载)
转载来源: https://blog.csdn.net/yc_1993/article/details/52431989 Echarts3.0引入百度地图 update: 由于目前echarts3.8 ...
- 用百度地图API分析打交通大数据
百度地图API, 文档不全,例子不细致. 在网上还没有太多有用的例子.比如说下面几个需求的解决方案就找不到: 1. 如何用百度地图API查询一个地点的经纬度. 2. 如何用百度地图通过一个经纬度查询商 ...
- ECharts 散点图+百度地图(案例转载)
转载来源:https://efe.baidu.com/blog/echarts-map-tutorial-2/ ECharts 实现地图散点图(下) 小红 2016-06-13 ECharts, ...
随机推荐
- 移动web开发和移动app开发的区分
1.移动web开发 这部分跟web前端开发差别不大,使用的技术都是html+css+js.区别为手机浏览器是webkit的天下,pc端是IE的天 下.手机网页可以理解成pc网页的缩小版加一些触摸特性. ...
- unity官方换装教程Character Customization 学习笔记
1. 下载示例demo,可以直接从AssetsStore上下载,但是速度比较慢,我在github上找了一个据说支持unity5.x的. 链接:https://github.com/spacebeagl ...
- BingHack,Bing旁注API查询工具
现在旁注查询都失效了.通过网上查询发现有人说可以通过微软的API进行旁注查询 https://datamarket.azure.com/dataset/explore/bing/search 注册登录 ...
- c#事件机制
namespace test { class Publisher//出版社 { public delegate void PubComputer(string magazineName);//声明事件 ...
- GC 源码分析
java对象的内存分配入口 Hotspot 源码解析(9) •内存代管理器TenuredGeneration对垃圾对象的回收2015-01-18阅读1154 •内存代管理器DefNewGenerati ...
- 0x00linux32位汇编初入--前期准备
0x00汇编初入--前期准备 一.汇编工具 在linux平台下常用的编译器为as,连接器为ld,使用的文本编辑器为vim,汇编语法为att 以下是一些工具: addr2line 把地址转换为文件名和行 ...
- 基于XML的AOP配置-转
http://www.cnblogs.com/yangy608/archive/2010/11/14/1876839.html AOP(Aspect-Oriented Programming,面向切面 ...
- WebAPI IIS PUT和DELETE请求失败
IIS拒绝PUT和DELETE请求是由于IIS为网站默认注册的一个名为WebDAVModule的自定义HttpModule导致的,如果我们的站点不需要提供针对WebDAV的支持,解决这个问题最为直接的 ...
- Oracle索引失效问题:WHERE C1='' OR C2 IN(SubQuery),并发请求时出现大量latch: cache buffers chains等待
问题描述: 项目反馈某功能响应时间很长,高峰期时系统整体响应很慢... 获取相应的AWR,问题确实比较严重,latch: cache buffers chains等待,因为这些会话SQL执行时间太长, ...
- CSharp 相关知识点小结
1.JS获取iframe下面的内容document.getElementById('IFRAME1').contentDocument; 2.dialog 弹出层,定位:postion:'bottom ...