From e967b16bd4517f98a8e9306a4c6092e2dea6a567 Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Tue, 14 Aug 2018 09:09:07 +0800
Subject: [PATCH] 固定网格

---
 src/app/routes/grid-trace/grid-trace.component.ts |   29 +++++++++++++++++++++++------
 1 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/src/app/routes/grid-trace/grid-trace.component.ts b/src/app/routes/grid-trace/grid-trace.component.ts
index 5180555..82d59aa 100644
--- a/src/app/routes/grid-trace/grid-trace.component.ts
+++ b/src/app/routes/grid-trace/grid-trace.component.ts
@@ -62,11 +62,18 @@
     //map���������������
     // TODO ������
     bs() {
+        debugger;
         var bs = this._map.getBounds();  //������������������������������������
         // var bssw = bs.getSouthWest();		//���������������������������(������������)
         // var bsne = bs.getNorthEast();		//���������������������������(������������)
+        if(!this.topLeftAnchor){
+            this.topLeftAnchor = {x0:0,y0:0};
+            this.topLeftAnchor.x0 =  bs.Ol.lng;
+            this.topLeftAnchor.y0 =  bs.xl.lat;
+		}
         return { 'x1': bs.Ol.lng, 'y1': bs.Ol.lat, 'x2': bs.xl.lng, 'y2': bs.xl.lat };
     }
+    private topLeftAnchor = null;
     /**
      * ������������
      */
@@ -74,16 +81,26 @@
     private showGridPolygons = [];
     showGrid(){
         const XY = this.bs();
-        console.log(XY);
+        var X1 = XY.x1;
+        var Y2 = XY.y2;
+        var X0 = this.topLeftAnchor.x0;
+        var Y0 = this.topLeftAnchor.y0;
+        var width = 0.0063;
+        var height = 0.0048;
+        // var multiple = 1000000;
+        if(!!this.topLeftAnchor) {
+            X1=X0 + Math.ceil((X1-X0)/width-1)*width;
+            Y2=Y0 + Math.ceil((Y2-Y0)/height)*height;
+		}
         let polygons = [];
-        for (let i = XY.x1; i < XY.x2; i = i + 0.0063) {
-            for (let j = XY.y2; j > XY.y1; j = j - 0.0048) {
+        for (let i = X1; i < XY.x2; i = i + width) {
+            for (let j = Y2; j > XY.y1; j = j - height) {
                 //���������������������������������������������������:������������������Point���������������������������,���������������������������,���������������������������,���������������������������������������������������������������������������������������������������������������,������������������������������������������������������������������
                 const polygon = new window.BMap.Polygon([
                     new window.BMap.Point(i, j),    //������������������
-                    new window.BMap.Point(i, j-0.0048),  //������������������
-                    new window.BMap.Point(i+0.0063, j-0.0048),	 //������������������
-                    new window.BMap.Point(i+0.0063, j)			//������������������
+                    new window.BMap.Point(i, j-height),  //������������������
+                    new window.BMap.Point(i+width, j-height),	 //������������������
+                    new window.BMap.Point(i+width, j)			//������������������
                 ], {strokeColor:"blue", strokeWeight:2, strokeOpacity:0.5, fillOpacity:0.1});
                 // polygon .addEventListener("click",function clickFunction(){
                 //     alert("������������������");

--
Gitblit v1.8.0