popup_simplePopup.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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_simplePopup"></title>
  9. <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
  10. <script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
  11. <style type="text/css">
  12. body {
  13. margin: 0;
  14. overflow: hidden;
  15. background: #fff;
  16. width: 100%;
  17. height: 100%
  18. }
  19. #map {
  20. position: absolute;
  21. width: 100%;
  22. height: 100%;
  23. }
  24. #toolbar {
  25. position: absolute;
  26. top: 50px;
  27. right: 10px;
  28. width: 300px;
  29. text-align: center;
  30. z-index: 100;
  31. border-radius: 4px;
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <div id="map"></div>
  37. <script>
  38. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  39. var map, layerWorld, marker, markers;
  40. var url = host + "/iserver/services/map-world/rest/maps/World";
  41. init();
  42. function init() {
  43. //map上添加控件
  44. map = new SuperMap.Map("map", {
  45. controls: [
  46. new SuperMap.Control.ScaleLine(),
  47. new SuperMap.Control.Zoom(),
  48. new SuperMap.Control.LayerSwitcher(),
  49. new SuperMap.Control.Navigation({ //添加导航控件到map
  50. dragPanOptions: {
  51. enableKinetic: true //拖拽动画
  52. }
  53. })]
  54. });
  55. //定义layerWorld图层,获取图层服务地址
  56. layerWorld = new SuperMap.Layer.TiledDynamicRESTLayer("World", url);
  57. //为图层初始化完毕添加layerInitialized事件
  58. layerWorld.events.on({"layerInitialized": addLayer});
  59. //初始化标记图层类
  60. markers = new SuperMap.Layer.Markers("Markers");
  61. layerWorld.events.on({"layerInitialized": addMarker});
  62. }
  63. var infowin = null;
  64. //定义mouseClickHandler函数,触发click事件会调用此函数
  65. function mouseClickHandler(event) {
  66. closeInfoWin();
  67. //初始化popup类
  68. popup = new SuperMap.Popup(
  69. "chicken",
  70. marker.getLonLat(),
  71. new SuperMap.Size(220, 140),
  72. '<img src="./images/xila.jpg">',
  73. true,
  74. null
  75. );
  76. infowin = popup;
  77. //添加弹窗到map图层
  78. map.addPopup(popup);
  79. }
  80. function closeInfoWin() {
  81. if (infowin) {
  82. try {
  83. infowin.hide();
  84. infowin.destroy();
  85. }
  86. catch (e) {
  87. }
  88. }
  89. }
  90. //定义addLayer函数,触发 layerInitialized事件会调用此函数
  91. function addLayer() {
  92. //map上添加分块动态REST图层和标记图层
  93. map.addLayers([layerWorld, markers]);
  94. map.setCenter(new SuperMap.LonLat(23, 38), 4);
  95. }
  96. //定义addMarker函数,触发layerInitialized事件会调用此函数
  97. function addMarker() {
  98. size = new SuperMap.Size(21, 25);
  99. offset = new SuperMap.Pixel(-(size.w / 2), -size.h);
  100. icon = new SuperMap.Icon('images/markerbig_select.png', size, offset);
  101. //初始化标记覆盖物类
  102. marker = new SuperMap.Marker(new SuperMap.LonLat(23.6530190, 37.9439259), icon);
  103. //添加覆盖物到标记图层
  104. markers.addMarker(marker);
  105. //注册 click 事件,触发 mouseClickHandler()方法
  106. marker.events.on({
  107. "click": mouseClickHandler,
  108. "touchstart": mouseClickHandler //假如要在移动端的浏览器也实现点击弹框,则在注册touch类事件
  109. });
  110. }
  111. </script>
  112. </body>
  113. </html>