/* * * IFrame地图与外部操作桥接 * @author BOONYACHENGDU@GMAIL.COM */ (function() { window.MapsUtil = {}; MapsUtil = { BASEPATH : null, MAP_OBJECT : null, MAP_CONSTANT : null, /** * 初始化地图 */ initMap : function(map_object,mapType,basePath) { this.BASEPATH = basePath; this.MAP_OBJECT = map_object; this.MAP_CONSTANT = map_object.CONSTANT; this.MAP_CONSTANT.CURRENT_MAP_TYPE = mapType || this.MAP_CONSTANT.CURRENT_MAP_TYPE; this.MAP_OBJECT.initOpenLayersMap(); }, initHistoricalTrackMap : function(map_object,mapType,basePath) { this.BASEPATH = basePath; this.MAP_OBJECT = map_object; this.MAP_CONSTANT = map_object.CONSTANT; this.MAP_CONSTANT.CURRENT_MAP_TYPE = mapType || "openStreetMap"; this.MAP_OBJECT.initHistoricalTrackMap(); }, /** * 获取坐标点Point */ getPoint : function(lat,lng) { return this.MAP_OBJECT.getPoint(lat,lng); }, /** * 设置地图居中 */ setCenterAndZoom : function(point,zoom) { this.MAP_OBJECT.setCenterAndZoom(point,zoom); }, /** * 点越界处理 */ ifOutBoundsPan : function(point) { this.MAP_OBJECT.ifOutBoundsPantoCenter(point); }, /** * 得到一个图标 */ getIcon : function(imei,iconName,iconType,isOnline) { var id = imei+(isOnline?"_on":"_off"); var scale = 1; var basePath = MapsUtil.BASEPATH; var iconPath = basePath+"/web/resource/images/trackerIcon/point1.png"; if(iconType ==1){ iconPath = basePath+"/web/resource/images/trackerIcon"; iconPath += (isOnline?"/":"/off/")+iconName; }else if(iconType ==2){ iconPath = basePath+"/web/getImage/trackerIcon/"; iconPath += iconName+(isOnline?"":"?off=true"); scale = 0.5; } return this.MAP_OBJECT.getIcon(id,iconPath,scale); }, /** * 得到一个标记图标 */ getMarker : function(id,point,icon) { return this.MAP_OBJECT.getMarker(id,point,icon); }, /** * 设置标记图标 */ setMarker : function(id, point, iconStyle) { return this.MAP_OBJECT.setMarker(id, point, iconStyle); }, isShowCircle : function(id, isShow) { id = id + 'circle'; return this.MAP_OBJECT.isShowCircle(id, isShow); }, getCircle : function(id,point,radius) { id = id + 'circle'; return this.MAP_OBJECT.getCircle(id,point,radius); }, setCircle : function(id, point, radius) { id = id + 'circle'; return this.MAP_OBJECT.setCircle(id, point, radius); }, removeCircle : function(id) { id = id + 'circle'; this.MAP_OBJECT.removeCircle(id); }, /** * 移除一个标记 */ removeMarker : function(id) { this.MAP_OBJECT.removeMarke(id); this.MAP_OBJECT.removeInfoWindow(id); this.removeCircle(id); }, /** * 移除所有标记 */ removeAllMarker : function() { if(this.MAP_OBJECT != null){ this.MAP_OBJECT.removeAllMarke(); this.MAP_OBJECT.removeAllInfoWindow(); } }, /** * */ getInfoWindow : function(id,point,htmlContent) { this.MAP_OBJECT.getInfoWindow(id,point,htmlContent); }, /** * */ setInfoWindow : function(id,point,htmlContent) { this.MAP_OBJECT.setInfoWindow(id,point,htmlContent); }, /** * */ geocoderToAddress : function(lat,lng,callback) { // this.MAP_OBJECT.getGeocoderAddressByPoint(lat,lng,callback); MapsUtil.api.getGeocoderAddress(lat,lng,callback); }, analysisAddress : function(lat,lng,isChina,callback){ if(isChina){ MapsUtil.service.jiupian(lat, lng, function(latlng) { var jiupian_lat = latlng[0]; var jiupian_lng = latlng[1]; //geocoder解析地址 MapsUtil.geocoderToAddress(jiupian_lat, jiupian_lng, function(address) { callback(address); }); }); }else{ //geocoder解析地址 MapsUtil.geocoderToAddress(lat, lng, function(address) { callback(address); }); } }, viewExtent : function(coordinates){ this.MAP_OBJECT.viewExtent(coordinates); } }; MapsUtil.service={ getLocalAddress : function(lat, lng, callback){ var mapType = MapsUtil.MAP_CONSTANT.CURRENT_MAP_TYPE; $.ajax({ url: MapsUtil.BASEPATH+"/web/getLocalAddress.do", datatype:'json', type: "Post", data: "mapType="+mapType+"&lat="+lat+"&lng="+lng, success: function(jsonData){ //alert(JSON.stringify(jsonData)); if(jsonData.code == 10000){ var address = jsonData.data["address"]; callback(address); } } }); }, saveLocalAddress : function (lat, lng, address){ var mapType = MapsUtil.MAP_CONSTANT.CURRENT_MAP_TYPE; $.ajax({ url: MapsUtil.BASEPATH+"/web/saveLocalAddress.do", datatype:'json', type: "Post", data: "mapType="+mapType+"&lat="+lat+"&lng="+lng+"&address="+address, success: function(data){ } }); }, updateLocalAddress : function (lat, lng, address, callback){ var mapType = MapsUtil.MAP_CONSTANT.CURRENT_MAP_TYPE; $.ajax({ url: MapsUtil.BASEPATH+"/web/updateLocalAddress.do", datatype:'json', type: "Post", data: "mapType="+mapType+"&lat="+lat+"&lng="+lng+"&address="+address, success: function(data){ callback(data); } }); }, jiupian : function (lat, lng, callback){ var jiupianType = MapsUtil.MAP_CONSTANT.CURRENT_MAP_JIUPIAN; $.ajax({ url: MapsUtil.BASEPATH+"/web/jiupian.json", datatype:'json', type: "Post", data: "lat="+lat+"&lng="+lng+"&jiupianType="+jiupianType, success: function(jsonData){ if(jsonData.code == 10000){ var latlng = jsonData.data["latlng"]; callback(latlng); } } }); } } MapsUtil.api={ /** * 反地址解析 */ getGeocoderAddress : function(lat, lng, callback) { var mapType = MapsUtil.MAP_CONSTANT.CURRENT_MAP_TYPE; if (mapType == 'googleMap') { var mapKey = window.parent.googleKey; //result_type=street_address 表示精确的街道地址。精确的街道地址有可能不存在 var url = 'https://maps.google.com/maps/api/geocode/json?sensor=false' +'&key='+mapKey+'&latlng='+lat+','+lng; $.ajax({ type : 'GET', url : url, success : function(data) { //alert("==="+JSON.stringify(data)); if (data["status"] == "OK") { var address = data["results"][0].formatted_address; //alert("address=="+address); callback(address); } } }); } else if (mapType == 'baiduMap') { // http://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-geocoding //var baiduKey = 'dGeD3fnmUH6W1RlVSvEHi2oOmsppaHQ4'; var mapKey = window.parent.baiduKey; var url = 'http://api.map.baidu.com/geocoder/v2/?output=json&ak=' + mapKey + '&location=' + lat + ',' + lng; $.ajax({ type : 'GET', dataType : 'JSONP', url : url, success : function(data) { // alert("==="+JSON.stringify(data)); if (data["status"] == 0) { var address = data["result"].formatted_address; //alert("baidu=="+address+",距离:"+data["result"].sematic_description); callback(address); } } }); } else if (mapType == 'gaodeMap') { // http://lbs.amap.com/api/webservice/reference/georegeo/#t6 //var gaodeKey = '5b12e9009f9ac5956f00a42947f3f994'; var mapKey = window.parent.gaodeKey; var url = 'http://restapi.amap.com/v3/geocode/regeo?output=json&key=' + mapKey + '&location=' + lng + ',' + lat; $.ajax({ url : url, type : 'get', success : function(data) { // alert("==="+JSON.stringify(data)); if (data["status"] == 1) { var address = data["regeocode"].formatted_address; callback(address); } }, }) } else if (mapType == 'openStreetMap') { // http://wiki.openstreetmap.org/wiki/Zh-hans:Nominatim var url = 'https://nominatim.openstreetmap.org/reverse?format=json&lat=' + lat + '&lon=' + lng + '&zoom=18&addressdetails=1'; $.ajax({ url : url, type : 'get', success : function(data) { // alert("openStreetMap==="+JSON.stringify(data)); if (data["display_name"] != "undefined") { var address = data["display_name"]; callback(address); } }, }) } }, /** * 地址解析 */ getGeocoderPointByAddress : function(address, callback) { var GOOGLEKEY = 'AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM'; // http://maps.google.com/maps/api/geocode/json?address=&sensor=false $.ajax('https://maps.googleapis.com/maps/api/geocode/json?address=${address}&key=${GOOGLEKEY}',{ beforeSend : function() { window.googleStart = new Date().getTime(); }, success : function(data) { // $('#google').empty(); // for (var res of data.results) { // $('#google').append('