regionSearch.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * @fileoverview 行政区域查询
  3. * @author Song.Huang
  4. * @version 1.0.0
  5. */
  6. define(function(){
  7. var regionSearch = function() {
  8. this.formatEarthLatLng = function(lat,lng){
  9. lng = lng%360;
  10. if(lng>180){
  11. lng = (lng%180)-180;
  12. }else if(lng<-180){
  13. lng = 180+(lng%180);
  14. }
  15. lat = lat%180;
  16. if(lat>90){
  17. lat = (lat%90)-90;
  18. }else if(lat<-90){
  19. lat = 90+(lat%90);
  20. }
  21. return [lat,lng];
  22. };
  23. /**
  24. * 通过坐标查询 父级市县和下级市县
  25. * @param {[type]} options [(lat纬度,lon经度 zoom(地图缩放等级)]
  26. * @param {[type]} callbackFunc [回调方法]
  27. * @return {[type]} [description]
  28. */
  29. this.getRegionInfo = function(options, callbackFunc) {
  30. options.latLng = this.formatEarthLatLng(options.latLng[0],options.latLng[1]);
  31. var sUrl = onemapUrlConfig.regionSearchDataUrl + '/v1.0/area/name/'+
  32. '?z=' + options.zoom +
  33. '&lon=' + options.latLng[1] +
  34. '&lat=' + options.latLng[0];
  35. ONEMAP.V.loading.load();
  36. $.ajax({
  37. url: sUrl,
  38. type: 'GET',
  39. dataType: 'jsonp'
  40. })
  41. .done(function(data) {
  42. ONEMAP.V.loading.loaded();
  43. callbackFunc(data);
  44. })
  45. .fail(function() {
  46. ONEMAP.V.loading.loaded();
  47. });
  48. };
  49. /**
  50. * 通过pac查询 所属区域信息
  51. * @param {[type]} options [(pac]
  52. * @param {[type]} callbackFunc [回调方法]
  53. * @return {[type]} [description]
  54. */
  55. this.getPacRegionInfo = function(options, callbackFunc) {
  56. options.latLng = this.formatEarthLatLng(options.pac);
  57. var sUrl = onemapUrlConfig.regionSearchDataUrl + '/v1.0/area/name2/'+
  58. '?pac=' + options.pac;
  59. ONEMAP.V.loading.load();
  60. $.ajax({
  61. url: sUrl,
  62. type: 'GET',
  63. dataType: 'jsonp'
  64. })
  65. .done(function(data) {
  66. ONEMAP.V.loading.loaded();
  67. callbackFunc(data);
  68. })
  69. .fail(function() {
  70. ONEMAP.V.loading.loaded();
  71. });
  72. };
  73. /**
  74. * 通过经纬度和省市级编号查询边界点
  75. * @param latLng {LatLng} 坐标
  76. * @param demand {Number} 省市级编号 4-省 5-市 6-县
  77. * @param callbackFunc {Function} 回调方法
  78. */
  79. this.getRegionBoundary = function(options, callbackFunc) {
  80. options.latLng = this.formatEarthLatLng(options.latLng[0],options.latLng[1]);
  81. var sUrl = onemapUrlConfig.regionSearchDataUrl + '/v1.0/area/edge/'+
  82. '?lon=' + options.latLng[1] +
  83. '&lat=' + options.latLng[0] +
  84. '&scale=' + options.demand;
  85. ONEMAP.V.loading.load();
  86. $.ajax({
  87. url: sUrl,
  88. type: 'GET',
  89. dataType: 'jsonp'
  90. })
  91. .done(function(data) {
  92. ONEMAP.V.loading.loaded();
  93. callbackFunc(data);
  94. })
  95. .fail(function() {
  96. ONEMAP.V.loading.loaded();
  97. });
  98. }
  99. };
  100. return regionSearch;
  101. })