Skip to content

Commit d8bd0de

Browse files
committed
Merge branch 'master' of https://github.com/SuperMap/iClient9
2 parents 87ec225 + 652f299 commit d8bd0de

File tree

4 files changed

+212
-0
lines changed

4 files changed

+212
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
require('../../../src/leaflet/overlay/GraphicLayer');
2+
3+
var url = "http://supermapiserver:8090/iserver/services/map-world/rest/maps/World";
4+
describe('leaflet_GraphicLayer', function () {
5+
var originalTimeout;
6+
var testDiv, map;
7+
beforeAll(function () {
8+
testDiv = window.document.createElement("div");
9+
testDiv.setAttribute("id", "map");
10+
testDiv.style.styleFloat = "left";
11+
testDiv.style.marginLeft = "8px";
12+
testDiv.style.marginTop = "50px";
13+
testDiv.style.width = "500px";
14+
testDiv.style.height = "500px";
15+
window.document.body.appendChild(testDiv);
16+
});
17+
beforeEach(function () {
18+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
19+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
20+
});
21+
afterEach(function () {
22+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
23+
});
24+
afterAll(function () {
25+
map.remove();
26+
window.document.body.removeChild(testDiv);
27+
});
28+
29+
it('initialize', function (done) {
30+
map = L.map('map', {
31+
preferCanvas: true,
32+
crs: L.CRS.EPSG4326,
33+
center: {lon: 0, lat: 0},
34+
maxZoom: 18,
35+
zoom: 1
36+
});
37+
L.supermap.tiledMapLayer(url).addTo(map);
38+
var colorCount = 5, count = 5;
39+
var graphics = [];
40+
var e = 45;
41+
var randomCircleStyles = [];
42+
for (var i = 0; i < colorCount; i++) {
43+
randomCircleStyles.push(L.supermap.circleStyle({
44+
color: '#3388ff',
45+
opacity: 1,
46+
radius: 2,
47+
fill: true,
48+
fillColor: '#3388ff',
49+
fillOpacity: 1
50+
}));
51+
}
52+
for (var j = 0; j < count; ++j) {
53+
var coordinates = [2 * e * Math.random() - e, 2 * e * Math.random() - e];
54+
graphics[j] = L.supermap.graphic({
55+
_latlng: L.latLng(coordinates[0], coordinates[1]),
56+
_canvas: randomCircleStyles[Math.floor(Math.random() * colorCount)].getCanvas()
57+
});
58+
}
59+
var graphicLayer = L.supermap.graphicLayer(graphics).addTo(map);
60+
setTimeout(function () {
61+
expect(graphicLayer.graphics.length).toEqual(count);
62+
for (var i = 0; i < graphicLayer.graphics.length; i++) {
63+
expect(graphicLayer.graphics[i]._canvas).not.toBeNull();
64+
expect(graphicLayer.graphics[i]._latlng).not.toBeNull();
65+
}
66+
var isContainsPoint = graphicLayer._containsPoint();
67+
expect(isContainsPoint).not.toBe("false");
68+
done();
69+
}, 1000)
70+
});
71+
});
72+
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
require('../../../src/openlayers/overlay/Graphic');
2+
require('../../../src/common/util/FetchRequest');
3+
4+
url ="http://supermapiserver:8090/iserver/services/map-china400/rest/maps/China_4326";
5+
describe('leaflet_GraphicLayer', function () {
6+
var originalTimeout;
7+
var testDiv, map, graphicLayer;
8+
var FetchRequest = SuperMap.FetchRequest;
9+
var escapedJson = "{\"viewBounds\":{\"top\":66.5212729371629,\"left\":-66.52127293716292,\"bottom\":-66.52127293716293,\"leftBottom\":{\"x\":-66.52127293716292,\"y\":-66.52127293716293},\"right\":66.52127293716292,\"rightTop\":{\"x\":66.52127293716292,\"y\":66.5212729371629}},\"viewer\":{\"leftTop\":{\"x\":0,\"y\":0},\"top\":0,\"left\":0,\"bottom\":256,\"rightBottom\":{\"x\":256,\"y\":256},\"width\":256,\"right\":256,\"height\":256},\"distanceUnit\":\"METER\",\"minVisibleTextSize\":0.1,\"coordUnit\":\"DEGREE\",\"scale\":4.573415833095347E-9,\"description\":\"\",\"paintBackground\":true,\"maxVisibleTextSize\":1000,\"maxVisibleVertex\":3600000,\"clipRegionEnabled\":false,\"antialias\":true,\"textOrientationFixed\":false,\"angle\":0,\"prjCoordSys\":{\"distanceUnit\":\"METER\",\"projectionParam\":null,\"epsgCode\":4326,\"coordUnit\":\"DEGREE\",\"name\":\"Longitude / Latitude Coordinate System---GCS_WGS_1984\",\"projection\":null,\"type\":\"PCS_EARTH_LONGITUDE_LATITUDE\",\"coordSystem\":{\"datum\":{\"name\":\"D_WGS_1984\",\"type\":\"DATUM_WGS_1984\",\"spheroid\":{\"flatten\":0.00335281066474748,\"name\":\"WGS_1984\",\"axis\":6378137,\"type\":\"SPHEROID_WGS_1984\"}},\"unit\":\"DEGREE\",\"spatialRefType\":\"SPATIALREF_EARTH_LONGITUDE_LATITUDE\",\"name\":\"GCS_WGS_1984\",\"type\":\"GCS_WGS_1984\",\"primeMeridian\":{\"longitudeValue\":0,\"name\":\"Greenwich\",\"type\":\"PRIMEMERIDIAN_GREENWICH\"}}},\"minScale\":0,\"markerAngleFixed\":false,\"overlapDisplayedOptions\":{\"allowPointWithTextDisplay\":true,\"horizontalOverlappedSpaceSize\":0,\"allowPointOverlap\":false,\"allowThemeGraduatedSymbolOverlap\":false,\"verticalOverlappedSpaceSize\":0,\"allowTextOverlap\":false,\"allowThemeGraphOverlap\":false,\"allowTextAndPointOverlap\":false},\"visibleScales\":[1.6901635716026555E-9,3.3803271432053056E-9,6.760654286410611E-9,1.3521308572821242E-8,2.7042617145642484E-8,5.408523429128511E-8,1.0817046858256998E-7,2.1634093716513974E-7,4.3268187433028044E-7,8.653637486605571E-7,1.7307274973211203E-6,3.4614549946422405E-6,6.9229099892844565E-6],\"visibleScalesEnabled\":false,\"customEntireBoundsEnabled\":false,\"clipRegion\":{\"center\":null,\"parts\":null,\"style\":null,\"prjCoordSys\":null,\"id\":0,\"type\":\"REGION\",\"partTopo\":null,\"points\":null},\"maxScale\":1.0E12,\"customParams\":\"\",\"center\":{\"x\":0,\"y\":-1.4210854715202004E-14},\"dynamicPrjCoordSyses\":[{\"distanceUnit\":null,\"projectionParam\":null,\"epsgCode\":0,\"coordUnit\":null,\"name\":null,\"projection\":null,\"type\":\"PCS_ALL\",\"coordSystem\":null}],\"colorMode\":\"DEFAULT\",\"textAngleFixed\":false,\"overlapDisplayed\":false,\"userToken\":{\"userID\":\"\"},\"cacheEnabled\":true,\"dynamicProjection\":true,\"autoAvoidEffectEnabled\":true,\"customEntireBounds\":null,\"name\":\"China_4326\",\"bounds\":{\"top\":85.05112877980648,\"left\":-180,\"bottom\":-85.0511287798065,\"leftBottom\":{\"x\":-180,\"y\":-85.0511287798065},\"right\":180,\"rightTop\":{\"x\":180,\"y\":85.05112877980648}},\"backgroundStyle\":{\"fillGradientOffsetRatioX\":0,\"markerSize\":2.4,\"fillForeColor\":{\"red\":255,\"green\":255,\"blue\":255,\"alpha\":255},\"fillGradientOffsetRatioY\":0,\"markerWidth\":0,\"markerAngle\":0,\"fillSymbolID\":0,\"lineColor\":{\"red\":0,\"green\":0,\"blue\":0,\"alpha\":255},\"markerSymbolID\":0,\"lineWidth\":0.1,\"markerHeight\":0,\"fillOpaqueRate\":100,\"fillBackOpaque\":true,\"fillBackColor\":{\"red\":255,\"green\":255,\"blue\":255,\"alpha\":255},\"fillGradientMode\":\"NONE\",\"lineSymbolID\":0,\"fillGradientAngle\":0}}";
10+
beforeEach(function () {
11+
testDiv = window.document.createElement("div");
12+
testDiv.setAttribute("id", "map");
13+
testDiv.style.styleFloat = "left";
14+
testDiv.style.marginLeft = "8px";
15+
testDiv.style.marginTop = "50px";
16+
testDiv.style.width = "500px";
17+
testDiv.style.height = "500px";
18+
window.document.body.appendChild(testDiv);
19+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
20+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
21+
});
22+
afterEach(function () {
23+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
24+
window.document.body.removeChild(testDiv);
25+
});
26+
27+
it('constructor_canvas', function (done) {
28+
spyOn(FetchRequest, 'commit').and.callFake(function () {
29+
return Promise.resolve(new Response(escapedJson));
30+
});
31+
var count = 5; //矢量点的个数
32+
var graphics = [];
33+
var e = 45;
34+
new ol.supermap.MapService(url).getMapInfo(function (serviceResult) {
35+
map = new ol.Map({
36+
target: 'map',
37+
view: new ol.View({
38+
center: [0, 0],
39+
zoom: 2,
40+
projection: 'EPSG:4326'
41+
}),
42+
renderer: ['canvas']
43+
});
44+
var options = ol.source.TileSuperMapRest.optionsFromMapJSON(url, serviceResult.result);
45+
var layer = new ol.layer.Tile({
46+
source: new ol.source.TileSuperMapRest(options)
47+
});
48+
map.addLayer(layer);
49+
var randomCircleStyles = new ol.style.RegularShape({
50+
radius: 5,
51+
fill: new ol.style.Fill({
52+
color: '#000000'
53+
}),
54+
stroke: new ol.style.Stroke({
55+
color: '#000000'
56+
}),
57+
points: 3
58+
});
59+
for (var j = 0; j < count; ++j) {
60+
var coordinates = [2 * e * Math.random() - e, 2 * e * Math.random() - e];
61+
graphics[j] = new ol.Graphic(new ol.geom.Point(coordinates));
62+
graphics[j].setStyle(randomCircleStyles);
63+
}
64+
graphicLayer = new ol.layer.Image({
65+
source: new ol.source.Graphic({
66+
graphics: graphics,
67+
map: map
68+
})
69+
});
70+
map.addLayer(graphicLayer);
71+
});
72+
setTimeout(function () {
73+
expect(1).not.toBeNull();
74+
var a = new ol.source.Graphic({
75+
graphics: graphics,
76+
map: map
77+
}).forEachFeatureAtCoordinate([-36.164319245276744, 31.050912682650818], 1, function (result) {
78+
console.log(result);
79+
});
80+
expect(a).not.toBeNull();
81+
map.removeLayer(graphicLayer);
82+
done();
83+
}, 1000)
84+
});
85+
86+
it('constructor_webgl', function (done) {
87+
spyOn(FetchRequest, 'commit').and.callFake(function () {
88+
return Promise.resolve(new Response(escapedJson));
89+
});
90+
var count = 5; //矢量点的个数
91+
var graphics = [];
92+
var e = 45;
93+
new ol.supermap.MapService(url).getMapInfo(function (serviceResult) {
94+
map = new ol.Map({
95+
target: 'map',
96+
view: new ol.View({
97+
center: [0, 0],
98+
zoom: 2,
99+
projection: 'EPSG:4326'
100+
}),
101+
renderer: ['webgl']
102+
});
103+
var options = ol.source.TileSuperMapRest.optionsFromMapJSON(url, serviceResult.result);
104+
var layer = new ol.layer.Tile({
105+
source: new ol.source.TileSuperMapRest(options)
106+
});
107+
map.addLayer(layer);
108+
var randomCircleStyles = new ol.style.RegularShape({
109+
radius: 5,
110+
fill: new ol.style.Fill({
111+
color: '#000000'
112+
}),
113+
stroke: new ol.style.Stroke({
114+
color: '#000000'
115+
}),
116+
points: 3
117+
});
118+
for (var j = 0; j < count; ++j) {
119+
var coordinates = [2 * e * Math.random() - e, 2 * e * Math.random() - e];
120+
graphics[j] = new ol.Graphic(new ol.geom.Point(coordinates));
121+
graphics[j].setStyle(randomCircleStyles);
122+
}
123+
graphicLayer = new ol.layer.Image({
124+
source: new ol.source.Graphic({
125+
graphics: graphics,
126+
map: map
127+
})
128+
});
129+
map.addLayer(graphicLayer);
130+
});
131+
setTimeout(function () {
132+
expect(1).not.toBeNull();
133+
map.removeLayer(graphicLayer);
134+
done();
135+
}, 1000)
136+
});
137+
});
138+

test/test-main-leaflet.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ require('./leaflet/services/TrafficTransferAnalystServiceSpec.js');
3636

3737
/*leaflet -- overlay*/
3838
require('./leaflet/overlay/EchartsLayerSpec.js');
39+
require('./leaflet/overlay/GraphicLayerSpec.js');
3940
require('./leaflet/overlay/GraphThemeLayerSpec.js');
4041
require('./leaflet/overlay/LabelThemeLayerSpec.js');
4142
require('./leaflet/overlay/mapVLayerSpec.js');

test/test-main-openlayers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ require('./openlayers/services/ThiessenAnalysisSpec.js');
2727
require('./openlayers/services/TrafficTransferAnalystServiceSpec.js');
2828

2929
/*openlayers -- overlay*/
30+
require('./openlayers/overlay/GraphicSpec.js');
3031
require('./openlayers/overlay/GraphSpec.js');
3132
require('./openlayers/overlay/LabelSpec');
3233
require('./openlayers/overlay/MapvSpec.js');

0 commit comments

Comments
 (0)