AMap_wev8.js 32.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
if(typeof(MEC_NS) == 'undefined'){
	MEC_NS = {};
}

MEC_NS.AMap = function(type, id, mecJson){
	this.type = type;
	if(!id){
		id = new UUID().toString();
	}
	this.id = id;
	if(!mecJson){
		mecJson = this.getDefaultMecJson();
	}
	this.mecJson = mecJson;
	this.amap = null;
};

/*获取id。 必需的方法*/
MEC_NS.AMap.prototype.getID = function(){
	return this.id;
};

MEC_NS.AMap.prototype.runWhenPageOnLoad = function(){
	this.afterDesignHtmlBuild();
};

/*获取设计的html, 页面上怎么显示控件完全依赖于此方法。 必需的方法*/
MEC_NS.AMap.prototype.getDesignHtml = function(){
	return getDesignHtml(this);
};

/*页面上显示控件完成后调用此方法,主要用于一些必须要使用js对页面进行后置操作时,无需要此方法可至空。 不必需的方法,有此方法系统自动调用*/
MEC_NS.AMap.prototype.afterDesignHtmlBuild = function(){
	var $con = $("#NMEC_" + this.id);

	$con.children("div").attr("id", "mapContainer_" + this.id);
	this.buildMap();
};

MEC_NS.AMap.prototype.buildMap = function(){
    var that = this, 
        theId = this.id;
    
	var zoomLevel = parseInt(this.mecJson["zoomLevel"]);
	
	var createMapAndAddPoint = function(point){
	    var amap = new AMap.Map("mapContainer_" + theId, {
	        resizeEnable: true, //是否监控地图容器尺寸变化
	        zoom: zoomLevel,
	        center: point
	    });
	    if(that.mecJson.type != '3'){
            var centerIcon = '/mobilemode/mobile/images/plugin/current-location.png';
            if(that.mecJson.centerIcon && that.mecJson.iconType == '1'){
                centerIcon = that.mecJson.centerIcon;
            }
            amap.add(new AMap.Marker({
                position: point,
                icon: new AMap.Icon({
                    size: new AMap.Size(40, 40),
                    image: centerIcon,
                    imageSize: new AMap.Size(40, 40),
                    imageOffset: new AMap.Pixel(0, 0)
                }),
                offset: new AMap.Pixel(-20, -35)
            }));
        }
	};
	/**
	 * @param lnglat [121.5222556500,31.0824170200](gps坐标泛微)
	 * @param type 类型为gps、baidu
	 */
	var convertFrom = function(lnglat, type, callback){
	    AMap.convertFrom(lnglat, type, function (status, result) {
	        if (result.info === 'ok') {
	            var resLnglat = result.locations[0];
	            callback && callback([resLnglat.lng, resLnglat.lat]);
	        }else{
	            console.error("坐标转换失败!");
	        }
        });
	};
	
	if(this.mecJson.type == "1"){  //指定位置
        if(this.mecJson.addrType == "1"){   //中文地址
			var isMatchedAddress = function(addr, formmatedAddr){
				var j = 0;
				for(var i = 0; i < addr.length; i++){
					if(~formmatedAddr.indexOf(addr.charAt(i))){
						j++;
						if(j >= formmatedAddr.length / 2)  return true;
					}
				}
				return false;
			}
			AMap.plugin('AMap.Geocoder', function(){
				var geocoder = new AMap.Geocoder();
				geocoder.getLocation(that.mecJson.address, function(status, result){
					if(status === 'complete' && result.geocodes.length){
						var formattedAddress = result.geocodes[0].formattedAddress;
						if(!isMatchedAddress(that.mecJson.address, formattedAddress)){
							return;
						}
						var poi = result.geocodes[0].location;
						createMapAndAddPoint([poi.lng, poi.lat]);
					}else{
						console.error("地址没有解析结果!");
					}
				});
			});
        }
        else if(this.mecJson.addrType == "2"){  //坐标
            var pointArr = this.mecJson.address.split(",");
            if (pointArr.length != 2) {
                return console.error("经纬度格式错误!");
            }
            var point = [pointArr[0], pointArr[1]];
            var coordinateType = this.mecJson.coordinateType;
            if(coordinateType == "1"){
                createMapAndAddPoint(point);
            }else{
                convertFrom(point, coordinateType == "2" ? "baidu" : "gps", function(data){
                    createMapAndAddPoint(data);
                });
            }
        }
    }else if(this.mecJson.type == "2" || this.mecJson.type == '3'){  //当前位置  无
		var that = this;
        AMap.plugin('AMap.Geolocation', function() {
            var geolocation = new AMap.Geolocation({
                enableHighAccuracy: true,//是否使用高精度定位,默认:true
                buttonPosition:'RB',    //定位按钮的停靠位置
                buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
                zoomToAccuracy: true,   //定位成功后是否自动调整地图视野到定位点
            });
            geolocation.getCurrentPosition(function(status,result){
                if(status === 'complete'){
                    createMapAndAddPoint([result.position.lng, result.position.lat]);
                }else{
                    AMap.plugin('AMap.CitySearch', function(){
                        var citysearch = new AMap.CitySearch();
                        citysearch.getLocalCity(function(status, result) {
                            if (status === 'complete' && result.info === 'OK' && result.bounds) {
                                var bounds = result.bounds;
                                var lng1 = bounds.northeast && bounds.northeast.P;
                                var lng2 = bounds.southwest && bounds.southwest.P;
                                var lat1 = bounds.northeast && bounds.northeast.O;
                                var lat2 = bounds.southwest && bounds.southwest.O;
                                var lng = (lng1 + lng2) / 2;
                                var lat = (lat1 + lat2) / 2;
                                that.mecJson.type = '3';
                                createMapAndAddPoint([lng, lat]);
                            } else {
                                console.error(result.info);
                            }
                        });
                    });
                }
            });
        });
    }
};

/*获取构建属性编辑窗体的html,添加和单击控件后会调用此方法,由此方法去构建属性编辑窗体。 必需的方法*/
MEC_NS.AMap.prototype.getAttrDlgHtml = function(){
	var styleL = "_style" + _userLanguage;

	var addrTip = "";
	if(_userLanguage=="8"){
		addrTip = "The address can be:&#10;1. fixed address or coordinate;&#10;2.get page parameters, such as {addr}&#10;3. data set reference, such as {data.addr}.";
	}else if(_userLanguage=="9"){
		addrTip = "該地址可以是:&#10;1.固定地址或座標,如:上海市xx區xx路&#10;2.獲取頁面參數,如:{addr}&#10;3.數据集引用,如:{data.addr}";
	}else{
		addrTip = "该地址可以是:&#10;1. 固定地址或坐标,如:上海市xx区xx路&#10;2. 获取页面参数,如:{addr}&#10;3. 数据集引用, 如:{data.addr}";
	}
	var theId = this.id;
	
	var htm = "<div id=\"MADM_"+theId+"\" style=\"padding-bottom: 10px;\">"
					+ "<div class=\"title\">"+SystemEnv.getHtmlNoteName(4854)+"</div>"//中心点信息
					+ "<div class=\"form-group\">"
						+ "<div class=\"row\">"
							+ "<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(4836)+"</span>"  //取值类型:
							+ "<span class=\"col-m-8 multi-checkbox\">"
								+ "<span>"
									+ "<input type=\"checkbox\" name=\"type_"+theId+"\" value=\"1\" onclick=\"MADAMap_ChangeType(this, '"+theId+"');\"/><span class=\"cbboxLabel\">"+SystemEnv.getHtmlNoteName(4837)+"</span>"  //指定地址
								+ "</span>"
								+ "<span>"
									+ "<input type=\"checkbox\" name=\"type_"+theId+"\" value=\"2\" onclick=\"MADAMap_ChangeType(this, '"+theId+"');\"/><span class=\"cbboxLabel\">"+SystemEnv.getHtmlNoteName(4838)+"</span>" //当前位置
								+ "</span>"
								+ "<span>"
									+ "<input type=\"checkbox\" name=\"type_"+theId+"\" value=\"3\" onclick=\"MADAMap_ChangeType(this, '"+theId+"');\"/><span class=\"cbboxLabel\">"+SystemEnv.getHtmlNoteName(4168)+"</span>" //无
								+ "</span>"
							+ "</span>"
						+ "</div>"
						
						+ "<div class=\"typeContent\" id=\"typeContent_"+theId+"_1\" style=\"display: none;\">"
							+ "<div class=\"row\">"
								+ "<span class=\"col-2 span-control\" style=\"vertical-align: top;\">"+SystemEnv.getHtmlNoteName(4212)+"</span>"  //地址:
								+ "<div class=\"col-m-8\"><textarea class=\"area-control\" style=\"height:84px;\" data-autobind='address' id=\"address_"+theId+"\" placeholder=\""+addrTip+"\">"+this.mecJson["address"]+"</textarea></div>"
							+ "</div>"
							
							+ "<div class=\"row\">"
								+ "<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(4839)+": </span>"  //地址类型:
								+ "<span class=\"col-m-8 multi-checkbox\">"
									+ "<span>"
										+ "<input type=\"checkbox\" name=\"addrType_"+theId+"\" value=\"1\" onclick=\"MADAMap_ChangeAddrType(this, '"+theId+"');\"/><span class=\"cbboxLabel\">"+SystemEnv.getHtmlNoteName(4840)+"</span>"  //中文地址
									+ "</span>"
									+ "<span>"
										+ "<input type=\"checkbox\" name=\"addrType_"+theId+"\" value=\"2\" onclick=\"MADAMap_ChangeAddrType(this, '"+theId+"');\"/><span class=\"cbboxLabel\">"+SystemEnv.getHtmlNoteName(4841)+"</span>" //坐标 (格式:经度,纬度)
									+ "</span>"
								+ "</span>"
							+ "</div>"
							
							+ "<div class=\"addrTypeContent\" id=\"addrTypeContent_"+theId+"_2\" style=\"display: none;\">"
								+ "<div class=\"row\">"
									+ "<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(4842)+"</span>"  //坐标类型:
									+ "<span class=\"col-m-8 multi-checkbox\">"
										+ "<span>"
											+ "<input type=\"checkbox\" name=\"coordinateType_"+theId+"\" value=\"1\"/><span class=\"cbboxLabel\">"+SystemEnv.getHtmlNoteName(4843)+"</span>"  //高德/腾讯
										+ "</span>"
										+ "<span>"
											+ "<input type=\"checkbox\" name=\"coordinateType_"+theId+"\" value=\"2\"/><span class=\"cbboxLabel\">"+SystemEnv.getHtmlNoteName(4844)+"</span>" //百度
										+ "</span>"
										+ "<span>"
											+ "<input type=\"checkbox\" name=\"coordinateType_"+theId+"\" value=\"3\"/><span class=\"cbboxLabel\">GPS</span>" 
										+ "</span>"
									+ "</span>"
								+ "</div>"
							+ "</div>"	
							
						+ "</div>"
						+ "<div id=\"addrIcon_"+theId+"\" class=\"row\">"
							+ "<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(4111)+": </span>"  //图标:
							+ "<div class=\"col-m-8\" style=\"width:80px;\">"
								+ "<select id=\"iconType_"+theId+"\" class=\"form-control\" data-autobind onchange=\"MADAMap_ChangeIcon('"+theId+"')\">"
									+ "<option value=\"0\">"+SystemEnv.getHtmlNoteName(3773)+"</option>"
									+ "<option value=\"1\">"+SystemEnv.getHtmlNoteName(3916)+"</option>"
								+ "</select>"
							+ "</div>"
							+ "<div class=\"col-m-8\" style=\"width: calc(100% - 65px - 80px);padding-left:8px;\">"
								+ "<div class=\"icon-set-wrap\" style=\"display:none;\" id=\"centerIcon_"+theId+"\" onclick=\"MADAMap_PicSet('','"+theId+"');\">"
									+ "<div class=\"icon-set-delete\" onclick=\"MADAMap_SetPicPath('','"+theId+"','');\"></div>"
									+ "<img class=\"icon-set-img\"/>"
									+ "<input type=\"hidden\" />"
						    	+ "</div>"
							+ "</div>"
						+ "</div>"

					+ "</div>"
					+ "<div class=\"title\">"+SystemEnv.getHtmlNoteName(4845)+"</div>"//附加点信息
					+ "<div class=\"form-group\">"
						+ "<div class=\"row\">"
							+ "<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(4836)+"</span>"  //取值类型:
							+ "<span class=\"col-m-8 multi-checkbox\">"
								+ "<span>"
									+ "<input type=\"checkbox\" name=\"additionalPointType_"+theId+"\" value=\"1\" onclick=\"MADAMap_ChangeAdditionalPointType(this, '"+theId+"');\"/><span class=\"cbboxLabel\">SQL</span>"  //SQL
								+ "</span>"
								+ "<span>"
									+ "<input type=\"checkbox\" name=\"additionalPointType_"+theId+"\" value=\"2\" onclick=\"MADAMap_ChangeAdditionalPointType(this, '"+theId+"');\"/><span class=\"cbboxLabel\">"+SystemEnv.getHtmlNoteName(5268)+"</span>" //接口
								+ "</span>"
							+ "</span>"
						+ "</div>"
						+ "<div id=\"additionalPointType_"+theId+"_1\" class=\"mb-8 additionalPointType\">"
							+ "<div class=\"row title2\">"
								+ "<div class=\"col-8\" style=\"padding-left:2px;vertical-align: bottom;\">"+SystemEnv.getHtmlNoteName(4846)+":</div>"//附加点SQL
								+ "<div class=\"col-4\">"
									+"<select class=\"form-control\" id=\"datasource_"+theId+"\">"
										+"<option value=\"\">(local)</option>"
									+"</select>"
								+"</div>"
							+ "</div>"
							+ "<div style=\"position:relative;\">"
								+ "<textarea id=\"additionalSql_"+theId+"\" class=\"area-control\" placeholder=\""+SystemEnv.getHtmlNoteName(4852)+"\"></textarea>"//请在此处输入查询附加点的SQL语句
								+ "<div class=\"helper sqlhelper\" for=\"sql\">?</div>"
							+ "</div>"
						+ "</div>"
						+ "<div id=\"additionalPointType_"+theId+"_2\" class=\"mb-8 additionalPointType\" style=\"display: none;\">"
							+ "<div class=\"row\">"
								+ "<div class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(5239)+"</div>"		//选择接口
								+ "<div class=\"col-m-8\">"
									+ "<div class=\"col api-browser pd-4 edit-before\" id=\"api-browser_"+theId+"\" style=\"width:20px;text-align:left;\"></div>"
									+ "<div class=\"col ml-5 pd-7 link\" id=\"api-name_"+theId+"\"></div>"
								+ "</div>"
							+ "</div>"
							+ "<div class=\"row tip-control\" style=\"position: relative; display: block;\">"
								+ SystemEnv.getHtmlNoteName(6017)+"<br/>"
								+ "{<br/>"
									+ "&nbsp;&nbsp;&nbsp;&nbsp;\"status\":\"1\", <br/>"
									+ "&nbsp;&nbsp;&nbsp;&nbsp;\"data\": [<br/>"
											+ "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{\"lng\": \"234.87653\", \"lat\": \"98.5876\", \"name\": \""+SystemEnv.getHtmlNoteName(6018)+"\"},<br/>"
											+ "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{\"lng\": \"231.87613\", \"lat\": \"95.6012\", \"name\": \""+SystemEnv.getHtmlNoteName(6019)+"\"}<br/>"
									+ "&nbsp;&nbsp;&nbsp;&nbsp;]<br/>"
								+ "}<br/>"
							+ "</div>"
        				+ "</div>"
						+ "<div class=\"row\">"
							+ "<span class=\"col-2 span-control MADM_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4842)+"</span>"  //坐标类型:
							+ "<span class=\"col-m-8 multi-checkbox\">"
								+ "<span>"
									+ "<input type=\"checkbox\" name=\"additionalCoordinateType_"+theId+"\" value=\"1\"/><span class=\"cbboxLabel\">"+SystemEnv.getHtmlNoteName(4843)+"</span>"  //高德/腾讯
								+ "</span>"
								+ "<span>"
									+ "<input type=\"checkbox\" name=\"additionalCoordinateType_"+theId+"\" value=\"2\"/><span class=\"cbboxLabel\">"+SystemEnv.getHtmlNoteName(4844)+"</span>" //百度
								+ "</span>"
								+ "<span>"
									+ "<input type=\"checkbox\" name=\"additionalCoordinateType_"+theId+"\" value=\"3\"/><span class=\"cbboxLabel\">GPS</span>" 
								+ "</span>"
							+ "</span>"
						+ "</div>"
						+"<div class=\"row\">"
							+"<span class=\"col-2 span-control MADM_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4847)+"</span>" //显示名称
							+"<div class=\"col pd-4\"><input type=\"checkbox\" id=\"isShowAdditionalPointName_"+theId+"\"/></div>"
						+"</div>"
						+ "<div id=\"additionalScope_"+theId+"\" class=\"row\" style=\"position:relative;\">"
							+ "<span class=\"col-2 span-control MADM_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4848)+":</span>" //范围
							+ "<div class=\"col-m-8\">"
								+"<input class=\"form-control\" id=\"additionalRadius_"+theId+"\" type=\"text\" placeholder=\""+SystemEnv.getHtmlNoteName(4851)+"\"/>"//如:500,单位:米,以此为半径筛选附加点
							+"</div>"
						+ "</div>"
						+ "<div class=\"row\">"
							+ "<span class=\"col-2 span-control\">"+SystemEnv.getHtmlNoteName(6012)+"</span>"  //是否连线
							+ "<div class=\"col-m-8\"><select class=\"form-control\" data-autobind id=\"isConnection_"+theId+"\">"
							+ "<option value=\"0\">"+SystemEnv.getHtmlNoteName(6013)+"</option>"	//无连接线
							+ "<option value=\"1\">"+SystemEnv.getHtmlNoteName(6014)+"</option>"	//点与点之间直线相连
							+ "<option value=\"2\">"+SystemEnv.getHtmlNoteName(6015)+"</option>"	//按步行规划路线连线
							+ "<option value=\"3\">"+SystemEnv.getHtmlNoteName(6016)+"</option>"	//按驾车规划路线连线
							+ "</select></div>"
						+ "</div>"
						+ "<div class=\"row\">"
							+ "<span class=\"col-2 span-control MADM_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4849)+"</span>"  //单击脚本:
							+ "<span class=\"click-control mg-2 inline MADM_ClickBtn\" onclick=\"MADAMap_writeValidateScript('"+theId+"')\">"
							+ "<input id=\"additionalScript_"+theId+"\" type=\"hidden\" value=\"\"/>"
							+ "<label class=\"mg-0 scriptTip\" id=\"scriptTip_"+theId+"\">"+SystemEnv.getHtmlNoteName(4850)+"</label>"  //点击输入附加点单击脚本
							+ "</span>"
						+ "</div>"
					+ "</div>"//附加点信息form-group end
					+ "<div class=\"title\">"+SystemEnv.getHtmlNoteName(4654)+"</div>"//其他设置
					+ "<div class=\"form-group\">"
						+ "<div class=\"row\">"
							+ "<span class=\"col-2 span-control MADM_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4213)+"</span>"  //地图高度:
							+ "<div class=\"col-m-8\"><input class=\"form-control\" data-autobind='height' id=\"height_"+theId+"\" type=\"text\"  value=\""+this.mecJson["height"]+"\"/></div>"
						+ "</div>"
						+ "<div class=\"row\">"
							+ "<span class=\"col-2 span-control MADM_BaseInfo_Label"+styleL+"\">"+SystemEnv.getHtmlNoteName(4214)+"</span>"  //比例尺:
							+ "<div class=\"col-m-8\"><select class=\"form-control\" data-autobind id=\"zoomLevel_"+theId+"\">"
								+ "<option value=\"18\">50m</option>"
								+ "<option value=\"17\">100m</option>"
								+ "<option value=\"16\">200m</option>"
								+ "<option value=\"15\">500m</option>"
								+ "<option value=\"14\">1km</option>"
								+ "<option value=\"13\">2km</option>"
								+ "<option value=\"12\">5km</option>"
								+ "<option value=\"11\">10km</option>"
								+ "<option value=\"10\">20km</option>"
								+ "<option value=\"9\">25km</option>"
								+ "<option value=\"8\">50km</option>"
								+ "<option value=\"7\">100km</option>"
								+ "<option value=\"6\">200km</option>"
								+ "<option value=\"5\">500km</option>"
								+ "<option value=\"4\">1000km</option>"
								+ "<option value=\"3\">2000km</option>"
							+ "</select></div>"
						+ "</div>"
					+ "</div>"
					
					+ "<div class=\"bottom\">"
    					+ "<div class=\"save-btn\" onclick=\"refreshMecDesign('"+theId+"');\">"+SystemEnv.getHtmlNoteName(3451)+"</div>"  //确定
    				+ "</div>"
			+ "</div>";
			
	htm += "<div class=\"MAD_Alert\">"+SystemEnv.getHtmlNoteName(4115)+"</div>";  //已生成到布局
	return htm;
};

/*构建属性编辑窗体完成后调用此方法,主要用于一些必须要使用js对页面进行后置操作时,无需要此方法可至空。 不必需的方法,有此方法系统自动调用*/
MEC_NS.AMap.prototype.afterAttrDlgBuild = function(){
	var that = this;
	var theId = this.id;
	var mecHandler = MECHandlerPool.getHandler(theId);
	var _u = require("utils");
	
	/*使用placeholder规避不能赋值的情况*/
	var address = this.mecJson["address"];
	$("#address_" + theId).val(address);
	
	var zoomLevel = this.mecJson["zoomLevel"];
	$("#zoomLevel_" + theId).val(zoomLevel);
	
	var type = this.mecJson["type"];
	var $type = $("input[type='checkbox'][name='type_"+theId+"'][value='"+type+"']");
	if($type.length > 0){
		$type.checked();
	}
	
	var addrType = this.mecJson["addrType"];
	var $addrType = $("input[type='checkbox'][name='addrType_"+theId+"'][value='"+addrType+"']");
	if($addrType.length > 0){
		$addrType.checked();
	}

	$("#iconType_" + theId).val(this.mecJson.iconType || 0);
    MADAMap_ChangeIcon(theId);
    MADAMap_SetPicPath("", theId, this.mecJson.centerIcon);
	var coordinateType = this.mecJson["coordinateType"];
	var $coordinateType = $("input[type='checkbox'][name='coordinateType_"+theId+"'][value='"+coordinateType+"']");
	if($coordinateType.length > 0){
		$coordinateType.checked();
	}
	var additionalPointType = this.mecJson.additionalPointType || 1;
	var $additionalPointType = $("input[type='checkbox'][name='additionalPointType_"+theId+"'][value='"+additionalPointType+"']");
    if($additionalPointType.length > 0){
        $additionalPointType.checked();
    }
	var additionalCoordinateType = this.mecJson["additionalCoordinateType"];
	var $additionalCoordinateType = $("input[type='checkbox'][name='additionalCoordinateType_"+theId+"'][value='"+additionalCoordinateType+"']");
	if($additionalCoordinateType.length > 0){
		$additionalCoordinateType.checked();
	}
	
	var additionalSql = this.mecJson["additionalSql"];
	$("#additionalSql_" + theId).val(additionalSql);
	
	//动态获取数据源的值,并给数据源添加HTML
	var datasource = this.mecJson["datasource"];
	$("#datasource_" + theId).val(datasource);
	MADAMap_setDataSourceHTML(theId, datasource);
	
	var apiConfig = this.mecJson.apiConfig || {
        api: {},
        params: {
            query: [],
            body: {}
        }
    };
    var apiId = apiConfig.api.id || "";
    var apiName = apiConfig.api.name || "";

    $("#api-name_"+theId).data("last", apiId).text(apiName);
	var additionalScript = this.mecJson["additionalScript"]||"";
	MADAMap_ChangeScriptTip(theId, additionalScript);
	$("#additionalScript_"+theId)[0].value = additionalScript;
	
	var isShowAdditionalPointName = this.mecJson["isShowAdditionalPointName"];
	if(isShowAdditionalPointName == "1"){
		$("#isShowAdditionalPointName_"+theId).checked();
	}
	
	var additionalRadius = this.mecJson["additionalRadius"];
	$("#additionalRadius_" + theId).val(additionalRadius);
	$("#isConnection_" + theId).val(this.mecJson.isConnection || 0);
	SL_ChangeStyle( $("#additionalScript_"+theId).parent(), additionalScript);
	
	var $attrContainer = $("#MADM_"+theId);
	$attrContainer.checkbox({
		onClick: function () { 
			mecHandler.autobind && mecHandler.autobind.update();
		}
	});
	require(["modal"], function(modal) {
		var sqlTip = "1、示例SQL如下:</br>select 经度列,纬度列,中文名称列 from table</br></br>2、SQL说明:</br>" +
            "经度列和纬度列为必需。中文名称列为可选,用于在坐标点上方显示的名称。</br>" +
            "可在查询中包含除经度,纬度,中文名称之外的列,但是要求必须经度为第1列,纬度为第2列,中文名称为第3列(如果有),然后后面接其他的字段。</br>";
		if(_userLanguage=="8"){
			sqlTip = "1、The sample SQL is as follows:</br>select 'lng' _lng_, 'lat' _lat_, 'label' _label_ from table</br></br>2, SQL Description:</br>" +
                "Longitude and latitude columns are required. The Chinese name is listed as an optional name for display above the coordinate point. </br>" +
                "Columns other than longitude, latitude, and Chinese names can be included in the query, but the required longitude must be the first column, the latitude is column 2, the Chinese name is column 3 (if any), and then followed by other fields. </br>";
		}else if(_userLanguage=="9"){
			sqlTip = "1、示例SQL如下:</br>select 經度列,緯度列,中文名稱列 from table</br></br>2、SQL說明:</br>" +
                "經度列和緯度列為必需。中文名稱列為可選,用於在坐標點上方顯示的名稱。</br>" +
                "可在查詢中包含除經度,維度,中文名稱之外的列,但是要求必須經度為第1列,緯度為第2列,中文名稱為第3列(如果有),然後後面接其他的字段。</br>";
		}
		var indexArr = [];
		$(".helper", $attrContainer).on("click", function(e) {
			indexArr.push(modal.tips(sqlTip, $(this), {
				area: ['250px', ''],
				placement: "left"
			}));
			e.stopPropagation();
		});

		$("body").on("click", function(e) {
			var $target = $(e.target);
			var layero = $target.parents(".layui-layer-tips");

			if(layero.length) return;
			
			indexArr.map(function (v) {
				modal.close(v);
			});
		});
	});

    //选择接口事件绑定
    $(".api-browser, #api-name_" + theId, $attrContainer).click(function(){
        var apiConfig = that.mecJson.apiConfig || {
            api: {},
            params: {
                query: [],
                body: {}
            }
        };

        _u.openRcDialog("api-config", {
            title: SystemEnv.getHtmlNoteName(5239).replace(/[::]/g, ""),//接口配置
            params: {
                id: apiConfig.api.id||"",
                config: apiConfig,
                height: 506
            }
        }, function(result) {
            that.mecJson["apiConfig"] = result;
            var selectApi = result.api || {};
            var selectApiId = selectApi.id,
                selectApiName = selectApi.name;
            var lastSourceValue = $("#api-name_" + theId).data("last");
            if(!selectApiId || selectApiId === lastSourceValue) return;
            $("#api-name_" + theId).data("last", selectApiId).text(selectApiName);
        });
    });
};

/*获取JSON*/
MEC_NS.AMap.prototype.getMecJson = function(){
	var theId = this.id;
	
	this.mecJson["id"] = theId;
	this.mecJson["mectype"] = this.type;
	
	var $attrContainer = $("#MADM_"+theId);
	if($attrContainer.length > 0){
		var height = $("#height_" + theId).val();
		if($.trim(height) == ""){
			height = "200";
		}
		var $container = $("#MEC_Design_Container");
		var realHeight = height;
		if($.trim(height).endsWith("%")){
			realHeight = $container.height()*(parseFloat(height.substring(0, height.length-1))/100)
		}
		this.mecJson["realHeight"] = realHeight;

		this.mecJson["height"] = height;
		
		this.mecJson["address"] = $("#address_" + theId).val();
		
		this.mecJson["zoomLevel"] = $("#zoomLevel_" + theId).val();
		
		this.mecJson["type"] = $("input[type='checkbox'][name='type_"+theId+"']:checked").val();
		
		this.mecJson["addrType"] = $("input[type='checkbox'][name='addrType_"+theId+"']:checked").val();

		this.mecJson["additionalPointType"] = $("input[type='checkbox'][name='additionalPointType_"+theId+"']:checked").val();

		this.mecJson["coordinateType"] = $("input[type='checkbox'][name='coordinateType_"+theId+"']:checked").val();

		this.mecJson["iconType"] = $("#iconType_"+theId).val();

		this.mecJson["centerIcon"] = $("#centerIcon_"+theId + " input").val();
		
		this.mecJson["datasource"] = $("#datasource_" + theId).val();
		
		this.mecJson["additionalSql"] = $("#additionalSql_" + theId).val();
		
		this.mecJson["isShowAdditionalPointName"] = $("#isShowAdditionalPointName_"+theId).is(':checked') ? "1" : "0";
		
		this.mecJson["additionalCoordinateType"] = $("input[type='checkbox'][name='additionalCoordinateType_"+theId+"']:checked").val();
		
		this.mecJson["additionalRadius"] = $("#additionalRadius_" + theId).val();	
		
		this.mecJson["additionalScript"] = $("#additionalScript_" + theId).val();	

		this.mecJson["isConnection"] = $("#isConnection_" + theId).val();
	}
	
	return this.mecJson;
};

MEC_NS.AMap.prototype.getDefaultMecJson = function(){
	var theId = this.id;
	
	var defMecJson = {};
	
	defMecJson["id"] = theId;
	defMecJson["mectype"] = this.type;
	//中心点信息
	defMecJson["type"] = "1";//取值类型
	defMecJson["addrType"] = "1";//地址类型
	defMecJson["coordinateType"] = "1";//坐标类型
	defMecJson["iconType"] = "0";//图标类型

	//附加点信息
	defMecJson["additionalPointType"] = "1";//附加点获取类型
	defMecJson["additionalCoordinateType"] = "1";//附加点坐标类型
	defMecJson["isShowAdditionalPointName"] = "1";//显示名称
	defMecJson["isConnection"] = "0";//是否连线
    defMecJson["apiConfig"] = {
        api: {},
        params: {
            query: [],
            body: {}
        }
    };

	defMecJson["height"] = "200";
	defMecJson["realHeight"] = "200";
	defMecJson["address"] = "上海泛微网络科技股份有限公司";
	defMecJson["zoomLevel"] = "15";
	
	return defMecJson;
};
function MADAMap_setDataSourceHTML(mec_id,val){
	var $MADAMap_DataSource = $("#datasource_" + mec_id);
	var url = jionActionUrl("com.weaver.formmodel.mobile.servlet.MobileAppBaseAction", "action=getDataSource");
	FormmodeUtil.doAjaxDataLoad(url, function(datas){
		for(var i = 0; i < datas.length; i++){
			var data = datas[i];
			var pointid = data;
			var selected = "";
			if (pointid=="" || typeof(pointid)=="undefined") continue;
			if (pointid == val) selected = "selected";
			var dataSourceSelectHtml = "<option value=\""+pointid+"\" "+selected+">";
			dataSourceSelectHtml += pointid;
			dataSourceSelectHtml += "</option>";
			$MADAMap_DataSource.append(dataSourceSelectHtml);
		}
	});
}
function MADAMap_ChangeType(cbObj, mec_id){
	setTimeout(function(){	//checkbox用了插件,不延时checkbox的checked状态获取不准确
		var objV = cbObj.value;
		if(!cbObj.checked){
			changeCheckboxStatus(cbObj, true);
			return;
		}else{
			$("input[type='checkbox'][name='type_"+mec_id+"']").each(function(){
				if(this.value != objV){
					changeCheckboxStatus(this, false);
				}
			});
		}
		
		$("#MADM_"+mec_id+" .typeContent").hide();
		$("#typeContent_" + mec_id + "_" + objV).show();
		$("#addrIcon_" + mec_id).show();
        $("#additionalScope_" + mec_id).show();
		if(objV == "3"){
            $("#typeContent_" + mec_id + "_1").hide();
            $("#typeContent_" + mec_id + "_2").hide();
            $("#addrIcon_" + mec_id).hide();
            $("#additionalScope_" + mec_id).hide();
		}
	},100);
}

function MADAMap_ChangeAddrType(cbObj, mec_id){
	setTimeout(function(){	//checkbox用了插件,不延时checkbox的checked状态获取不准确
		var objV = cbObj.value;
		if(!cbObj.checked){
			changeCheckboxStatus(cbObj, true);
			return;
		}else{
			$("input[type='checkbox'][name='addrType_"+mec_id+"']").each(function(){
				if(this.value != objV){
					changeCheckboxStatus(this, false);
				}
			});
		}
		
		$("#MADM_"+mec_id+" .addrTypeContent").hide();
		$("#addrTypeContent_" + mec_id + "_" + objV).show();
	},100);
}
var MADAMap_ScriptTip = "";
if(_userLanguage=="8"){
	MADAMap_ScriptTip = "/*You can use the variable pointData directly to obtain the map point information.*/\nvar billid = pointData.id;\n";
}else if(_userLanguage=="9"){
	MADAMap_ScriptTip = "/*可直接使用變量pointData獲取地圖點信息*/\nvar billid = pointData.id;\n" ;
}else{
	MADAMap_ScriptTip = "/*可直接使用变量pointData获取地图点信息*/\nvar billid = pointData.id;\n";
}
function MADAMap_writeValidateScript(mec_id){
	var $field = $("#additionalScript_" + mec_id);
	var fieldV = $.trim($field.val());
	if(fieldV == ""){
		fieldV = MADAMap_ScriptTip;
		$field.val(fieldV);
	}
	SL_AddScriptToField($field, function(scriptCode){
		MADAMap_ChangeScriptTip(mec_id, scriptCode);
	});
}

function MADAMap_ChangeScriptTip(mec_id, scriptCode){
	var $scriptTip = $("#scriptTip_" + mec_id);
	scriptCode = $.trim(scriptCode);
	if(scriptCode == ""){
		$scriptTip.html(SystemEnv.getHtmlNoteName(4850));  //点击输入提交前验证脚本
	}else{
		$scriptTip.html(SystemEnv.getHtmlNoteName(4510));  //已设置
	}
}

function MADAMap_ChangeIcon(mec_id){
    var v = $("#iconType_" + mec_id).val();

    v == '1'? $("#centerIcon_"+mec_id).show() : $("#centerIcon_"+mec_id).hide();
}

function MADAMap_PicSet(prefix, mec_id){
    var pic_path = $("#centerIcon"+prefix+"_"+mec_id + " input").val();
    var params = "pic_path=" + pic_path;

    showPicsetModal(params, function(result){
        var picPath = result["pic_path"];
        MADAMap_SetPicPath(prefix, mec_id, picPath);
    });
}

function MADAMap_SetPicPath(prefix, mec_id, picPath){
    var mecHandler = MECHandlerPool.getHandler(mec_id);
    var $img = $("#centerIcon"+prefix+"_"+mec_id);
    $("input", $img).val(picPath || '');
    $(".icon-set-img", $img).attr("src", picPath || '');
    if(!picPath){
        $img.removeClass("hasValue");
    }else{
        $img.addClass("hasValue");
    }

    var e = event || window.event;
    if (e){
        if(e.stopPropagation){
            e.stopPropagation();
        }else{
            e.cancelBubble=true;
        }
    }
    mecHandler.autobind && mecHandler.autobind.update();
}

function MADAMap_ChangeAdditionalPointType(cbObj, mec_id){
    setTimeout(function(){	//checkbox用了插件,不延时checkbox的checked状态获取不准确
        var objV = cbObj.value;
        if(!cbObj.checked){
            changeCheckboxStatus(cbObj, true);
            return;
        }else{
            $("input[type='checkbox'][name='additionalPointType_"+mec_id+"']").each(function(){
                if(this.value != objV){
                    changeCheckboxStatus(this, false);
                }
            });
        }

        $("#MADM_"+mec_id+" .additionalPointType").hide();
        $("#additionalPointType_" + mec_id + "_" + objV).show();
    },100);
}