| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- /* *
- * 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('<li>${res.formatted_address}</li>')
- // }
- // $('#google').append('<li>took ${new
- // Date().getTime() -
- // window.googleStart}ms</li>');
- }
- });
- }
- }
-
- MapsUtil.tools={
- /**
- * 画多边形、圆
- */
- addDraw : function(){
- this.MAP_OBJECT.tools.addDraw();
- }
-
- }
-
- MapsUtil.event={
- /**
- * 添加监听事件
- */
- addListener:function(mapObject,type,htmlContent,callback){
- if(type=="click"){//点击标注事件
- return this.MAP_OBJECT.event.addListener_singleclick(mapObject,htmlContent);
- }else if(type=="mousemove"){
-
- }
-
- },
- };
- })();
|