|
楼主 |
发表于 2016-5-14 20:52:46
|
显示全部楼层
- define(function(require){
- var $ = require("jquery");
- var justep = require("$UI/system/lib/justep");
- var map;
- var Model = function(){
- this.callParent();
- };
- Model.prototype.modelLoad = function(event){
-
- var id = this.getIDByXID("baiduMap");
- var self = this;
- var data=this.comp("statusData");
- window._baiduInit = function() {
- map = new BMap.Map(id,{minZoom:2,enableMapClick:false}); //创建地图对象,可以设置地图缩放最大最小级别,设置是否显示POI点击
- var geoc = new BMap.Geocoder();
-
- //map.centerAndZoom("长春",11); //以城市名称为参数设置地图
- map.centerAndZoom(new BMap.Point(125.276579, 43.852057), 13); //以坐标点为中心设置地图
- //map.addControl(new BMap.MapTypeControl()); //添加地图显示类型控件(地图,卫星图,和3D模型显示)
- //map.disableDragging(); //设置地图禁止拖动
-
- map.enableScrollWheelZoom(true); //设置允许鼠标滚轮缩放地图
- map.enableContinuousZoom(); //设置连续缩放
-
-
- var pointA = new BMap.Point(125.310364,43.873797); // 创建点坐标A
- var pointB = new BMap.Point(125.367928,43.857159); // 创建点坐标B
- var pointC = new BMap.Point(125.319132,43.830163); // 创建坐标C
-
- //alert('从A点到B点的距离是:'+(map.getDistance(pointA,pointB)).toFixed(2)+' 米。'); //获取两点距离,保留小数点后两位
-
-
- //在地图上添加折线
- /* var polyline = new BMap.Polyline([pointA,pointB,pointC], {strokeColor:"red", strokeWeight:4, strokeOpacity:0.5}); //定义折线
- map.addOverlay(polyline); //添加折线到地图上
- */
-
- /* var bs = map.getBounds(); //获取可视区域
- var bssw = bs.getSouthWest(); //拿到可视区域左下角
- var bsne = bs.getNorthEast(); //拿到可视区域右上角
- alert("当前地图可视范围是:" + bssw.lng + "," + bssw.lat + "到" + bsne.lng + "," + bsne.lat);
- */
-
-
- /* setTimeout(function(){
- map.panTo(new BMap.Point(113.262232,23.154345)); //两秒后移动到广州
- }, 2000);
- */
-
- //设置地图显示范围,如果用户在平移地图超过设置区域,会弹回设置区域
- /* var b = new BMap.Bounds(new BMap.Point(125.147942, 43.964754),new BMap.Point(125.550382, 43.806325));
- try {
- BMapLib.AreaRestriction.setBounds(map, b);
- } catch (e) {
- alert(e);
- }
- */
- /* var bottom_right_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT});// 右下角,添加比例尺
- map.addControl(bottom_right_control);
- */
-
-
- //右上角,添加默认缩放平移控件
- /*var top_right_navigation = new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL});
- //BMAP_NAVIGATION_CONTROL_SMALL:仅包含平移和缩放按钮;BMAP_NAVIGATION_CONTROL_PAN:仅包含平移按钮;BMAP_NAVIGATION_CONTROL_ZOOM:仅包含缩放按钮
- map.addControl(top_right_navigation);
- */
-
- // 添加定位控件
- /* var geolocationControl = new BMap.GeolocationControl();
- geolocationControl.addEventListener("locationSuccess", function(e){
- // 定位成功事件
- var address = '';
- address += e.addressComponent.province;
- address += e.addressComponent.city;
- address += e.addressComponent.district;
- address += e.addressComponent.street;
- address += e.addressComponent.streetNumber;
- self.comp("tittle1").set({"title":address});
- });
- geolocationControl.addEventListener("locationError",function(e){
- // 定位失败事件
- alert(e.message);
- });
- map.addControl(geolocationControl);
- */
-
-
- //添加城市列表
- /* var size = new BMap.Size(10, 20); //定义控件偏移量
- map.addControl(new BMap.CityListControl({
- anchor: BMAP_ANCHOR_TOP_LEFT,
- offset: size,
- // 切换城市之间事件
- onChangeBefore: function(){
- alert('城市切换之前事件');
- },
- // 切换城市之后事件
- onChangeAfter:function(){
- alert('城市切换之后事件');
- }
- }));
- */
- /* map.addEventListener("click",function(e){ //增加鼠标点击事件
- //alert(e.point.lng + "," + e.point.lat);
- });
- */
-
- //在地图两点上生成一条路线规划
- /* var myP1 = new BMap.Point(125.283837,43.815675); //起点
- var myP2 = new BMap.Point(125.352396,43.869804); //终点
- var driving2 = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true}}); //驾车实例
- driving2.search(myP1, myP2); //显示一条公交线路
- */
-
- map.addEventListener("click",function(e){ //增加鼠标点击事件
- map.clearOverlays();
- map.addOverlay(new BMap.Marker(new BMap.Point(e.point.lng, e.point.lat))); //增加点
-
- geoc.getLocation(e.point, function(rs){
- var addComp = rs.addressComponents;
-
- data.setValue("curLng",rs.point.lng);
- data.setValue("curLat",rs.point.lat);
- data.setValue("province",addComp.province);
- data.setValue("city",addComp.city);
-
- data.setValue("district",addComp.district);
- data.setValue("street",addComp.street);
- data.setValue("streetNumber",addComp.streetNumber);
- data.setValue("business",rs.business);
- data.setValue("address",rs.address);
- //G("div403").innerHTML = addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber;
-
- self.comp("statusData").setValue("editStatus","查看");
- });
-
- });
-
- function G(id) {
- return document.getElementById(id);
- }
- var ac = new BMap.Autocomplete( //建立一个自动完成的对象
- {"input" : "suggestId",
- "location" : map
- });
-
-
- /* ac.addEventListener("onhighlight", function(e) { //鼠标放在下拉列表上的事件
- var str = "";
- var _value = e.fromitem.value;
- var value = "";
- if (e.fromitem.index > -1) {
- value = _value.province + _value.city + _value.district + _value.street + _value.business;
- }
- str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;
-
- value = "";
- if (e.toitem.index > -1) {
- _value = e.toitem.value;
- value = _value.province + _value.city + _value.district + _value.street + _value.business;
- }
- str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
- G("searchResultPanel").innerHTML = str;
- });*/
-
- var myValue;
- ac.addEventListener("onconfirm", function(e) { //鼠标点击下拉列表后的事件
- var _value = e.item.value;
- myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
- G("searchResultPanel").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
-
- setPlace();
-
- });
-
- function setPlace(){
- map.clearOverlays(); //清除地图上所有覆盖物
- function myFun(){
- var pp = local.getResults().getPoi(0).point; //获取第一个智能搜索的结果
- map.centerAndZoom(pp, 18);
- map.addOverlay(new BMap.Marker(pp)); //添加标注
-
- geoc.getLocation(pp, function(rs){
- var addComp = rs.addressComponents;
-
- data.setValue("curLng",rs.point.lng);
- data.setValue("curLat",rs.point.lat);
- data.setValue("province",addComp.province);
- data.setValue("city",addComp.city);
- data.setValue("district",addComp.district);
- data.setValue("street",addComp.street);
- data.setValue("streetNumber",addComp.streetNumber);
- data.setValue("business",rs.business);
- data.setValue("address",rs.address);
-
- //G("div403").innerHTML = addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber;
- });
- self.comp("statusData").setValue("editStatus","查看");
- }
-
- var local = new BMap.LocalSearch(map, { //智能搜索
- onSearchComplete: myFun
- });
- local.search(myValue);
-
- }
-
- }
- require([ 'http://api.map.baidu.com/api?v=2.0&ak=o9pzum8sF8s3wqodZnt9S5OsKlLdjOil&callback=_baiduInit' ], function() {
- if (window.BMap && window.BMap.Map) {
- window._baiduInit();
- }
- });
- };
- Model.prototype.searchBtnClick = function(event){
- var data=this.comp("statusData");
- alert("当前位置经度: "+data.val("curLng")+"\r当前位置维度:"+data.val("curLat")+"\r当前位置省份:"+data.val("province")+"\r当前位置城市:"+data.val("city")+"\r当前位置县区:"+data.val("district")+"\r当前位置镇级街道:"+data.val("street")+"\r当前位置街道号:"+data.val("streetNumber")+"\r当前位置商业机构:"+data.val("business")+"\r当前位置地址:"+data.val("address"));
- };
-
- Model.prototype.div2Click = function(event){
- this.comp("statusData").setValue("editStatus","编辑");
- };
-
- return Model;
- });
复制代码 |
|