Skip to content

Commit ba07a17

Browse files
authored
fix UIComponent ViewPoint cal error when geometry coordinates carry z… (#2134)
* fix UIComponent ViewPoint cal error when geometry coordinates carry z value * spec
1 parent f39a18b commit ba07a17

File tree

2 files changed

+80
-15
lines changed

2 files changed

+80
-15
lines changed

src/ui/UIComponent.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,10 @@ class UIComponent extends Eventable(Class) {
511511
altitude = coordinates.z;
512512
} else if (this._owner && this._owner.getAltitude) {
513513
altitude = this._owner.getAltitude() || 0;
514+
//altitude is array from linestring ,polygon etc when coordinates carry z value [[x,y,z],[x,y,z],....];
515+
if (!isNumber(altitude)) {
516+
altitude = 0;
517+
}
514518
}
515519
const alt = this._meterToPoint(this._coordinate, altitude);
516520
return this.getMap().coordToViewPoint(this._coordinate, undefined, alt)

test/ui/InfoWindowSpec.js

Lines changed: 76 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ describe('UI.InfoWindow', function () {
7979
});
8080

8181
it('infowindow not repeat fire show event when geometry symbol change', function (done) {
82-
var marker1 = new maptalks.Marker(map.getCenter(),{
83-
symbol:{
82+
var marker1 = new maptalks.Marker(map.getCenter(), {
83+
symbol: {
8484
'markerType': 'ellipse',
8585
'markerWidth': 40,
8686
'markerHeight': 40,
@@ -93,8 +93,8 @@ describe('UI.InfoWindow', function () {
9393
content: 'hello maptalks'
9494
});
9595

96-
var marker2 = new maptalks.Marker(map.getCenter().add(0.001,0),{
97-
symbol:{
96+
var marker2 = new maptalks.Marker(map.getCenter().add(0.001, 0), {
97+
symbol: {
9898
'markerType': 'ellipse',
9999
'markerWidth': 40,
100100
'markerHeight': 40,
@@ -106,29 +106,90 @@ describe('UI.InfoWindow', function () {
106106
title: 'hello maptalks',
107107
content: 'hello maptalks'
108108
});
109-
[marker1, marker2].forEach(function(marker) {
110-
marker.getInfoWindow().on('showstart', function(e) {
109+
[marker1, marker2].forEach(function (marker) {
110+
marker.getInfoWindow().on('showstart', function (e) {
111111
var ownver = e.target.getOwner();
112112
if (!ownver._orignalSymbol) {
113113
ownver._orignalSymbol = ownver.getSymbol();
114114
}
115-
//The show event should not be triggered,otherwise error:Maximum call stack size exceeded
115+
//The show event should not be triggered,otherwise error:Maximum call stack size exceeded
116116
e.target.getOwner().setSymbol();
117117
})
118-
marker.getInfoWindow().on('hide',function(e) {
118+
marker.getInfoWindow().on('hide', function (e) {
119119
var ownver = e.target.getOwner();
120-
//The show event should not be triggered,otherwise error:Maximum call stack size exceeded
120+
//The show event should not be triggered,otherwise error:Maximum call stack size exceeded
121121
ownver.setSymbol(ownver._orignalSymbol);
122122
})
123123
});
124124
//fire show events
125125
marker1.openInfoWindow();
126-
setTimeout(function(){
127-
marker2.openInfoWindow();
128-
setTimeout(function(){
129-
done();
130-
},100)
131-
},100)
126+
setTimeout(function () {
127+
marker2.openInfoWindow();
128+
setTimeout(function () {
129+
done();
130+
}, 100)
131+
}, 100)
132+
133+
});
134+
it('#2133 infowindow when owner coordinates carry z value', function (done) {
135+
const pointSymbol = {
136+
markerType: 'ellipse',
137+
markerWidth: 20,
138+
markerHeight: 20
139+
};
140+
const lineSymbol = {
141+
lineColor: 'black',
142+
lineWidth: 4
143+
};
144+
145+
const fillSymbol = {
146+
polygonFill: "black",
147+
polygonOpacity: 1
148+
};
149+
map.setCenter([0, 0]);
150+
map.setZoom(12);
151+
//geometry coordinates carry z value
152+
const lefttop = [-0.01, 0.01, 1], righttop = [0.01, 0.01, 1], rightbottom = [0.01, -0.01, 1], leftbottom = [-0.01, -0.01, 1];
153+
const point = new maptalks.Marker(lefttop, { symbol: pointSymbol });
154+
const multipoint = new maptalks.MultiPoint([lefttop, lefttop], { symbol: pointSymbol });
155+
const line = new maptalks.LineString([lefttop, righttop], { symbol: lineSymbol });
156+
const multiline = new maptalks.MultiLineString([[lefttop, righttop], [lefttop, righttop]], { symbol: lineSymbol });
157+
const polygon = new maptalks.Polygon([[lefttop, righttop, rightbottom, leftbottom]], { symbol: fillSymbol });
158+
const multipolygon = new maptalks.MultiPolygon([[[lefttop, righttop, rightbottom, leftbottom]], [[lefttop, righttop, rightbottom, leftbottom]]], { symbol: fillSymbol });
159+
const rectange = new maptalks.Rectangle(lefttop, 2000, 1000, { symbol: fillSymbol });
160+
const ellispe = new maptalks.Ellipse(lefttop, 2000, 1000, { symbol: fillSymbol });
161+
const sector = new maptalks.Sector(lefttop, 1000, 0, 90, { symbol: fillSymbol });
162+
const circle = new maptalks.Circle(lefttop, 1000, { symbol: fillSymbol });
163+
const geos = [point, multipoint, line, multiline, polygon, multipolygon, circle, rectange, ellispe, sector];
164+
geos.forEach(geo => {
165+
geo.setInfoWindow({
166+
animationDuration: 0,
167+
title: 'hello maptalks',
168+
content: 'hello maptalks'
169+
});
170+
});
171+
let idx = 0;
172+
173+
function test() {
174+
if (idx < geos.length) {
175+
layer.clear();
176+
const geo = geos[idx];
177+
geo.addTo(layer);
178+
setTimeout(() => {
179+
const center = geo.getCenter();
180+
center.z = undefined;
181+
geo.openInfoWindow(center);
182+
setTimeout(function () {
183+
expect(geo.getInfoWindow().__uiDOM.style.display).not.to.be.eql('none');
184+
idx++;
185+
test();
186+
}, 50);
187+
}, 40);
188+
} else {
189+
done();
190+
}
191+
}
132192

193+
test();
133194
});
134195
});

0 commit comments

Comments
 (0)