f25_textMaterial.html 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
  6. <meta name="author" content="火星科技 http://mars3d.cn " />
  7. <meta name="apple-touch-fullscreen" content="yes" />
  8. <meta name="apple-mobile-web-app-capable" content="yes" />
  9. <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  10. <meta name="format-detection" content="telephone=no" />
  11. <meta name="x5-fullscreen" content="true" />
  12. <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
  13. <!-- 标题及搜索关键字 -->
  14. <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
  15. <meta
  16. name="description"
  17. content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型 gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包 地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS"
  18. />
  19. <link rel="shortcut icon" type="image/x-icon" href="" />
  20. <title>文字贴图 </title>
  21. <!--第三方lib-->
  22. <script
  23. type="text/javascript"
  24. src="../lib/include-lib.js"
  25. libpath="../lib/"
  26. include="jquery,jquery.range,font-awesome,bootstrap,bootstrap-checkbox,layer,haoutil,turf,mars3d"
  27. ></script>
  28. <link href="css/style.css" rel="stylesheet" />
  29. </head>
  30. <body class="dark">
  31. <!--加载前进行操作提示,优化用户体验-->
  32. <div id="mask" class="signmask" onclick="removeMask()"></div>
  33. <div id="mars3dContainer" class="mars3d-container"></div>
  34. <div class="infoview">
  35. <div>
  36. 图层状态:
  37. <div class="checkbox checkbox-primary checkbox-inline">
  38. <input id="chkPopup" class="styled" type="checkbox" checked />
  39. <label for="chkPopup"> Popup绑定 </label>
  40. </div>
  41. <div class="checkbox checkbox-primary checkbox-inline">
  42. <input id="chkTooltip" class="styled" type="checkbox" />
  43. <label for="chkTooltip"> Tooltip绑定 </label>
  44. </div>
  45. <div class="checkbox checkbox-primary checkbox-inline">
  46. <input id="chkContextMenu" class="styled" type="checkbox" checked />
  47. <label for="chkContextMenu"> 右键菜单绑定 </label>
  48. </div>
  49. </div>
  50. <div>
  51. 大数据加载:
  52. <input id="txtCount" type="number" value="500" min="1" max="10000" step="1" class="form-control" style="width: 80px" />条
  53. <input type="button" class="btn btn-primary" value="生成" id="btnAddData" />
  54. <input type="button" class="btn btn-primary" value="清除" id="btnClear" />
  55. </div>
  56. </div>
  57. <!-- 图层管理相关处理js -->
  58. <script type="text/javascript" src="./js/graphicManager.js"></script>
  59. <script src="./js/common.js"></script>
  60. <script type="text/javascript">
  61. "use script"; //开发环境建议开启严格模式
  62. var map;
  63. function initMap(options) {
  64. //合并属性参数,可覆盖config.json中的对应配置
  65. var mapOptions = mars3d.Util.merge(options, {
  66. scene: {
  67. center: { lat: 29.792193, lng: 121.48008, alt: 122, heading: 198, pitch: -54 },
  68. },
  69. });
  70. //创建三维地球场景
  71. map = new mars3d.Map("mars3dContainer", mapOptions);
  72. //加个模型
  73. var tiles3dLayer = new mars3d.layer.TilesetLayer({
  74. name: "水利闸门",
  75. url: "//data.mars3d.cn/3dtiles/max-fsdzm/tileset.json",
  76. position: { alt: 15.2 },
  77. maximumScreenSpaceError: 1,
  78. maximumMemoryUsage: 1024,
  79. });
  80. map.addLayer(tiles3dLayer);
  81. //创建矢量数据图层
  82. var graphicLayer = new mars3d.layer.GraphicLayer({
  83. hasEdit: true,
  84. });
  85. map.addLayer(graphicLayer);
  86. //图层管理的相关处理,代码在\js\graphicManager.js
  87. initLayerManager(graphicLayer);
  88. $("#btnAddData").click(function () {
  89. graphicLayer.clear();
  90. map.centerAt({ lat: 29.81612, lng: 121.476177, alt: 945, heading: 179, pitch: -22 });
  91. haoutil.loading.show();
  92. var startTime = new Date().getTime();
  93. var count = Number($("#txtCount").val());
  94. //取区域内的随机图标
  95. function randomPoint(j) {
  96. var jd = haoutil.math.random(121.460727 * 1000, 121.494659 * 1000) / 1000;
  97. var wd = haoutil.math.random(29.778576 * 1000, 29.806463 * 1000) / 1000;
  98. return Cesium.Cartesian3.fromDegrees(jd, wd, 20);
  99. }
  100. let txtWidth = 90; //图片宽度,单位:米
  101. let txtHeight = 40; //图片高度,单位:米
  102. //多个面对象的合并渲染。
  103. const instances = [];
  104. for (var j = 0; j < count; ++j) {
  105. var position = randomPoint(j);
  106. var pt1 = mars3d.PointUtil.getPositionByDirectionAndLen(position, 160, txtWidth);
  107. var primitive = new mars3d.graphic.WallPrimitive({
  108. positions: [position, pt1],
  109. style: {
  110. diffHeight: txtHeight,
  111. materialType: mars3d.MaterialType.Text,
  112. text: "第" + j + "个",
  113. font_family: "楷体",
  114. fillColor: "#00ffff",
  115. },
  116. tooltip: "第" + j + "个",
  117. });
  118. graphicLayer.addGraphic(primitive);
  119. }
  120. haoutil.loading.close();
  121. var endTime = new Date().getTime();
  122. // 两个时间戳相差的毫秒数
  123. var usedTime = (endTime - startTime) / 1000;
  124. console.log(usedTime);
  125. haoutil.msg("共耗时" + usedTime.toFixed(2) + "秒");
  126. });
  127. //加一些演示数据
  128. addGraphic_01(graphicLayer);
  129. addGraphic_02(graphicLayer);
  130. addGraphic_03(graphicLayer);
  131. addGraphic_04(graphicLayer);
  132. }
  133. // wall文字 primitive方式添加
  134. function addGraphic_01(graphicLayer) {
  135. var primitive = new mars3d.graphic.WallPrimitive({
  136. positions: [
  137. [121.479914, 29.791249, 32],
  138. [121.479694, 29.791303, 32],
  139. ],
  140. style: {
  141. diffHeight: 5,
  142. materialType: mars3d.MaterialType.Text,
  143. text: "水利闸门",
  144. font_family: "楷体",
  145. fillColor: "#00ffff",
  146. },
  147. });
  148. graphicLayer.addGraphic(primitive);
  149. }
  150. // wall文字 primitive方式添加
  151. function addGraphic_02(graphicLayer) {
  152. var primitive = new mars3d.graphic.WallPrimitive({
  153. positions: [
  154. [121.479343, 29.791419, 35],
  155. [121.479197, 29.791474, 35],
  156. ],
  157. style: {
  158. diffHeight: 5,
  159. material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.Text, {
  160. text: "火星科技",
  161. font_size: 70,
  162. fillColor: "#3388cc",
  163. outlineWidth: 4,
  164. }),
  165. },
  166. });
  167. graphicLayer.addGraphic(primitive);
  168. }
  169. //rectangle贴地矩形 3dtiles路面文字
  170. function addGraphic_03(graphicLayer) {
  171. var rectanglePrimitive = new mars3d.graphic.RectanglePrimitive({
  172. name: "路面文字",
  173. positions: [
  174. [121.479989, 29.791162],
  175. [121.480114, 29.791201],
  176. ],
  177. style: {
  178. clampToGround: true,
  179. material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.Text, {
  180. text: "火星路",
  181. font_size: 50,
  182. font_family: "楷体",
  183. fillColor: "#00ff00",
  184. stroke: true,
  185. strokeWidth: 2,
  186. strokeColor: "#ffffff",
  187. }),
  188. rotationDegree: 163,
  189. //高亮时的样式(默认为鼠标移入,也可以指定type:'click'单击高亮),构造后也可以openHighlight、closeHighlight方法来手动调用
  190. highlight: {
  191. type: mars3d.EventType.click,
  192. stroke: true,
  193. strokeColor: new Cesium.Color(1.0, 1.0, 0.0, 0.8),
  194. strokeWidth: 5,
  195. },
  196. },
  197. });
  198. graphicLayer.addGraphic(rectanglePrimitive);
  199. }
  200. function addGraphic_04(graphicLayer) {
  201. var rectanglePrimitive = new mars3d.graphic.RectanglePrimitive({
  202. positions: [
  203. [121.479593, 29.791632, 13],
  204. [121.480136, 29.79169, 13],
  205. ],
  206. style: {
  207. material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.Text, {
  208. text: "火星科技Mars3D平台",
  209. font_size: 70,
  210. fillColor: new Cesium.Color(1.0, 1.0, 0.0, 1.0),
  211. stroke: true,
  212. strokeWidth: 2,
  213. strokeColor: new Cesium.Color(1.0, 1.0, 1.0, 0.8),
  214. }),
  215. rotation: Cesium.Math.toRadians(163),
  216. stRotation: Cesium.Math.toRadians(163),
  217. clampToGround: true,
  218. },
  219. });
  220. graphicLayer.addGraphic(rectanglePrimitive);
  221. }
  222. </script>
  223. </body>
  224. </html>