MapUtil.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import {
  2. zjMarker
  3. } from './ZjMarker.js';
  4. export class MapUtil {
  5. constructor(northeast, southwest, scale) {
  6. this.northeast = northeast;
  7. this.southwest = southwest;
  8. this.scale = scale;
  9. }
  10. setInitData(northeast, southwest, scale) {
  11. this.northeast = northeast;
  12. this.southwest = southwest;
  13. this.scale = scale;
  14. }
  15. checkRefresh(northeast, southwest) {
  16. let result = true;
  17. if (this.northeast.latitude > northeast.latitude && this.southwest.latitude < southwest.latitude &&
  18. this.northeast.longitude > northeast.longitude && this.southwest.longitude < southwest.longitude) {
  19. result = false
  20. }
  21. return result;
  22. }
  23. getFortMatMarkerList(northeast, southwest, scale, backendMarkerList) {
  24. // console.log(scale)
  25. let mapWidth = southwest.longitude - northeast.longitude;
  26. let mapHeight = northeast.latitude - southwest.latitude;
  27. let widthSize = 0;
  28. if (scale > 10 && scale < 15)
  29. widthSize = scale - 5;
  30. else
  31. widthSize = scale + 3;
  32. let heightSize = widthSize + parseInt(scale / 2);
  33. let resultMapArray = [];
  34. if (scale <= 10) {
  35. let markerItem = new zjMarker(backendMarkerList[0].longitude, backendMarkerList[0].latitude, backendMarkerList[0].id, {
  36. type: 'cluster',
  37. iconPath: '/static/img/cluMarkerIcon.png',
  38. num: backendMarkerList.length
  39. });
  40. resultMapArray.push(markerItem);
  41. // console.log(resultMapArray)
  42. return resultMapArray;
  43. }
  44. let unitWidth = mapWidth / widthSize;
  45. let unitHeight = mapHeight / heightSize;
  46. let pointData = {};
  47. backendMarkerList.forEach(latLng => {
  48. if (latLng.latitude < northeast.latitude && latLng.latitude > southwest.latitude &&
  49. latLng.longitude < northeast.longitude && latLng.longitude > southwest.longitude) {
  50. let relativeX = latLng.longitude - northeast.longitude;
  51. let relativeY = latLng.latitude - southwest.latitude;
  52. let x = parseInt(Math.floor(relativeX / unitWidth));
  53. let y = parseInt(Math.floor(relativeY / unitHeight));
  54. if (x < 0 || y < 0) {
  55. }
  56. let pointKey = x + ',' + y;
  57. if (pointData[pointKey] == undefined) {
  58. pointData[pointKey] = [];
  59. }
  60. pointData[pointKey].push(latLng);
  61. }
  62. });
  63. for (let y = 0; y < heightSize; y++) {
  64. for (let x = 0; x < widthSize; x++) {
  65. let pointKey = x + ',' + y;
  66. if (pointData[pointKey] != undefined) {
  67. let markerItem = {};
  68. if (pointData[pointKey].length == 1) {
  69. markerItem = new zjMarker(pointData[pointKey][0].longitude, pointData[pointKey][0].latitude, pointData[pointKey][0].id, {
  70. iconPath: pointData[pointKey][0].iconPath,
  71. isSelect: pointData[pointKey][0].isSelect
  72. })
  73. } else if (pointData[pointKey].length > 1) {
  74. markerItem = new zjMarker(pointData[pointKey][0].longitude, pointData[pointKey][0].latitude, pointData[pointKey][0].id, {
  75. type: 'cluster',
  76. iconPath: '/static/img/cluMarkerIcon.png',
  77. num: pointData[pointKey].length
  78. })
  79. }
  80. resultMapArray.push(markerItem);
  81. }
  82. }
  83. }
  84. // console.log(resultMapArray)
  85. return resultMapArray;
  86. }
  87. }
  88. module.exports = {
  89. MapUtil: MapUtil,
  90. }