popup_infoWindow.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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_infoWindow"></title>
  9. <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
  10. <script type="text/javascript" exclude="iclient-classic" include="nanoscroller,infoWindow"
  11. src="../../dist/classic/include-classic.js"></script>
  12. <style type="text/css">
  13. body {
  14. margin: 0;
  15. overflow: hidden;
  16. background: #fff;
  17. width: 100%;
  18. height: 100%
  19. }
  20. #map {
  21. position: absolute;
  22. width: 100%;
  23. height: 100%;
  24. }
  25. /*用户自定义*/
  26. #pop-content {
  27. right: 0 !important;
  28. padding-left: 10px;
  29. color: #000;
  30. word-wrap: break-word;
  31. }
  32. /*滚动条样式*/
  33. div.nano-pane {
  34. margin-right: 10px;
  35. margin-top: 3px;
  36. }
  37. .nano > .nano-pane {
  38. background-color: transparent;
  39. width: 1px;
  40. display: block;
  41. opacity: 1;
  42. visibility: visible;
  43. }
  44. .nano > .nano-pane > .nano-slider {
  45. background: #DEDEDE;
  46. width: 6px;
  47. transform: translate(0px, 43px);
  48. }
  49. </style>
  50. </head>
  51. <body>
  52. <div id="map"></div>
  53. <script>
  54. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  55. var map, layerWorld, marker, markers;
  56. var vectorLayer, feature;
  57. var featurePop, markerPop;
  58. var url = host + "/iserver/services/map-world/rest/maps/World";
  59. init();
  60. function init() {
  61. //map上添加控件
  62. map = new SuperMap.Map("map", {
  63. controls: [
  64. new SuperMap.Control.ScaleLine(),
  65. new SuperMap.Control.Zoom(),
  66. new SuperMap.Control.LayerSwitcher(),
  67. new SuperMap.Control.Navigation({ //添加导航控件到map
  68. dragPanOptions: {
  69. enableKinetic: true //拖拽动画
  70. }
  71. })]
  72. });
  73. //定义layerWorld图层,获取图层服务地址
  74. layerWorld = new SuperMap.Layer.TiledDynamicRESTLayer("World", url);
  75. //为图层初始化完毕添加layerInitialized事件
  76. layerWorld.events.on({"layerInitialized": addLayer});
  77. //初始化矢量图层类
  78. vectorLayer = new SuperMap.Layer.Vector("vectorLayer");
  79. var selectControl = new SuperMap.Control.SelectFeature(vectorLayer, {
  80. onSelect: onFeatureSelect
  81. });
  82. map.addControl(selectControl);
  83. selectControl.activate();
  84. //初始化标记图层类
  85. markers = new SuperMap.Layer.Markers("Markers");
  86. //初始化popup类
  87. markerPop = new SuperMap.InfoWindow(
  88. "marker"
  89. );
  90. }
  91. //定义addLayer函数,触发 layerInitialized事件会调用此函数
  92. function addLayer() {
  93. //map上添加分块动态REST图层和标记图层
  94. map.addLayers([layerWorld, vectorLayer, markers]);
  95. map.setCenter(new SuperMap.LonLat(23, 38), 4);
  96. addFeature();
  97. addMarker();
  98. }
  99. //定义addMarker函数,触发layerInitialized事件会调用此函数
  100. function addMarker() {
  101. size = new SuperMap.Size(21, 25);
  102. offset = new SuperMap.Pixel(-(size.w / 2), -size.h);
  103. var icon = new SuperMap.Icon('./images/markerbig_select.png', size, offset);
  104. //初始化标记覆盖物类
  105. marker = new SuperMap.Marker(new SuperMap.LonLat(23.6530190, 37.9439259), icon);
  106. //添加覆盖物到标记图层
  107. markers.addMarker(marker);
  108. //注册 click 事件,触发 mouseClickHandler()方法
  109. marker.events.on({
  110. "click": mouseClickHandler,
  111. "touchstart": mouseClickHandler //假如要在移动端的浏览器也实现点击弹框,则在注册touch类事件
  112. });
  113. }
  114. //定义addFeature函数,触发layerInitialized事件会调用此函数
  115. function addFeature() {
  116. var point = new SuperMap.Geometry.Point(53, 38);
  117. feature = new SuperMap.Feature.Vector(point, {
  118. "SmID": "17",
  119. "CAPITAL": "普拉亚",
  120. "CAPITAL_EN": "Praia",
  121. "COUNTRY": "佛得角",
  122. "COUNTRY_EN": "Cape Verde",
  123. "SmGeometrySize": "16",
  124. "SmX": "-23.5209955",
  125. "SmY": "14.9229990",
  126. "USERID": "0"
  127. });
  128. vectorLayer.addFeatures(feature);
  129. }
  130. //定义mouseClickHandler函数,触发click事件会调用此函数
  131. function mouseClickHandler() {
  132. markerPop.titleBox = false;
  133. markerPop.contentSize = new SuperMap.Size(300, 200);
  134. markerPop.render();
  135. //设置弹窗的位置
  136. markerPop.setLonLat(this.getLonLat(), {x: 0, y: 0});
  137. //设置弹窗的内容
  138. markerPop.setContentHTML(null, '<div id="pop-content">' + 'SmID : 31' + "<br>" +
  139. resources.text_district + "<br>" +
  140. resources.text_organization + "<br>" +
  141. resources.text_serviceType + "<br>" +
  142. '<p>'+resources.text_note +
  143. resources.text_featureStyle +
  144. resources.text_needModify+'</p></div>');
  145. //添加弹窗到map图层
  146. map.addPopup(markerPop);
  147. }
  148. // Feature 选中事件响应
  149. function onFeatureSelect(feature) {
  150. featurePop = new SuperMap.InfoWindow(
  151. "feature",
  152. resources.text_featureInfo
  153. );
  154. featurePop.hide();
  155. featurePop.titleBox = true;
  156. featurePop.contentSize = new SuperMap.Size(300, 200);
  157. featurePop.render();
  158. featurePop.show(null, feature);
  159. var lonLat = new SuperMap.LonLat(feature.geometry.x, feature.geometry.y);
  160. featurePop.setLonLat(lonLat, {x: 0, y: 0});
  161. //添加弹窗到map图层
  162. map.addPopup(featurePop);
  163. /*使用jquery的滚动条插件 jquery.nanoscroller.min.js
  164. *此插件依赖于jquery
  165. *还需引入此插件的css样式,还可以在此样式上进行修改
  166. * */
  167. document.getElementById("feature_contentDiv").className = "nano";
  168. document.getElementById("feature_groupDiv").className = "nano-content";
  169. $(".nano").nanoScroller();
  170. }
  171. // Feature取消选中事件响应
  172. function onFeatureUnselect() {
  173. featurePop.destroy();
  174. }
  175. </script>
  176. </body>
  177. </html>