14areaby4527.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>计算投影面积</title>
  7. <link rel="stylesheet" href="../dist/ol/ol.css" />
  8. <script src="../dist/index.js"></script>
  9. <style>
  10. * {
  11. padding: 0;
  12. margin: 0;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <div id="map" style="height: 100vh; width: 100vw;"></div>
  18. </body>
  19. <script>
  20. const source = new CTMapOl.source.XYZ({
  21. url: 'http://t0.tianditu.gov.cn/vec_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=86db5390161c4da2abe96c3fca00f403'
  22. })
  23. const tileLayer = new CTMapOl.layer.Tile({
  24. title: '天地图',
  25. source: source
  26. })
  27. var sourceMarker = new CTMapOl.source.XYZ({
  28. url: 'http://t0.tianditu.gov.cn/cva_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=86db5390161c4da2abe96c3fca00f403'
  29. })
  30. const tileMarker = new CTMapOl.layer.Tile({
  31. title: '标注图层',
  32. source: sourceMarker
  33. })
  34. // CTMapOl.proj4.defs("EPSG:4513", "+proj=tmerc +lat_0=0 +lon_0=75 +k=1 +x_0=25500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  35. // CTMapOl.proj4.defs("EPSG:4514", "+proj=tmerc +lat_0=0 +lon_0=78 +k=1 +x_0=26500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  36. // CTMapOl.proj4.defs("EPSG:4515", "+proj=tmerc +lat_0=0 +lon_0=81 +k=1 +x_0=27500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  37. // CTMapOl.proj4.defs("EPSG:4516", "+proj=tmerc +lat_0=0 +lon_0=84 +k=1 +x_0=28500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  38. // CTMapOl.proj4.defs("EPSG:4517", "+proj=tmerc +lat_0=0 +lon_0=87 +k=1 +x_0=29500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  39. // CTMapOl.proj4.defs("EPSG:4518", "+proj=tmerc +lat_0=0 +lon_0=90 +k=1 +x_0=30500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  40. // CTMapOl.proj4.defs("EPSG:4519", "+proj=tmerc +lat_0=0 +lon_0=93 +k=1 +x_0=31500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  41. // CTMapOl.proj4.defs("EPSG:4520", "+proj=tmerc +lat_0=0 +lon_0=96 +k=1 +x_0=32500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  42. // CTMapOl.proj4.defs("EPSG:4521", "+proj=tmerc +lat_0=0 +lon_0=99 +k=1 +x_0=33500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  43. // CTMapOl.proj4.defs("EPSG:4522", "+proj=tmerc +lat_0=0 +lon_0=102 +k=1 +x_0=34500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  44. // CTMapOl.proj4.defs("EPSG:4523", "+proj=tmerc +lat_0=0 +lon_0=105 +k=1 +x_0=35500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  45. // CTMapOl.proj4.defs("EPSG:4524", "+proj=tmerc +lat_0=0 +lon_0=108 +k=1 +x_0=36500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  46. // CTMapOl.proj4.defs("EPSG:4525", "+proj=tmerc +lat_0=0 +lon_0=111 +k=1 +x_0=37500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  47. // CTMapOl.proj4.defs("EPSG:4526", "+proj=tmerc +lat_0=0 +lon_0=114 +k=1 +x_0=38500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  48. // CTMapOl.proj4.defs("EPSG:4527", "+proj=tmerc +lat_0=0 +lon_0=117 +k=1 +x_0=39500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  49. // CTMapOl.proj4.defs("EPSG:4528", "+proj=tmerc +lat_0=0 +lon_0=120 +k=1 +x_0=40500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  50. // CTMapOl.proj4.defs("EPSG:4529", "+proj=tmerc +lat_0=0 +lon_0=123 +k=1 +x_0=41500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  51. // CTMapOl.proj4.defs("EPSG:4530", "+proj=tmerc +lat_0=0 +lon_0=126 +k=1 +x_0=42500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  52. // CTMapOl.proj4.defs("EPSG:4531", "+proj=tmerc +lat_0=0 +lon_0=129 +k=1 +x_0=43500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  53. // CTMapOl.proj4.defs("EPSG:4532", "+proj=tmerc +lat_0=0 +lon_0=132 +k=1 +x_0=44500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  54. // CTMapOl.proj4.defs("EPSG:4533", "+proj=tmerc +lat_0=0 +lon_0=135 +k=1 +x_0=45500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs");
  55. // CTMapOl.proj4register(CTMapOl.proj4)
  56. CTMapOl.extend.initcgcs2000()
  57. const epsg4527 = new CTMapOl.proj.Projection({
  58. code: 'EPSG:4527',
  59. extent: [-Infinity, -Infinity, Infinity, Infinity],
  60. WorldExtent: [-180, -90, 180, 90]
  61. });
  62. const epsg4326 = new CTMapOl.proj.Projection({
  63. code: 'EPSG:4326',
  64. extent: [-180, -90, 180, 90],
  65. WorldExtent: [-180, -90, 180, 90]
  66. });
  67. const map = new CTMapOl.Map({
  68. view: new CTMapOl.View({
  69. projection: 'EPSG:3857',
  70. center: CTMapOl.extend.formatLayer.transCooordinateToOpenlayer([116.39, 39.91]),
  71. // center: [0, 0],
  72. zoom: 16,
  73. maxZoom: 18,
  74. minZoom: 1
  75. }),
  76. layers: [tileLayer, tileMarker],
  77. target: 'map'
  78. })
  79. console.log(epsg4527, epsg4326)
  80. let geom = (new CTMapOl.format.WKT).readGeometry('POLYGON((116.36 39.92,116.39 39.93,116.41 39.92,116.41 39.89,116.39 39.89,116.35 39.91,116.36 39.92))', {
  81. dataProjection: epsg4326
  82. })
  83. console.log(geom, geom.getArea())
  84. // let geom4527 = geom.transform('EPSG:4326', 'EPSG:4527')
  85. // console.log(geom4527.getCoordinates(), geom4527.getArea())
  86. // function getarea(geom)
  87. // {
  88. // let temp=geom.clone()
  89. // let center=CTMapOl.extent.getCenter(geom.getExtent())
  90. // let srid=0;
  91. // if(center[0]<=73.5)
  92. // {
  93. // srid=4513
  94. // }else if(center[0]>=136.5)
  95. // {
  96. // srid=4533
  97. // }else
  98. // {
  99. // srid=Math.floor((center[0]-73.5)/3+4513)
  100. // }
  101. // let targeom = temp.transform('EPSG:4326', 'EPSG:'+srid)
  102. // return targeom.getArea()
  103. // }
  104. console.log(CTMapOl.extend.getarea(geom))
  105. // let area=0
  106. // for(let i=0;i<geom4527.getCoordinates()[0].length;i++)
  107. // {
  108. // area += geom4527.getCoordinates()[0][i][0] * geom4527.getCoordinates()[0][(i+1)%geom4527.getCoordinates()[0].length][1] - geom4527.getCoordinates()[0][i][1] * geom4527.getCoordinates()[0][(i+1)%geom4527.getCoordinates()[0].length][0];
  109. // }
  110. // console.log(Math.abs(area)/2)
  111. </script>
  112. </html>