AMap_wev8.js 7.34 KB
define("AMap_html",function(){return'<div id="NMEC_${id}" class="wev-comp-${compType}" >\t<div style="height:${realHeight}px;"></div></div>'}),define(["mUtil","Component","amap"],function(c,i){return i.init(function(e){var l,d,p={},s={};i.super(this,e),this.type="AMap",this.tpl=this.type+"_html",this.css=this.type+"_css";var o="CURRENT_LOCATION",r="/mobilemode/mobile/images/plugin/start.png",f=this.viewModel={type:"2",centerPoint:{address:o,coordinateType:-1},additionalPointType:1,apiConfig:{api:{},params:{query:[],body:{}}},additionalPoint:{enabled:!1,coordinateType:1,additionalRadius:"",coordinates:[],showLabel:!0,isConnection:0},height:200,zoomLevel:18,standalone:!0};this.beforeMount=function(){if(/^\d+%$/g.test(f.height)){var e=this.$container.height(),i=parseFloat(f.height)/100;f.realHeight=e*i}else c.isFunction(f.height)?f.height=f.height():f.height=parseFloat(f.height);f.realHeight||(f.realHeight=f.height)},this.mounted=function(){d=$(".wev-comp-"+this.type+" > div",this.$el);var e=f.type,i=f.centerPoint.address,n=f.centerPoint.coordinateType;p.getCenterPointCoordinate(e,i,n,function(e){var i=l=new AMap.Map(d[0],{resizeEnable:!0,zoom:f.zoomLevel,center:e});if("3"!==f.type){var n="/mobilemode/mobile/images/plugin/current-location.png",t={};f.centerIcon&&"1"==f.iconType&&(n=f.centerIcon),"3"==f.additionalPoint.isConnection&&(t={size:new AMap.Size(19,30),image:r,imageSize:new AMap.Size(19,30),imageOffset:new AMap.Pixel(0,0)}),i.add(new AMap.Marker({position:e,icon:new AMap.Icon($.extend({size:new AMap.Size(40,40),image:n,imageSize:new AMap.Size(40,40),imageOffset:new AMap.Pixel(0,0)},t)),offset:new AMap.Pixel(-20,-35)}))}if(f.additionalPoint.enabled){p.getAdditionalPoints({lng:e[0],lat:e[1]});var a=function(e){var i=$(this).data("id");d.find(".amap-marker-label").removeClass("selected"),$(this).closest(".amap-marker-label").addClass("selected");var n=f.additionalPoint.click;n&&n(s[i]),e&&e.stopPropagation()};d.on("click",".amap-label-content",function(e){a.call(this,e)}),d.on("touchstart",".amap-label-content",function(e){a.call(this,e)})}})},p.addMarker=function(t,e,a,i){var o=this;if(t&&t.lng&&t.lat){var r=$.extend({},i);p.convertCoordinate([t.lng,t.lat],e,function(e){var i=new AMap.Marker({position:e,icon:new AMap.Icon($.extend({size:new AMap.Size(30,30),image:"/mobilemode/mobile/images/plugin/location.png",imageSize:new AMap.Size(30,30),imageOffset:new AMap.Pixel(0,0)},r)),offset:new AMap.Pixel(-15,-25)});if(l.add(i),i.on("click",function(){this.Mg&&(d.find(".amap-marker-label").removeClass("selected"),$(this.Mg.contentDom).siblings(".amap-marker-label").addClass("selected")),a&&c.eval(a,o.pageid,t)}),f.additionalPoint.showLabel){var n=c.UUID();(s[n]=t).name&&i.setLabel({offset:r&&r.labelOffset||new AMap.Pixel(15,-25),content:"<div class='amap-label-content' data-id='"+n+"'>"+t.name+"</div>"})}})}else c.getLabel(5296,"经纬度:#ADDR# 格式错误!",function(e){c.console.error(e.replace("#ADDR#",address))})},p.addMarkers=function(e,i,n){if("3"==f.additionalPoint.isConnection){var t={size:new AMap.Size(19,30),imageSize:new AMap.Size(19,30),imageOffset:new AMap.Pixel(0,0),labelOffset:new AMap.Pixel(10,-25)};p.addMarker(e[e.length-1],i,f.additionalPoint.click,$.extend(t,{image:"/mobilemode/mobile/images/plugin/end.png"}));var a=e.slice(0,e.length-1);"3"==f.type&&1<e.length&&(p.addMarker(e[0],i,f.additionalPoint.click,$.extend(t,{image:r})),a=e.slice(1,e.length-1)),c.isArray(a)&&a.forEach(function(e){p.addMarker(e,i,f.additionalPoint.click,$.extend(t,{image:"/mobilemode/mobile/images/plugin/mid.png"}))})}else c.isArray(e)&&e.forEach(function(e){p.addMarker(e,i,f.additionalPoint.click)});"0"!=f.additionalPoint.isConnection&&p.connectAdditionalPoints(e,i)},p.convertCoordinate=function(i,n,t){1===n?t&&t(i):require(["amapHelper"],function(e){e.convertPoint(i,n,function(e){t&&t(e)})})},p.getCenterPointCoordinate=function(e,i,n,t){if(-1==n){if(i==o||"3"==e)return Mobile_NS.getCurrPosition(function(e){f.centerPoint.lng=e.lng,f.centerPoint.lat=e.lat,"function"==typeof t&&t([e.lng,e.lat])});require(["amapHelper"],function(e){e.getPosition(i,function(e){f.centerPoint.lng=e[0],f.centerPoint.lat=e[1],"function"==typeof t&&t(e)})})}else{var a=i.split(",");if(2!=a.length)return void c.getLabel(5296,"经纬度:#ADDR# 格式错误!",function(e){c.console.error(e.replace("#ADDR#",i))});p.convertCoordinate([a[0],a[1]],n,function(e){f.centerPoint.lng=e[0],f.centerPoint.lat=e[1],"function"==typeof t&&t(e)})}},p.getAdditionalPoints=function(e){if("1"==f.additionalPointType){if(!f.standalone){var i=c.getActionUrl(this.type,{action:"getAdditionalPoints",mec_id:this.id,lng:e.lng,lat:e.lat,additionalRadius:f.additionalPoint.additionalRadius},this.pageid);return c.getJSON(i,function(e){p.addMarkers(e.datas,f.additionalPoint.coordinateType,f.additionalPoint.click)})}var n=f.additionalPoint.coordinates;if(c.isFunction(n))return n(e,function(e){p.addMarkers(e,f.additionalPoint.coordinateType,f.additionalPoint.click)})}else"2"==f.additionalPointType&&require(["apiHelper"],function(e){queryParams={},f.apiConfig.params.query.forEach(function(e){queryParams[e.name]=e.value}),e.callApi(f.apiConfig,queryParams,function(e){if("1"==e.status){var c=[];e.data.reduce(function(e,s){return e.then(function(){var d=$.Deferred();return"3"!=f.type&&""!=f.additionalPoint.additionalRadius?p.convertCoordinate([s.lng,s.lat],f.additionalPoint.coordinateType,function(e){var i,n,t,a,o,r,l;i=[f.centerPoint.lng,f.centerPoint.lat],n=e,t=i[1]*Math.PI/180,a=n[1]*Math.PI/180,o=t-a,r=i[0]*Math.PI/180-n[0]*Math.PI/180,l=2*Math.asin(Math.sqrt(Math.pow(Math.sin(o/2),2)+Math.cos(t)*Math.cos(a)*Math.pow(Math.sin(r/2),2))),l*=6378137,(l=Math.round(1e4*l)/1e4)<=f.additionalPoint.additionalRadius&&c.push(s),d.resolve()}):(c.push(s),d.resolve()),d})},$.Deferred().resolve()).then(function(){p.addMarkers(c,f.additionalPoint.coordinateType,f.additionalPoint.click)})}},function(e){console.error(e)})})},p.connectAdditionalPoints=function(e,t){var a=[];"3"!=f.type&&a.push([f.centerPoint.lng,f.centerPoint.lat]),c.isArray(e)&&e.reduce(function(e,n){return e.then(function(){var i=$.Deferred();return p.convertCoordinate([n.lng,n.lat],t,function(e){a.push(e),i.resolve()}),i})},$.Deferred().resolve()).then(function(){if(!(a.length<2))if("1"==f.additionalPoint.isConnection){var n=[];a.forEach(function(e){var i={O:e[1],P:e[0],lat:e[1],lng:e[0]};n.push(i)}),new AMap.Polyline({path:n,isOutline:!0,outlineColor:"#ffeeee",borderWeight:2,strokeWeight:5,strokeColor:"#0091ff",lineJoin:"round"}).setMap(l)}else"2"==f.additionalPoint.isConnection?AMap.plugin("AMap.Walking",function(){var n=new AMap.Walking({autoFitView:!0});a.reduce(function(e,i){return n.search(e,i,function(e,i){var n,t;"complete"===e?i.routes&&i.routes.length&&(n=i.routes[0],t=function(e){for(var i=[],n=0,t=e.steps.length;n<t;n++)for(var a=e.steps[n],o=0,r=a.path.length;o<r;o++)i.push(a.path[o]);return i}(n),new AMap.Polyline({path:t,isOutline:!0,outlineColor:"#ffeeee",borderWeight:2,strokeWeight:5,strokeColor:"#0091ff",lineJoin:"round"}).setMap(l)):console.error("步行路线数据查询失败"+i)}),i})}):"3"==f.additionalPoint.isConnection&&AMap.service("AMap.Driving",function(){var e=new AMap.Driving({map:l,autoFitView:!0,hideMarkers:!0}),i=a[0],n=a[a.length-1],t=a.slice(1,a.length-1);e.search(i,n,{waypoints:t},function(e,i){"complete"!==e&&console.error("获取驾车数据失败:"+i)})})})},p.getAdditionalPoints=p.getAdditionalPoints.bind(this),p.addMarker=p.addMarker.bind(this)})});