123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import {
- zjMarker
- } from './ZjMarker.js';
- export class MapUtil {
- constructor(northeast, southwest, scale) {
- this.northeast = northeast;
- this.southwest = southwest;
- this.scale = scale;
- }
- setInitData(northeast, southwest, scale) {
- this.northeast = northeast;
- this.southwest = southwest;
- this.scale = scale;
- }
- checkRefresh(northeast, southwest) {
- let result = true;
- if (this.northeast.latitude > northeast.latitude && this.southwest.latitude < southwest.latitude &&
- this.northeast.longitude > northeast.longitude && this.southwest.longitude < southwest.longitude) {
- result = false
- }
- return result;
- }
- getFortMatMarkerList(northeast, southwest, scale, backendMarkerList) {
- // console.log(scale)
- let mapWidth = southwest.longitude - northeast.longitude;
- let mapHeight = northeast.latitude - southwest.latitude;
- let widthSize = 0;
- if (scale > 10 && scale < 15)
- widthSize = scale - 5;
- else
- widthSize = scale + 3;
- let heightSize = widthSize + parseInt(scale / 2);
- let resultMapArray = [];
- if (scale <= 10) {
- let markerItem = new zjMarker(backendMarkerList[0].longitude, backendMarkerList[0].latitude, backendMarkerList[0].id, {
- type: 'cluster',
- iconPath: '/static/img/cluMarkerIcon.png',
- num: backendMarkerList.length
- });
- resultMapArray.push(markerItem);
- // console.log(resultMapArray)
- return resultMapArray;
- }
- let unitWidth = mapWidth / widthSize;
- let unitHeight = mapHeight / heightSize;
- let pointData = {};
- backendMarkerList.forEach(latLng => {
- if (latLng.latitude < northeast.latitude && latLng.latitude > southwest.latitude &&
- latLng.longitude < northeast.longitude && latLng.longitude > southwest.longitude) {
- let relativeX = latLng.longitude - northeast.longitude;
- let relativeY = latLng.latitude - southwest.latitude;
- let x = parseInt(Math.floor(relativeX / unitWidth));
- let y = parseInt(Math.floor(relativeY / unitHeight));
- if (x < 0 || y < 0) {
- }
- let pointKey = x + ',' + y;
- if (pointData[pointKey] == undefined) {
- pointData[pointKey] = [];
- }
- pointData[pointKey].push(latLng);
- }
- });
- for (let y = 0; y < heightSize; y++) {
- for (let x = 0; x < widthSize; x++) {
- let pointKey = x + ',' + y;
- if (pointData[pointKey] != undefined) {
- let markerItem = {};
- if (pointData[pointKey].length == 1) {
- markerItem = new zjMarker(pointData[pointKey][0].longitude, pointData[pointKey][0].latitude, pointData[pointKey][0].id, {
- iconPath: pointData[pointKey][0].iconPath,
- isSelect: pointData[pointKey][0].isSelect
- })
- } else if (pointData[pointKey].length > 1) {
- markerItem = new zjMarker(pointData[pointKey][0].longitude, pointData[pointKey][0].latitude, pointData[pointKey][0].id, {
- type: 'cluster',
- iconPath: '/static/img/cluMarkerIcon.png',
- num: pointData[pointKey].length
- })
- }
- resultMapArray.push(markerItem);
- }
- }
- }
- // console.log(resultMapArray)
- return resultMapArray;
- }
- }
- module.exports = {
- MapUtil: MapUtil,
- }
|