others_SM_OSMBuildings_addGeoJson.html 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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>Supermap BUildings add GeoJson Data</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="margin:0 auto;width: 100%;height: 100%"></div>
  12. <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
  13. <script type="text/javascript" exclude="iclient-classic" include="OSMBuildings-SuperMap"
  14. src="../../dist/classic/include-classic.js"></script>
  15. <script type="text/javascript">
  16. var map, layer, osm,
  17. host = window.isLocal ? window.server : "https://iserver.supermap.io";
  18. url = host + "/iserver/services/map-china400/rest/maps/China";
  19. //检测浏览器是啥支持canves Buildings 需要Canvas绘制
  20. if (!document.createElement('canvas').getContext) {
  21. widgets.alert.showAlert(resources.msg_supportCanvas, false);
  22. }
  23. //初始化地图
  24. map = new SuperMap.Map("map", {
  25. controls: [
  26. new SuperMap.Control.Navigation(),
  27. new SuperMap.Control.MousePosition(),
  28. new SuperMap.Control.LayerSwitcher(),
  29. new SuperMap.Control.Zoom()
  30. ]
  31. });
  32. //初始化图层
  33. layer = new SuperMap.Layer.TiledDynamicRESTLayer("China", url, null, {maxResolution: "auto"});
  34. //监听图层信息加载完成事件
  35. layer.events.on({"layerInitialized": addLayer});
  36. //异步加载图层
  37. function addLayer() {
  38. map.addLayers([layer]);
  39. map.setCenter(new SuperMap.LonLat(12957186.36784, 4852711.53595), 12);
  40. // Supermap 底图上 添加默认的 OSMBuildings geojson 数据
  41. var geoJSON = {
  42. "type": "FeatureCollection",
  43. "features": [{
  44. "type": "Feature",
  45. "id": 134,
  46. "geometry": {
  47. "type": "Polygon",
  48. "coordinates": [[
  49. [116.39211, 39.91289],
  50. [116.39278, 39.90844],
  51. [116.39654, 39.90860],
  52. [116.39614, 39.91305],
  53. [116.39211, 39.91289]
  54. ]]
  55. },
  56. "properties": {
  57. "wallColor": "#DDDDDD",
  58. "roofColor": "#F9F7F4",
  59. "height": 20,
  60. "minHeight": 0,
  61. "roofHeight": 5,
  62. "roofShape": "pyramid"
  63. }
  64. }]
  65. };
  66. osm = new OSMBuildings(map);
  67. osm.load();
  68. osm.date(new Date()); //设置当前时间 计算OSMBuildings 阴影
  69. osm.set(geoJSON);
  70. osm.click(function (e) {
  71. // 返回当前点击的feature ID 和 当前的经纬度
  72. //Buildings 单击事件 返回当前Building的ID 和 经纬度
  73. widgets.alert.showAlert("FeatureID:" + e.feature, true);
  74. });
  75. }
  76. </script>
  77. </body>
  78. </html>