addressMatchService.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="UTF-8">
  8. <title data-i18n="resources.title_addressMatchService"></title>
  9. </head>
  10. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  11. <div id="map" style="width: 100%;height:100%"></div>
  12. <script type="text/javascript" include="bootstrap-css,jquery" src="../js/include-web.js"></script>
  13. <script type="text/javascript" src="../../dist/leaflet/include-leaflet.js"></script>
  14. <script type="text/javascript">
  15. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  16. var map, codeMarkers = [], decodeMarkers = [],
  17. url = host + "/iserver/services/map-china400/rest/maps/China_4326",
  18. addressUrl = host + "/iserver/services/addressmatch-Address/restjsr/v1/address",
  19. addressMatchService = L.supermap.addressMatchService(addressUrl);
  20. map = L.map('map', {
  21. crs: L.CRS.EPSG4326,
  22. center: [39.914714, 116.383572],
  23. maxZoom: 18,
  24. zoom: 11
  25. });
  26. L.supermap.tiledMapLayer(url).addTo(map);
  27. var control = L.control({position: 'topright'});
  28. control.onAdd = function () {
  29. var popup = L.DomUtil.create('div');
  30. popup.style.width = '350px';
  31. popup.innerHTML = "<div class='panel panel-default'>" +
  32. "<div class='panel-body'>" +
  33. "<ul class='nav nav-tabs nav-justified'>" +
  34. "<li id='geocode' role='presentation' class='active'><a href='#'>" + resources.text_code + "</a></li>" +
  35. "<li id='geodecode' role='presentation'><a href='#'>" + resources.text_decode + "</a></li>" +
  36. "</ul><p>" +
  37. "<div class='tab-content'>" +
  38. "<div id='geocodeParam' role='tabpanel' class='tab-pane deplistContent active'>" +
  39. "<div class='input-group'>" +
  40. "<span class='input-group-addon'>" + resources.text_address + "</span>" +
  41. "<input id='address' type='text' class='form-control' placeholder='超图软件'/>" +
  42. "</div><p>" +
  43. "<div class='input-group'>" +
  44. "<span class='input-group-addon'>" + resources.text_filterField + " </span>" +
  45. "<input id='filters' type='text' class='form-control' placeholder='北京市,朝阳区'/>" +
  46. "</div><p>" +
  47. "<div class='input-group'>" +
  48. "<span class='input-group-addon'>" + resources.text_minIndex + "</span>" +
  49. "<input id='fromIndex' type='text' class='form-control' placeholder='0'/>" +
  50. "</div><p>" +
  51. "<div class='input-group'>" +
  52. "<span class='input-group-addon'>" + resources.text_maxIndex + "</span>" +
  53. "<input id='toIndex' type='text' class='form-control' placeholder='10'/>" +
  54. "</div><p>" +
  55. "<div class='input-group'>" +
  56. "<span class='input-group-addon'>" + resources.text_maxCount + "</span>" +
  57. "<input id='maxReturn' type='text' class='form-control' placeholder='-1'/>" +
  58. "</div><p>" +
  59. "<div class='input-group'>" +
  60. "<span class='input-group-addon'>" + resources.text_coorSystem + "</span>" +
  61. "<input id='prjCoordSys' type='text' class='form-control' placeholder='{epsgcode:4326}'/>" +
  62. "</div><p>" +
  63. "<div align='right'>" +
  64. "<input type='button' id='codeBtn' class='btn btn-primary' value='" + resources.btn_input_value_match + "'/>" +
  65. "</div></div>" +
  66. "<div id='geodecodeParam' role='tabpanel' class='tab-pane deplistContent'>" +
  67. "<div class='input-group'>" +
  68. "<span class='input-group-addon'>" + resources.text_abscissa + "</span>" +
  69. "<input id='xCoord' type='text' class='form-control' placeholder='116.3518541194752'/>" +
  70. "</div><p>" +
  71. "<div class='input-group'>" +
  72. "<span class='input-group-addon'>" + resources.text_ordinate + " </span>" +
  73. "<input id='yCoord' type='text' class='form-control' placeholder='40.00097839595237'/>" +
  74. "</div><p>" +
  75. "<div class='input-group'>" +
  76. "<span class='input-group-addon'>" + resources.text_filterField + "</span>" +
  77. "<input id='filters2' type='text' class='form-control' placeholder=''/>" +
  78. "</div><p>" +
  79. "<div class='input-group'>" +
  80. "<span class='input-group-addon'>" + resources.text_minIndex + "</span>" +
  81. "<input id='fromIndex2' type='text' class='form-control' placeholder='0'/>" +
  82. "</div><p>" +
  83. "<div class='input-group'>" +
  84. "<span class='input-group-addon'>" + resources.text_maxIndex + "</span>" +
  85. "<input id='toIndex2' type='text' class='form-control' placeholder='10'/>" +
  86. "</div><p>" +
  87. "<div class='input-group'>" +
  88. "<span class='input-group-addon'>" + resources.text_maxCount + "</span>" +
  89. "<input id='maxReturn2' type='text' class='form-control' placeholder='-1'/>" +
  90. "</div><p>" +
  91. "<div class='input-group'>" +
  92. "<span class='input-group-addon'>" + resources.text_queryRadius + "</span>" +
  93. "<input id='geoDecodingRadius' type='text' class='form-control' placeholder='-1'/>" +
  94. "</div><p>" +
  95. "<div class='input-group'>" +
  96. "<span class='input-group-addon'>" + resources.text_coorSystem + "</span>" +
  97. "<input id='prjCoordSys2' type='text' class='form-control' placeholder='{epsgcode:4326}'/>" +
  98. "</div><p>" +
  99. "<div align='right'>" +
  100. "<input type='button' id='decodeBtn' class='btn btn-primary' value='" + resources.btn_input_value_match + "'/>" +
  101. "</div></div></div>";
  102. handleMapEvent(popup, this._map);
  103. return popup;
  104. };
  105. control.addTo(map);
  106. $("#geocode").click(function () {
  107. $("#geocode")[0].className = 'active';
  108. $("#geodecode")[0].className = '';
  109. $("#geocodeParam").addClass('active');
  110. $("#geodecodeParam").removeClass('active');
  111. });
  112. $("#geodecode").click(function () {
  113. $("#geocode")[0].className = '';
  114. $("#geodecode")[0].className = 'active';
  115. $("#geodecodeParam").addClass('active');
  116. $("#geocodeParam").removeClass('active');
  117. });
  118. //判断输入字符串是否为空或者全部都是空格
  119. function isNull(str) {
  120. if (str == "") return true;
  121. var regu = "^[ ]+$";
  122. var re = new RegExp(regu);
  123. return re.test(str);
  124. }
  125. $("#codeBtn").click(function () {
  126. var geoCodeParam = new SuperMap.GeoCodingParameter({
  127. address: $('#address').val() || $('#address').attr('placeholder'),
  128. fromIndex: $('#fromIndex').val() || $('#fromIndex').attr('placeholder'),
  129. toIndex: $('#toIndex').val() || $('#toIndex').attr('placeholder'),
  130. filters: $('#filters').val() || $('#filters').attr('placeholder'),
  131. prjCoordSys: $('#prjCoordSys').val() || $('#prjCoordSys').attr('placeholder'),
  132. maxReturn: $('#maxReturn').val() || $('#maxReturn').attr('placeholder')
  133. });
  134. addressMatchService.code(geoCodeParam, match);
  135. });
  136. $("#decodeBtn").click(function () {
  137. var geoDecodeParam = new SuperMap.GeoDecodingParameter({
  138. x: $('#xCoord').val() || $('#xCoord').attr('placeholder'),
  139. y: $('#yCoord').val() || $('#yCoord').attr('placeholder'),
  140. fromIndex: $('#fromIndex2').val() || $('#fromIndex2').attr('placeholder'),
  141. toIndex: $('#toIndex2').val() || $('#toIndex2').attr('placeholder'),
  142. filters: $('#filters2').val() || $('#filters2').attr('placeholder'),
  143. prjCoordSys: $('#prjCoordSys2').val() || $('#prjCoordSys2').attr('placeholder'),
  144. maxReturn: $('#maxReturn2').val() || $('#maxReturn2').attr('placeholder'),
  145. geoDecodingRadius: $('#geoDecodingRadius').val() || $('#geoDecodingRadius').attr('placeholder'),
  146. });
  147. addressMatchService.decode(geoDecodeParam, match);
  148. });
  149. function match(obj) {
  150. clearMarkers();
  151. obj.result.map(function (item) {
  152. var marker = L.marker([item.location.y, item.location.x]);
  153. decodeMarkers.push(marker);
  154. var innerHTML = "";
  155. innerHTML += resources.text_address + ":" + item.address + "<br>";
  156. var x = Number(item.location.x.toString().match(/^\d+(?:\.\d{0,2})?/));
  157. var y = Number(item.location.y.toString().match(/^\d+(?:\.\d{0,2})?/));
  158. innerHTML += resources.text_coordinate + ":[" + x + "," + y + "]<br>";
  159. if (item.score > 0) {
  160. innerHTML += resources.text_matchDegree + ":" + item.score + "<br>";
  161. }
  162. innerHTML += resources.text_filterField + ":" + item.filters + "<br>";
  163. marker.bindPopup(innerHTML);
  164. });
  165. for (var i = 0; i < decodeMarkers.length; i++) {
  166. decodeMarkers[i].addTo(map);
  167. }
  168. map.setView(L.latLng(39.914714, 116.383572), 10);
  169. }
  170. function clearMarkers() {
  171. if (codeMarkers) {
  172. for (var i = 0; i < codeMarkers.length; i++) {
  173. codeMarkers[i].remove();
  174. }
  175. }
  176. if (decodeMarkers) {
  177. for (var i = 0; i < decodeMarkers.length; i++) {
  178. decodeMarkers[i].remove();
  179. }
  180. }
  181. codeMarkers = [];
  182. decodeMarkers = [];
  183. }
  184. function handleMapEvent(div, map) {
  185. if (!div || !map) {
  186. return;
  187. }
  188. div.addEventListener('mouseover', function () {
  189. map.dragging.disable();
  190. map.scrollWheelZoom.disable();
  191. map.doubleClickZoom.disable();
  192. });
  193. div.addEventListener('mouseout', function () {
  194. map.dragging.enable();
  195. map.scrollWheelZoom.enable();
  196. map.doubleClickZoom.enable();
  197. });
  198. }
  199. </script>
  200. </body>
  201. </html>