| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,4 +81,37 @@ describe('GraphMap leaflet', () => { | |||
| 81 | 81 | } | |
| 82 | 82 | }); | |
| 83 | 83 | }); | |
| 84 | + it('no graph highlight clearHighlight', (done) => { | ||
| 85 | + spyOn(FetchRequest, 'get').and.callFake((testUrl) => { | ||
| 86 | + if (testUrl.includes('/query.json')) { | ||
| 87 | + return Promise.resolve(new Response(queryData)); | ||
| 88 | + } | ||
| 89 | + if (testUrl === knowledgegraphURL + '/graphmaps/xxx图谱.json') { | ||
| 90 | + expect(testUrl).toBe(knowledgegraphURL + '/graphmaps/xxx图谱.json'); | ||
| 91 | + return Promise.resolve(new Response(graphmapData)); | ||
| 92 | + } | ||
| 93 | + if (testUrl.includes('/shortestPath.json')) { | ||
| 94 | + expect(testUrl).toBe(knowledgegraphURL + '/shortestPath.json?startID=38756&endID=38757'); | ||
| 95 | + return Promise.resolve(new Response(findShortestPathData)); | ||
| 96 | + } | ||
| 97 | + }); | ||
| 98 | + var graphMap = new GraphMap(knowledgegraphmapURL, { config: { center: [0, 0] } }); | ||
| 99 | + graphMap.createGraphMap = () => {}; | ||
| 100 | + | ||
| 101 | + graphMap.on('loaded', () => { | ||
| 102 | + try { | ||
| 103 | + expect(graphMap).not.toBeNull(); | ||
| 104 | + graphMap.graph = null; | ||
| 105 | + const res = graphMap.highlight(); | ||
| 106 | + const res1 = graphMap.clearHighlight(); | ||
| 107 | + expect(res).toBeUndefined(); | ||
| 108 | + expect(res1).toBeUndefined(); | ||
| 109 | + done(); | ||
| 110 | + } catch (exception) { | ||
| 111 | + console.log("'no graph highlight clearHighlight'案例失败:" + exception.name + ':' + exception.message); | ||
| 112 | + expect(false).toBeTruthy(); | ||
| 113 | + done(); | ||
| 114 | + } | ||
| 115 | + }); | ||
| 116 | + }); | ||
| 84 | 117 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -82,4 +82,34 @@ describe('GraphMap mapboxgl', () => { | |||
| 82 | 82 | } | |
| 83 | 83 | }); | |
| 84 | 84 | }); | |
| 85 | + it('no graph highlight clearHighlight', (done) => { | ||
| 86 | + spyOn(FetchRequest, 'get').and.callFake((testUrl) => { | ||
| 87 | + if (testUrl.includes('/query.json')) { | ||
| 88 | + return Promise.resolve(new Response(queryData)); | ||
| 89 | + } | ||
| 90 | + if (testUrl === knowledgegraphURL + '/graphmaps/xxx图谱.json') { | ||
| 91 | + expect(testUrl).toBe(knowledgegraphURL + '/graphmaps/xxx图谱.json'); | ||
| 92 | + return Promise.resolve(new Response(graphmapData)); | ||
| 93 | + } | ||
| 94 | + if (testUrl.includes('/shortestPath.json')) { | ||
| 95 | + expect(testUrl).toBe(knowledgegraphURL + '/shortestPath.json?startID=38756&endID=38757'); | ||
| 96 | + return Promise.resolve(new Response(findShortestPathData)); | ||
| 97 | + } | ||
| 98 | + }); | ||
| 99 | + var graphMap = new GraphMap(knowledgegraphmapURL, { config: { center: [0, 0] } }); | ||
| 100 | + graphMap.createGraphMap = () => {}; | ||
| 101 | + try { | ||
| 102 | + expect(graphMap).not.toBeNull(); | ||
| 103 | + graphMap.graph = null; | ||
| 104 | + const res = graphMap.highlight(); | ||
| 105 | + const res1 = graphMap.clearHighlight(); | ||
| 106 | + expect(res).toBeUndefined(); | ||
| 107 | + expect(res1).toBeUndefined(); | ||
| 108 | + done(); | ||
| 109 | + } catch (exception) { | ||
| 110 | + console.log("'no graph highlight clearHighlight'案例失败:" + exception.name + ':' + exception.message); | ||
| 111 | + expect(false).toBeTruthy(); | ||
| 112 | + done(); | ||
| 113 | + } | ||
| 114 | + }); | ||
| 85 | 115 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,7 @@ var url = GlobeParameter.ChinaURL + '/zxyTileImage.png?z={z}&x={x}&y={y}'; | |||
| 8 | 8 | ||
| 9 | 9 | describe('mapboxgl L7Layer', () => { | |
| 10 | 10 | var originalTimeout; | |
| 11 | - var testDiv, map, getL7Scene, setLayoutProperty; | ||
| 11 | + var testDiv, map, getL7Scene, setLayoutProperty, removeLayer; | ||
| 12 | 12 | var data = [ | |
| 13 | 13 | { | |
| 14 | 14 | id: '5011000000404', | |
@@ -22,17 +22,16 @@ describe('mapboxgl L7Layer', () => { | |||
| 22 | 22 | beforeAll((done) => { | |
| 23 | 23 | getL7Scene = mapboxgl.Map.prototype.getL7Scene; | |
| 24 | 24 | setLayoutProperty = mapboxgl.Map.prototype.setLayoutProperty; | |
| 25 | + removeLayer = mapboxgl.Map.prototype.removeLayer; | ||
| 25 | 26 | mbglmap.prototype.getL7Scene = getL7Scene; | |
| 26 | 27 | mbglmap.prototype.setLayoutProperty = setLayoutProperty; | |
| 28 | + | ||
| 27 | 29 | spyOn(mapboxgl, 'Map').and.callFake(mbglmap); | |
| 28 | 30 | ||
| 29 | 31 | spyOn(L7, 'PointLayer').and.callFake(mockL7.PointLayer); | |
| 30 | 32 | spyOn(L7, 'GeometryLayer').and.callFake(mockL7.GeometryLayer); | |
| 31 | 33 | spyOn(L7, 'Scene').and.callFake(mockL7.Scene); | |
| 32 | 34 | spyOn(L7, 'Mapbox').and.callFake(mockL7.Mapbox); | |
| 33 | - // Scene = mockL7.Scene; | ||
| 34 | - // Mapbox = mockL7.Mapbox; | ||
| 35 | - // mapboxgl.Map.prototype.getCRS = () => ({ fromWGS84: (val) => val, getExtent: () => [] }); | ||
| 36 | 35 | testDiv = window.document.createElement('div'); | |
| 37 | 36 | testDiv.setAttribute('id', 'map'); | |
| 38 | 37 | testDiv.style.styleFloat = 'left'; | |
@@ -65,6 +64,8 @@ describe('mapboxgl L7Layer', () => { | |||
| 65 | 64 | center: [112, 37.94], | |
| 66 | 65 | zoom: 13 | |
| 67 | 66 | }); | |
| 67 | + map.removeLayer = removeLayer; | ||
| 68 | + map.style.removeLayer = () => {}; | ||
| 68 | 69 | map.on('load', function () { | |
| 69 | 70 | done(); | |
| 70 | 71 | }); | |
@@ -86,6 +87,7 @@ describe('mapboxgl L7Layer', () => { | |||
| 86 | 87 | it('getL7Scene', (done) => { | |
| 87 | 88 | map.getL7Scene().then((scene) => { | |
| 88 | 89 | expect(scene).not.toBeNull(); | |
| 90 | + map.$l7scene = null; | ||
| 89 | 91 | done(); | |
| 90 | 92 | }); | |
| 91 | 93 | }); | |
@@ -108,6 +110,7 @@ describe('mapboxgl L7Layer', () => { | |||
| 108 | 110 | .color('#4cfd47'); | |
| 109 | 111 | map.getL7Scene().then((scene) => { | |
| 110 | 112 | expect(scene).not.toBeNull(); | |
| 113 | + map.$l7scene = null; | ||
| 111 | 114 | done(); | |
| 112 | 115 | }); | |
| 113 | 116 | }); | |
@@ -271,7 +274,6 @@ describe('mapboxgl L7Layer', () => { | |||
| 271 | 274 | expect(map.style.setLayoutProperty).toHaveBeenCalled(); | |
| 272 | 275 | expect(layer.animateStatus).toBeFalsy(); | |
| 273 | 276 | ||
| 274 | - | ||
| 275 | 277 | map.setLayoutProperty(layer.id, 'visibility', 'visible'); | |
| 276 | 278 | expect(l7Layer.show).toHaveBeenCalled(); | |
| 277 | 279 | expect(map.style.setLayoutProperty).toHaveBeenCalled(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,42 @@ | |||
| 1 | + import { Util } from '../../../src/maplibregl/core/Util'; | ||
| 2 | + | ||
| 3 | + describe('Util', () => { | ||
| 4 | + it('isString', () => { | ||
| 5 | + expect(Util.isString('m')).toBeTruthy(); | ||
| 6 | + expect(Util.isString(5)).toBeFalsy(); | ||
| 7 | + }); | ||
| 8 | + it('toSuperMapPoint', () => { | ||
| 9 | + expect(Util.toSuperMapPoint([110, 10]).x).toBe(110); | ||
| 10 | + expect(Util.toSuperMapPoint({ lng: 110, lat: 10 }).x).toBe(110); | ||
| 11 | + expect(Util.toSuperMapPoint({ geometry: { coordinates: [110, 10] } }).x).toBe(110); | ||
| 12 | + }); | ||
| 13 | + it('toGeoJSON', () => { | ||
| 14 | + expect(Util.toGeoJSON([{ type: 'Feature', properties: {} }]).type).toBe('FeatureCollection'); | ||
| 15 | + }); | ||
| 16 | + it('toProcessingParam', () => { | ||
| 17 | + expect(Util.toProcessingParam([[110, 10]]).type).toBe('REGION'); | ||
| 18 | + }); | ||
| 19 | + it('isNumber', () => { | ||
| 20 | + expect(Util.isNumber(5)).toBeTruthy(); | ||
| 21 | + expect(Util.isNumber(isNaN)).toBeFalsy(); | ||
| 22 | + expect(Util.isNumber('d')).toBeFalsy(); | ||
| 23 | + expect(Util.isNumber('5')).toBeTruthy(); | ||
| 24 | + expect(Util.isNumber('5f')).toBeFalsy(); | ||
| 25 | + expect(Util.isNumber('')).toBeFalsy(); | ||
| 26 | + }); | ||
| 27 | + it('newGuid', () => { | ||
| 28 | + expect(Util.newGuid().length).toBe(31); | ||
| 29 | + expect(Util.newGuid(6).length).toBe(5); | ||
| 30 | + }); | ||
| 31 | + it('hexToRgba', () => { | ||
| 32 | + expect(Util.hexToRgba('#fff', 1)).toBe('rgba(255,255,255,1)'); | ||
| 33 | + expect(Util.hexToRgba('#ffffff', 1)).toBe('rgba(255,255,255,1)'); | ||
| 34 | + }); | ||
| 35 | + it('isMatchAdministrativeName', () => { | ||
| 36 | + expect(Util.isMatchAdministrativeName('张家界', '张家界市')).toBeTruthy(); | ||
| 37 | + expect(Util.isMatchAdministrativeName('张家口', '张家界市')).toBeFalsy(); | ||
| 38 | + expect(Util.isMatchAdministrativeName('张家口', '张家口市')).toBeTruthy(); | ||
| 39 | + expect(Util.isMatchAdministrativeName('北京', '北京市')).toBeTruthy(); | ||
| 40 | + expect(Util.isMatchAdministrativeName('北京', null)).toBeFalsy(); | ||
| 41 | + }); | ||
| 42 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,4 +81,37 @@ describe('GraphMap maplibregl', () => { | |||
| 81 | 81 | } | |
| 82 | 82 | }); | |
| 83 | 83 | }); | |
| 84 | + it('no graph highlight clearHighlight', (done) => { | ||
| 85 | + spyOn(FetchRequest, 'get').and.callFake((testUrl) => { | ||
| 86 | + if (testUrl.includes('/query.json')) { | ||
| 87 | + return Promise.resolve(new Response(queryData)); | ||
| 88 | + } | ||
| 89 | + if (testUrl === knowledgegraphURL + '/graphmaps/xxx图谱.json') { | ||
| 90 | + expect(testUrl).toBe(knowledgegraphURL + '/graphmaps/xxx图谱.json'); | ||
| 91 | + return Promise.resolve(new Response(graphmapData)); | ||
| 92 | + } | ||
| 93 | + if (testUrl.includes('/shortestPath.json')) { | ||
| 94 | + expect(testUrl).toBe(knowledgegraphURL + '/shortestPath.json?startID=38756&endID=38757'); | ||
| 95 | + return Promise.resolve(new Response(findShortestPathData)); | ||
| 96 | + } | ||
| 97 | + }); | ||
| 98 | + var graphMap = new GraphMap(knowledgegraphmapURL, { config: { center: [0, 0] } }); | ||
| 99 | + graphMap.createGraphMap = () => {}; | ||
| 100 | + | ||
| 101 | + graphMap.on('loaded', () => { | ||
| 102 | + try { | ||
| 103 | + expect(graphMap).not.toBeNull(); | ||
| 104 | + graphMap.graph = null; | ||
| 105 | + const res = graphMap.highlight(); | ||
| 106 | + const res1 = graphMap.clearHighlight(); | ||
| 107 | + expect(res).toBeUndefined(); | ||
| 108 | + expect(res1).toBeUndefined(); | ||
| 109 | + done(); | ||
| 110 | + } catch (exception) { | ||
| 111 | + console.log("'no graph highlight clearHighlight'案例失败:" + exception.name + ':' + exception.message); | ||
| 112 | + expect(false).toBeTruthy(); | ||
| 113 | + done(); | ||
| 114 | + } | ||
| 115 | + }); | ||
| 116 | + }); | ||
| 84 | 117 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,7 @@ var url = GlobeParameter.ChinaURL + '/zxyTileImage.png?z={z}&x={x}&y={y}'; | |||
| 8 | 8 | ||
| 9 | 9 | describe('maplibregl L7Layer', () => { | |
| 10 | 10 | var originalTimeout; | |
| 11 | - var testDiv, map, getL7Scene, setLayoutProperty; | ||
| 11 | + var testDiv, map, getL7Scene, setLayoutProperty,removeLayer; | ||
| 12 | 12 | var data = [ | |
| 13 | 13 | { | |
| 14 | 14 | id: '5011000000404', | |
@@ -22,7 +22,9 @@ describe('maplibregl L7Layer', () => { | |||
| 22 | 22 | beforeAll((done) => { | |
| 23 | 23 | getL7Scene = maplibregl.Map.prototype.getL7Scene; | |
| 24 | 24 | setLayoutProperty = maplibregl.Map.prototype.setLayoutProperty; | |
| 25 | + removeLayer = maplibregl.Map.prototype.removeLayer; | ||
| 25 | 26 | mbglmap.prototype.getL7Scene = getL7Scene; | |
| 27 | + | ||
| 26 | 28 | spyOn(maplibregl, 'Map').and.callFake(mbglmap); | |
| 27 | 29 | ||
| 28 | 30 | spyOn(L7, 'PointLayer').and.callFake(mockL7.PointLayer); | |
@@ -62,6 +64,8 @@ describe('maplibregl L7Layer', () => { | |||
| 62 | 64 | center: [112, 37.94], | |
| 63 | 65 | zoom: 13 | |
| 64 | 66 | }); | |
| 67 | + map.removeLayer = removeLayer; | ||
| 68 | + map.style.removeLayer = () => {}; | ||
| 65 | 69 | map.on('load', function () { | |
| 66 | 70 | done(); | |
| 67 | 71 | }); | |
@@ -82,6 +86,7 @@ describe('maplibregl L7Layer', () => { | |||
| 82 | 86 | it('getL7Scene', (done) => { | |
| 83 | 87 | map.getL7Scene().then((scene) => { | |
| 84 | 88 | expect(scene).not.toBeNull(); | |
| 89 | + map.$l7scene = null; | ||
| 85 | 90 | done(); | |
| 86 | 91 | }); | |
| 87 | 92 | }); | |
@@ -103,6 +108,7 @@ describe('maplibregl L7Layer', () => { | |||
| 103 | 108 | .color('#4cfd47'); | |
| 104 | 109 | map.getL7Scene().then((scene) => { | |
| 105 | 110 | expect(scene).not.toBeNull(); | |
| 111 | + map.$l7scene = null; | ||
| 106 | 112 | done(); | |
| 107 | 113 | }); | |
| 108 | 114 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,4 +81,37 @@ describe('GraphMap openlayers', () => { | |||
| 81 | 81 | } | |
| 82 | 82 | }); | |
| 83 | 83 | }); | |
| 84 | + it('no graph highlight clearHighlight', (done) => { | ||
| 85 | + spyOn(FetchRequest, 'get').and.callFake((testUrl) => { | ||
| 86 | + if (testUrl.includes('/query.json')) { | ||
| 87 | + return Promise.resolve(new Response(queryData)); | ||
| 88 | + } | ||
| 89 | + if (testUrl === knowledgegraphURL + '/graphmaps/xxx图谱.json') { | ||
| 90 | + expect(testUrl).toBe(knowledgegraphURL + '/graphmaps/xxx图谱.json'); | ||
| 91 | + return Promise.resolve(new Response(graphmapData)); | ||
| 92 | + } | ||
| 93 | + if (testUrl.includes('/shortestPath.json')) { | ||
| 94 | + expect(testUrl).toBe(knowledgegraphURL + '/shortestPath.json?startID=38756&endID=38757'); | ||
| 95 | + return Promise.resolve(new Response(findShortestPathData)); | ||
| 96 | + } | ||
| 97 | + }); | ||
| 98 | + var graphMap = new GraphMap(knowledgegraphmapURL, { config: { center: [0, 0] } }); | ||
| 99 | + graphMap.createGraphMap = () => {}; | ||
| 100 | + | ||
| 101 | + graphMap.on('loaded', () => { | ||
| 102 | + try { | ||
| 103 | + expect(graphMap).not.toBeNull(); | ||
| 104 | + graphMap.graph = null; | ||
| 105 | + const res = graphMap.highlight(); | ||
| 106 | + const res1 = graphMap.clearHighlight(); | ||
| 107 | + expect(res).toBeUndefined(); | ||
| 108 | + expect(res1).toBeUndefined(); | ||
| 109 | + done(); | ||
| 110 | + } catch (exception) { | ||
| 111 | + console.log("'no graph highlight clearHighlight'案例失败:" + exception.name + ':' + exception.message); | ||
| 112 | + expect(false).toBeTruthy(); | ||
| 113 | + done(); | ||
| 114 | + } | ||
| 115 | + }); | ||
| 116 | + }); | ||
| 84 | 117 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | ||
| 2 | 2 | import './maplibregl/core/MapExtendSpec.js'; | |
| 3 | + import './maplibregl/core/UtilSpec.js'; | ||
| 3 | 4 | ||
| 4 | 5 | /*maplibregl -- services*/ | |
| 5 | 6 | import './maplibregl/services/AddressMatchServiceSpec.js'; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,23 +1,42 @@ | |||
| 1 | - const Scene = () => { | ||
| 2 | - return { | ||
| 3 | - removeAllLayer: () => {}, | ||
| 4 | - layerService: { | ||
| 1 | + class Scene { | ||
| 2 | + constructor() { | ||
| 3 | + this.layerService = { | ||
| 5 | 4 | renderLayer: () => {}, | |
| 6 | 5 | stopAnimate: () => true, | |
| 7 | 6 | startAnimate: () => true | |
| 8 | - }, | ||
| 9 | - getLayer: () => true, | ||
| 10 | - addLayer: () => true, | ||
| 11 | - removeLayer: () => true, | ||
| 12 | - on: (type, callback) => { | ||
| 13 | - callback(); | ||
| 14 | - }, | ||
| 15 | - addMarkerLayer: () => true, | ||
| 16 | - removeMarkerLayer: () => true, | ||
| 17 | - addImage: () => true, | ||
| 18 | - hasImage: () => false | ||
| 19 | - }; | ||
| 20 | - }; | ||
| 7 | + }; | ||
| 8 | + this.callbacks = {} | ||
| 9 | + } | ||
| 10 | + removeAllLayer() {} | ||
| 11 | + getLayer() { | ||
| 12 | + return true; | ||
| 13 | + } | ||
| 14 | + addLayer() { | ||
| 15 | + return true; | ||
| 16 | + } | ||
| 17 | + removeLayer() { | ||
| 18 | + return true; | ||
| 19 | + } | ||
| 20 | + on(type, callback) { | ||
| 21 | + this.callbacks[type] = callback; | ||
| 22 | + callback() | ||
| 23 | + } | ||
| 24 | + emit(type) { | ||
| 25 | + this.callbacks[type](); | ||
| 26 | + } | ||
| 27 | + addMarkerLayer() { | ||
| 28 | + return true; | ||
| 29 | + } | ||
| 30 | + removeMarkerLayer() { | ||
| 31 | + return true; | ||
| 32 | + } | ||
| 33 | + addImage() { | ||
| 34 | + return true; | ||
| 35 | + } | ||
| 36 | + hasImage() { | ||
| 37 | + return false; | ||
| 38 | + } | ||
| 39 | + } | ||
| 21 | 40 | const Mapbox = ({ mapInstance }) => { | |
| 22 | 41 | return mapInstance; | |
| 23 | 42 | }; | |
@@ -27,6 +46,9 @@ const Maplibre = ({ mapInstance }) => { | |||
| 27 | 46 | class Layer { | |
| 28 | 47 | constructor() { | |
| 29 | 48 | this.animateStatus = false; | |
| 49 | + this.layerModel = { | ||
| 50 | + spriteAnimate: false | ||
| 51 | + }; | ||
| 30 | 52 | } | |
| 31 | 53 | source() { | |
| 32 | 54 | return this; | |
@@ -50,7 +72,13 @@ class Layer { | |||
| 50 | 72 | filter() { | |
| 51 | 73 | return this; | |
| 52 | 74 | } | |
| 53 | - shape() { | ||
| 75 | + shape(type) { | ||
| 76 | + this.shape = type; | ||
| 77 | + if (this.shape === 'sprite') { | ||
| 78 | + this.layerModel = { | ||
| 79 | + spriteAnimate: true | ||
| 80 | + }; | ||
| 81 | + } | ||
| 54 | 82 | return this; | |
| 55 | 83 | } | |
| 56 | 84 | active() { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments