| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a241001 commit b766efe
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,6 +40,26 @@ describe('classic_AddressMatchService', () => { | |||
| 40 | 40 | codingSuccessEventArgs = null; | |
| 41 | 41 | var codeCompleted = analyseEventArgs => { | |
| 42 | 42 | codingSuccessEventArgs = analyseEventArgs; | |
| 43 | + try { | ||
| 44 | + expect(addressCodeService).not.toBeNull(); | ||
| 45 | + expect(codingSuccessEventArgs).not.toBeNull(); | ||
| 46 | + expect(codingSuccessEventArgs.type).toBe('processCompleted'); | ||
| 47 | + expect(codingSuccessEventArgs.result).not.toBeNull(); | ||
| 48 | + expect(codingSuccessEventArgs.result.length).toBe(10); | ||
| 49 | + addressCodeService.destroy(); | ||
| 50 | + GeoCodingParams.destroy(); | ||
| 51 | + codingSuccessEventArgs = null; | ||
| 52 | + codingFailedEventArgs = null; | ||
| 53 | + done(); | ||
| 54 | + } catch (exception) { | ||
| 55 | + console.log("'code'案例失败:" + exception.name + ":" + exception.message); | ||
| 56 | + addressCodeService.destroy(); | ||
| 57 | + GeoCodingParams.destroy(); | ||
| 58 | + codingFailedEventArgs = null; | ||
| 59 | + codingSuccessEventArgs = null; | ||
| 60 | + expect(false).toBeTruthy(); | ||
| 61 | + done(); | ||
| 62 | + } | ||
| 43 | 63 | }; | |
| 44 | 64 | var codeFailed = (serviceFailedEventArgs) => { | |
| 45 | 65 | codingFailedEventArgs = serviceFailedEventArgs; | |
@@ -65,28 +85,6 @@ describe('classic_AddressMatchService', () => { | |||
| 65 | 85 | }); | |
| 66 | 86 | ||
| 67 | 87 | addressCodeService.code(GeoCodingParams, codeCompleted); | |
| 68 | - setTimeout(() => { | ||
| 69 | - try { | ||
| 70 | - expect(addressCodeService).not.toBeNull(); | ||
| 71 | - expect(codingSuccessEventArgs).not.toBeNull(); | ||
| 72 | - expect(codingSuccessEventArgs.type).toBe('processCompleted'); | ||
| 73 | - expect(codingSuccessEventArgs.result).not.toBeNull(); | ||
| 74 | - expect(codingSuccessEventArgs.result.length).toBe(10); | ||
| 75 | - addressCodeService.destroy(); | ||
| 76 | - GeoCodingParams.destroy(); | ||
| 77 | - codingSuccessEventArgs = null; | ||
| 78 | - codingFailedEventArgs = null; | ||
| 79 | - done(); | ||
| 80 | - } catch (exception) { | ||
| 81 | - console.log("'code'案例失败:" + exception.name + ":" + exception.message); | ||
| 82 | - addressCodeService.destroy(); | ||
| 83 | - GeoCodingParams.destroy(); | ||
| 84 | - codingFailedEventArgs = null; | ||
| 85 | - codingSuccessEventArgs = null; | ||
| 86 | - expect(false).toBeTruthy(); | ||
| 87 | - done(); | ||
| 88 | - } | ||
| 89 | - }, 0); | ||
| 90 | 88 | }); | |
| 91 | 89 | ||
| 92 | 90 | it('decode', (done) => { | |
@@ -96,26 +94,6 @@ describe('classic_AddressMatchService', () => { | |||
| 96 | 94 | }; | |
| 97 | 95 | var decodeCompleted = (analyseEventArgs) => { | |
| 98 | 96 | decodingSuccessEventArgs = analyseEventArgs; | |
| 99 | - }; | ||
| 100 | - var GeoDeCodingParams = new GeoDecodingParameter({ | ||
| 101 | - x: 116.31740122415627, | ||
| 102 | - y: 39.92311315752059, | ||
| 103 | - fromIndex: 0, | ||
| 104 | - toIndex: 5, | ||
| 105 | - filters: '北京市,海淀区', | ||
| 106 | - prjCoordSys: '{epsgcode:4326}', | ||
| 107 | - maxReturn: -1, | ||
| 108 | - geoDecodingRadius: 500 | ||
| 109 | - }); | ||
| 110 | - var addressDeCodeService = new AddressMatchService(addressMatchURL); | ||
| 111 | - spyOn(FetchRequest, 'get').and.callFake((testUrl, params, options) => { | ||
| 112 | - expect(testUrl).toBe(addressMatchURL + "/geodecoding"); | ||
| 113 | - expect(params).not.toBeNull(); | ||
| 114 | - expect(options).not.toBeNull(); | ||
| 115 | - return Promise.resolve(new Response(decodeSuccessEscapedJson)); | ||
| 116 | - }); | ||
| 117 | - addressDeCodeService.decode(GeoDeCodingParams, decodeCompleted); | ||
| 118 | - setTimeout(() => { | ||
| 119 | 97 | try { | |
| 120 | 98 | expect(addressDeCodeService).not.toBeNull(); | |
| 121 | 99 | expect(decodingSuccessEventArgs).not.toBeNull(); | |
@@ -136,6 +114,24 @@ describe('classic_AddressMatchService', () => { | |||
| 136 | 114 | expect(false).toBeTruthy(); | |
| 137 | 115 | done(); | |
| 138 | 116 | } | |
| 139 | - }, 0); | ||
| 117 | + }; | ||
| 118 | + var GeoDeCodingParams = new GeoDecodingParameter({ | ||
| 119 | + x: 116.31740122415627, | ||
| 120 | + y: 39.92311315752059, | ||
| 121 | + fromIndex: 0, | ||
| 122 | + toIndex: 5, | ||
| 123 | + filters: '北京市,海淀区', | ||
| 124 | + prjCoordSys: '{epsgcode:4326}', | ||
| 125 | + maxReturn: -1, | ||
| 126 | + geoDecodingRadius: 500 | ||
| 127 | + }); | ||
| 128 | + var addressDeCodeService = new AddressMatchService(addressMatchURL); | ||
| 129 | + spyOn(FetchRequest, 'get').and.callFake((testUrl, params, options) => { | ||
| 130 | + expect(testUrl).toBe(addressMatchURL + "/geodecoding"); | ||
| 131 | + expect(params).not.toBeNull(); | ||
| 132 | + expect(options).not.toBeNull(); | ||
| 133 | + return Promise.resolve(new Response(decodeSuccessEscapedJson)); | ||
| 134 | + }); | ||
| 135 | + addressDeCodeService.decode(GeoDeCodingParams, decodeCompleted); | ||
| 140 | 136 | }); | |
| 141 | 137 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -319,20 +319,20 @@ describe('openlayers_GraphicLayer', () => { | |||
| 319 | 319 | }) | |
| 320 | 320 | }); | |
| 321 | 321 | map.addLayer(graphicLayer); | |
| 322 | + const key = graphicLayer.on('postrender', function() { | ||
| 323 | + if (graphicLayer.getSource().renderer) { | ||
| 324 | + unByKey(key); | ||
| 325 | + const graphic = graphicLayer.getSource().getGraphicBy("id", 1); | ||
| 326 | + expect(graphic).not.toBeNull(); | ||
| 327 | + expect(graphic.getId()).toEqual(1); | ||
| 322 | 328 | ||
| 323 | - setTimeout(() => { | ||
| 324 | - const graphic = graphicLayer.getSource().getGraphicBy("id", 1); | ||
| 325 | - expect(graphic).not.toBeNull(); | ||
| 326 | - expect(graphic.getId()).toEqual(1); | ||
| 327 | - | ||
| 328 | - const graphic1 = graphicLayer.getSource().getGraphicById(1); | ||
| 329 | - expect(graphic1.getId()).toEqual(1); | ||
| 329 | + const graphic1 = graphicLayer.getSource().getGraphicById(1); | ||
| 330 | + expect(graphic1.getId()).toEqual(1); | ||
| 330 | 331 | ||
| 331 | 332 | // map.removeLayer(graphicLayer); | |
| 332 | - done(); | ||
| 333 | - }, 0) | ||
| 334 | - | ||
| 335 | - | ||
| 333 | + done(); | ||
| 334 | + } | ||
| 335 | + }); | ||
| 336 | 336 | }); | |
| 337 | 337 | it("getGraphicsByAttribute", (done) => { | |
| 338 | 338 | let graphics = []; | |
@@ -359,14 +359,21 @@ describe('openlayers_GraphicLayer', () => { | |||
| 359 | 359 | }) | |
| 360 | 360 | }); | |
| 361 | 361 | map.addLayer(graphicLayer); | |
| 362 | - | ||
| 363 | - setTimeout(() => { | ||
| 364 | - const graphic = graphicLayer.getSource().getGraphicsByAttribute("name", "graphic_1"); | ||
| 365 | - expect(graphic).not.toBeNull(); | ||
| 366 | - expect(graphic[0].getAttributes().name).toBe("graphic_1"); | ||
| 367 | - // map.removeLayer(graphicLayer); | ||
| 368 | - done(); | ||
| 369 | - }, 0); | ||
| 362 | + const key = graphicLayer.on('postrender', function() { | ||
| 363 | + if (graphicLayer.getSource().renderer) { | ||
| 364 | + unByKey(key); | ||
| 365 | + const graphic = graphicLayer.getSource().getGraphicsByAttribute("name", "graphic_1"); | ||
| 366 | + const key1 = graphic[0].on('postrender', function() { | ||
| 367 | + if (graphic[0].getSource().renderer) { | ||
| 368 | + unByKey(key1); | ||
| 369 | + expect(graphic).not.toBeNull(); | ||
| 370 | + expect(graphic[0].getAttributes().name).toBe("graphic_1"); | ||
| 371 | + // map.removeLayer(graphicLayer); | ||
| 372 | + done(); | ||
| 373 | + } | ||
| 374 | + }) | ||
| 375 | + } | ||
| 376 | + }); | ||
| 370 | 377 | }); | |
| 371 | 378 | ||
| 372 | 379 | it("removeGraphics", (done) => { | |
@@ -394,25 +401,27 @@ describe('openlayers_GraphicLayer', () => { | |||
| 394 | 401 | }) | |
| 395 | 402 | }); | |
| 396 | 403 | map.addLayer(graphicLayer); | |
| 404 | + const key = graphicLayer.on('postrender', function() { | ||
| 405 | + if (graphicLayer.getSource().renderer) { | ||
| 406 | + unByKey(key); | ||
| 407 | + const graphicSource = graphicLayer.getSource(); | ||
| 408 | + //删除单个 | ||
| 409 | + let deleteGraphic = graphics[0]; | ||
| 410 | + expect(graphicSource.graphics.length).toEqual(5); | ||
| 411 | + graphicSource.removeGraphics(deleteGraphic); | ||
| 412 | + expect(graphicSource.graphics.length).toEqual(4); | ||
| 397 | 413 | ||
| 398 | - setTimeout(() => { | ||
| 399 | - const graphicSource = graphicLayer.getSource(); | ||
| 400 | - //删除单个 | ||
| 401 | - let deleteGraphic = graphics[0]; | ||
| 402 | - expect(graphicSource.graphics.length).toEqual(5); | ||
| 403 | - graphicSource.removeGraphics(deleteGraphic); | ||
| 404 | - expect(graphicSource.graphics.length).toEqual(4); | ||
| 405 | - | ||
| 406 | - //多个 | ||
| 407 | - deleteGraphic = [graphics[1], graphics[2]]; | ||
| 408 | - graphicSource.removeGraphics(deleteGraphic); | ||
| 409 | - expect(graphicSource.graphics.length).toEqual(2); | ||
| 414 | + //多个 | ||
| 415 | + deleteGraphic = [graphics[1], graphics[2]]; | ||
| 416 | + graphicSource.removeGraphics(deleteGraphic); | ||
| 417 | + expect(graphicSource.graphics.length).toEqual(2); | ||
| 410 | 418 | ||
| 411 | - //默认 | ||
| 412 | - graphicSource.removeGraphics(); | ||
| 413 | - expect(graphicSource.graphics.length).toEqual(0); | ||
| 414 | - done(); | ||
| 415 | - }, 0); | ||
| 419 | + //默认 | ||
| 420 | + graphicSource.removeGraphics(); | ||
| 421 | + expect(graphicSource.graphics.length).toEqual(0); | ||
| 422 | + done(); | ||
| 423 | + } | ||
| 424 | + }); | ||
| 416 | 425 | }); | |
| 417 | 426 | it("getLayerState", (done) => { | |
| 418 | 427 | let graphics = []; | |
@@ -440,13 +449,15 @@ describe('openlayers_GraphicLayer', () => { | |||
| 440 | 449 | }) | |
| 441 | 450 | }); | |
| 442 | 451 | map.addLayer(graphicLayer); | |
| 443 | - | ||
| 444 | - setTimeout(() => { | ||
| 445 | - const state = graphicLayer.getSource().getLayerState(); | ||
| 446 | - expect(state).not.toBeNull(); | ||
| 447 | - expect(state.color).toEqual("red"); | ||
| 448 | - done(); | ||
| 449 | - }, 0); | ||
| 452 | + const key = graphicLayer.on('postrender', function() { | ||
| 453 | + if (graphicLayer.getSource().renderer) { | ||
| 454 | + unByKey(key); | ||
| 455 | + const state = graphicLayer.getSource().getLayerState(); | ||
| 456 | + expect(state).not.toBeNull(); | ||
| 457 | + expect(state.color).toEqual("red"); | ||
| 458 | + done(); | ||
| 459 | + } | ||
| 460 | + }); | ||
| 450 | 461 | }); | |
| 451 | 462 | ||
| 452 | 463 | it("setGraphics", (done) => { | |
@@ -474,23 +485,25 @@ describe('openlayers_GraphicLayer', () => { | |||
| 474 | 485 | }) | |
| 475 | 486 | }); | |
| 476 | 487 | map.addLayer(graphicLayer); | |
| 477 | - | ||
| 478 | - setTimeout(() => { | ||
| 479 | - graphicLayer.getSource().clear(); | ||
| 480 | - expect(graphicLayer.getSource().graphics.length).toEqual(0); | ||
| 481 | - let graphics = []; | ||
| 482 | - for (let j = 0; j < coors.length; ++j) { | ||
| 483 | - graphics[j] = new GraphicObj(new Point(coors[j])); | ||
| 484 | - graphics[j].setId(j); | ||
| 485 | - graphics[j].setAttributes({ | ||
| 486 | - name: "graphic_" + j | ||
| 487 | - }); | ||
| 488 | + const key = graphicLayer.on('postrender', function() { | ||
| 489 | + if (graphicLayer.getSource().renderer) { | ||
| 490 | + unByKey(key); | ||
| 491 | + graphicLayer.getSource().clear(); | ||
| 492 | + expect(graphicLayer.getSource().graphics.length).toEqual(0); | ||
| 493 | + let graphics = []; | ||
| 494 | + for (let j = 0; j < coors.length; ++j) { | ||
| 495 | + graphics[j] = new GraphicObj(new Point(coors[j])); | ||
| 496 | + graphics[j].setId(j); | ||
| 497 | + graphics[j].setAttributes({ | ||
| 498 | + name: "graphic_" + j | ||
| 499 | + }); | ||
| 500 | + } | ||
| 501 | + | ||
| 502 | + graphicLayer.getSource().setGraphics(graphics); | ||
| 503 | + expect(graphicLayer.getSource().graphics.length).toEqual(5); | ||
| 504 | + done() | ||
| 488 | 505 | } | |
| 489 | - | ||
| 490 | - graphicLayer.getSource().setGraphics(graphics); | ||
| 491 | - expect(graphicLayer.getSource().graphics.length).toEqual(5); | ||
| 492 | - done() | ||
| 493 | - }, 0); | ||
| 506 | + }); | ||
| 494 | 507 | }); | |
| 495 | 508 | ||
| 496 | 509 | it("setStyle", (done) => { | |
@@ -519,15 +532,17 @@ describe('openlayers_GraphicLayer', () => { | |||
| 519 | 532 | }) | |
| 520 | 533 | }); | |
| 521 | 534 | map.addLayer(graphicLayer); | |
| 522 | - | ||
| 523 | - setTimeout(() => { | ||
| 524 | - expect(graphicLayer.getSource().color).toEqual("red"); | ||
| 525 | - graphicLayer.getSource().setStyle({ | ||
| 526 | - color: "blue" | ||
| 527 | - }); | ||
| 528 | - expect(graphicLayer.getSource().color).toEqual("blue"); | ||
| 529 | - done() | ||
| 530 | - }, 0); | ||
| 535 | + const key = graphicLayer.on('postrender', function() { | ||
| 536 | + if (graphicLayer.getSource().renderer) { | ||
| 537 | + unByKey(key); | ||
| 538 | + expect(graphicLayer.getSource().color).toEqual("red"); | ||
| 539 | + graphicLayer.getSource().setStyle({ | ||
| 540 | + color: "blue" | ||
| 541 | + }); | ||
| 542 | + expect(graphicLayer.getSource().color).toEqual("blue"); | ||
| 543 | + done() | ||
| 544 | + } | ||
| 545 | + }); | ||
| 531 | 546 | }); | |
| 532 | 547 | ||
| 533 | 548 | it("clear", (done) => { | |
@@ -555,13 +570,15 @@ describe('openlayers_GraphicLayer', () => { | |||
| 555 | 570 | }) | |
| 556 | 571 | }); | |
| 557 | 572 | map.addLayer(graphicLayer); | |
| 558 | - | ||
| 559 | - setTimeout(() => { | ||
| 560 | - const graphicSource = graphicLayer.getSource(); | ||
| 561 | - graphicSource.clear(); | ||
| 562 | - expect(graphicSource.graphics.length).toEqual(0); | ||
| 563 | - done(); | ||
| 564 | - }, 0); | ||
| 573 | + const key = graphicLayer.on('postrender', function() { | ||
| 574 | + if (graphicLayer.getSource().renderer) { | ||
| 575 | + unByKey(key); | ||
| 576 | + const graphicSource = graphicLayer.getSource(); | ||
| 577 | + graphicSource.clear(); | ||
| 578 | + expect(graphicSource.graphics.length).toEqual(0); | ||
| 579 | + done(); | ||
| 580 | + } | ||
| 581 | + }); | ||
| 565 | 582 | }); | |
| 566 | 583 | ||
| 567 | 584 | it('forEachFeatureAtCoordinate_ICL_1047', (done) => { | |
@@ -610,29 +627,32 @@ describe('openlayers_GraphicLayer', () => { | |||
| 610 | 627 | color: "rgba(0,166,0,1)", | |
| 611 | 628 | }), | |
| 612 | 629 | }); | |
| 613 | - setTimeout(() => { | ||
| 614 | - var resgraphics = graphicLayer.getSource(); | ||
| 615 | - for (let j = 0; j < resgraphics.length; ++j) { | ||
| 616 | - resgraphics[j].setStyle(cloverShapeStyle); | ||
| 617 | - var resolution = 1; | ||
| 618 | - var evtPixel = [-35.16, 38.05]; | ||
| 619 | - //1、当鼠标点击在三叶草叶子内时,得到要素,调用高亮函数 | ||
| 620 | - var innerCoors = [25.576171875, -27.158203125]; | ||
| 621 | - var callback = function (a, b) { | ||
| 622 | - expect(b).toNotBe(null); | ||
| 623 | - expect(a.coordinate).toBe([25.576171875, -27.158203125]); | ||
| 624 | - }; | ||
| 625 | - graphicLayer.getSource()._forEachFeatureAtCoordinate(innerCoors, resolution, callback, evtPixel); | ||
| 626 | - spyOn(graphicLayer, '_highLight'); | ||
| 627 | - expect(graphicLayer.getSource()._highLight).toHaveBeenCalled(); | ||
| 628 | - //2、当鼠标点击在三叶草外时, 关闭高亮,返回undefined | ||
| 629 | - var outerCoors = [27.685546875, -26.015625]; | ||
| 630 | - var re = graphicLayer.getSource()._forEachFeatureAtCoordinate(outerCoors, resolution, callback, evtPixel); | ||
| 631 | - spyOn(graphicLayer, '_highLightClose'); | ||
| 632 | - expect(graphicLayer.getSource()._highLightClose).toHaveBeenCalled(); | ||
| 633 | - expect(re).toBe(undefined); | ||
| 630 | + const key = graphicLayer.on('postrender', function() { | ||
| 631 | + if (graphicLayer.getSource().renderer) { | ||
| 632 | + unByKey(key); | ||
| 633 | + var resgraphics = graphicLayer.getSource(); | ||
| 634 | + for (let j = 0; j < resgraphics.length; ++j) { | ||
| 635 | + resgraphics[j].setStyle(cloverShapeStyle); | ||
| 636 | + var resolution = 1; | ||
| 637 | + var evtPixel = [-35.16, 38.05]; | ||
| 638 | + //1、当鼠标点击在三叶草叶子内时,得到要素,调用高亮函数 | ||
| 639 | + var innerCoors = [25.576171875, -27.158203125]; | ||
| 640 | + var callback = function (a, b) { | ||
| 641 | + expect(b).toNotBe(null); | ||
| 642 | + expect(a.coordinate).toBe([25.576171875, -27.158203125]); | ||
| 643 | + }; | ||
| 644 | + graphicLayer.getSource()._forEachFeatureAtCoordinate(innerCoors, resolution, callback, evtPixel); | ||
| 645 | + spyOn(graphicLayer, '_highLight'); | ||
| 646 | + expect(graphicLayer.getSource()._highLight).toHaveBeenCalled(); | ||
| 647 | + //2、当鼠标点击在三叶草外时, 关闭高亮,返回undefined | ||
| 648 | + var outerCoors = [27.685546875, -26.015625]; | ||
| 649 | + var re = graphicLayer.getSource()._forEachFeatureAtCoordinate(outerCoors, resolution, callback, evtPixel); | ||
| 650 | + spyOn(graphicLayer, '_highLightClose'); | ||
| 651 | + expect(graphicLayer.getSource()._highLightClose).toHaveBeenCalled(); | ||
| 652 | + expect(re).toBe(undefined); | ||
| 653 | + } | ||
| 654 | + done(); | ||
| 634 | 655 | } | |
| 635 | - done(); | ||
| 636 | - }, 0); | ||
| 656 | + }); | ||
| 637 | 657 | }); | |
| 638 | 658 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments