Skip to content

Commit 6e267ac

Browse files
committed
fix ol 客户端专题图 传入 ol.geom.Point,ol.geom.LineString,ol.geom.Polygon,不成功问题。review by zhurc.并添加测试。(后面三个端的测试都应该补上,尽量覆盖到分支)
1 parent 25cdea3 commit 6e267ac

File tree

4 files changed

+46
-10
lines changed

4 files changed

+46
-10
lines changed

dist/iclient9-openlayers.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21547,11 +21547,11 @@ var Theme = exports.Theme = function (_ol$source$ImageCanva) {
2154721547
}, {
2154821548
key: '_toFeature',
2154921549
value: function _toFeature(feature) {
21550-
var geometry,
21550+
var geometry = feature.getGeometry(),
2155121551
attributes = feature.getProperties()["Properties"] ? feature.getProperties()["Properties"] : {};
2155221552
//热点图支支持传入点对象要素
21553-
if (feature.getGeometry() instanceof _openlayers2.default.geom.Point) {
21554-
geometry = new _iclientCommon.GeometryPoint(feature.getGeometry().getCoordinates()[0], feature.getGeometry().getCoordinates()[1]);
21553+
if (geometry instanceof _openlayers2.default.geom.Point) {
21554+
geometry = new _iclientCommon.GeometryPoint(geometry.getCoordinates()[0], geometry.getCoordinates()[1]);
2155521555
//固定属性字段为 "Properties"
2155621556
}
2155721557
if (geometry instanceof _openlayers2.default.geom.LineString) {
@@ -21563,14 +21563,15 @@ var Theme = exports.Theme = function (_ol$source$ImageCanva) {
2156321563
geometry = new _iclientCommon.LineString(points);
2156421564
}
2156521565
if (geometry instanceof _openlayers2.default.geom.Polygon) {
21566-
var _coords = geometry.getCoordinates();
21566+
var _coords = geometry.getCoordinates()[0];
2156721567
var _points = [];
2156821568
for (var _i = 0; _i < _coords.length; _i++) {
2156921569
_points.push(new _iclientCommon.GeometryPoint(_coords[_i][0], _coords[_i][1]));
2157021570
}
2157121571
var linearRings = new _iclientCommon.LinearRing(_points);
2157221572
geometry = new _iclientCommon.Polygon([linearRings]);
2157321573
}
21574+
2157421575
if (geometry && geometry.length === 3) {
2157521576
geometry = new _iclientCommon.GeoText(geometry[0], geometry[1], geometry[2]);
2157621577
}
@@ -68115,7 +68116,7 @@ module.exports = function (proj4) {
6811568116
/* 346 */
6811668117
/***/ (function(module) {
6811768118

68118-
module.exports = {"_from":"proj4@2.3.15","_id":"proj4@2.3.15","_inBundle":false,"_integrity":"sha1-WtBui8owvg/6OJpJ5FZfUfBtCJ4=","_location":"/proj4","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"proj4@2.3.15","name":"proj4","escapedName":"proj4","rawSpec":"2.3.15","saveSpec":null,"fetchSpec":"2.3.15"},"_requiredBy":["/"],"_resolved":"http://registry.npm.taobao.org/proj4/download/proj4-2.3.15.tgz","_shasum":"5ad06e8bca30be0ffa389a49e4565f51f06d089e","_spec":"proj4@2.3.15","_where":"E:\\2018\\git\\iClient-JavaScript","author":"","bugs":{"url":"https://github.com/proj4js/proj4js/issues"},"bundleDependencies":false,"contributors":[{"name":"Mike Adair","email":"madair@dmsolutions.ca"},{"name":"Richard Greenwood","email":"rich@greenwoodmap.com"},{"name":"Calvin Metcalf","email":"calvin.metcalf@gmail.com"},{"name":"Richard Marsden","url":"http://www.winwaed.com"},{"name":"T. Mittan"},{"name":"D. Steinwand"},{"name":"S. Nelson"}],"dependencies":{"mgrs":"~0.0.2"},"deprecated":false,"description":"Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.","devDependencies":{"browserify":"~12.0.1","chai":"~1.8.1","curl":"git://github.com/cujojs/curl.git","grunt":"~0.4.2","grunt-browserify":"~4.0.1","grunt-cli":"~0.1.13","grunt-contrib-connect":"~0.6.0","grunt-contrib-jshint":"~0.8.0","grunt-contrib-uglify":"~0.11.1","grunt-mocha-phantomjs":"~0.4.0","istanbul":"~0.2.4","mocha":"~1.17.1","tin":"~0.4.0"},"directories":{"test":"test","doc":"docs"},"homepage":"https://github.com/proj4js/proj4js#readme","jam":{"main":"dist/proj4.js","include":["dist/proj4.js","README.md","AUTHORS","LICENSE.md"]},"license":"MIT","main":"lib/index.js","name":"proj4","repository":{"type":"git","url":"git://github.com/proj4js/proj4js.git"},"scripts":{"test":"./node_modules/istanbul/lib/cli.js test ./node_modules/mocha/bin/_mocha test/test.js"},"version":"2.3.15"};
68119+
module.exports = {"_from":"proj4@2.3.15","_id":"proj4@2.3.15","_inBundle":false,"_integrity":"sha1-WtBui8owvg/6OJpJ5FZfUfBtCJ4=","_location":"/proj4","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"proj4@2.3.15","name":"proj4","escapedName":"proj4","rawSpec":"2.3.15","saveSpec":null,"fetchSpec":"2.3.15"},"_requiredBy":["/"],"_resolved":"http://registry.npm.taobao.org/proj4/download/proj4-2.3.15.tgz","_shasum":"5ad06e8bca30be0ffa389a49e4565f51f06d089e","_spec":"proj4@2.3.15","_where":"G:\\iClient\\iClient-JavaScript","author":"","bugs":{"url":"https://github.com/proj4js/proj4js/issues"},"bundleDependencies":false,"contributors":[{"name":"Mike Adair","email":"madair@dmsolutions.ca"},{"name":"Richard Greenwood","email":"rich@greenwoodmap.com"},{"name":"Calvin Metcalf","email":"calvin.metcalf@gmail.com"},{"name":"Richard Marsden","url":"http://www.winwaed.com"},{"name":"T. Mittan"},{"name":"D. Steinwand"},{"name":"S. Nelson"}],"dependencies":{"mgrs":"~0.0.2"},"deprecated":false,"description":"Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.","devDependencies":{"browserify":"~12.0.1","chai":"~1.8.1","curl":"git://github.com/cujojs/curl.git","grunt":"~0.4.2","grunt-browserify":"~4.0.1","grunt-cli":"~0.1.13","grunt-contrib-connect":"~0.6.0","grunt-contrib-jshint":"~0.8.0","grunt-contrib-uglify":"~0.11.1","grunt-mocha-phantomjs":"~0.4.0","istanbul":"~0.2.4","mocha":"~1.17.1","tin":"~0.4.0"},"directories":{"test":"test","doc":"docs"},"homepage":"https://github.com/proj4js/proj4js#readme","jam":{"main":"dist/proj4.js","include":["dist/proj4.js","README.md","AUTHORS","LICENSE.md"]},"license":"MIT","main":"lib/index.js","name":"proj4","repository":{"type":"git","url":"git://github.com/proj4js/proj4js.git"},"scripts":{"test":"./node_modules/istanbul/lib/cli.js test ./node_modules/mocha/bin/_mocha test/test.js"},"version":"2.3.15"};
6811968120

6812068121
/***/ }),
6812168122
/* 347 */

dist/iclient9-openlayers.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/openlayers/overlay/theme/Theme.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,11 +545,11 @@ export class Theme extends ol.source.ImageCanvas {
545545
}
546546

547547
_toFeature(feature) {
548-
var geometry,
548+
var geometry = feature.getGeometry(),
549549
attributes = feature.getProperties()["Properties"] ? feature.getProperties()["Properties"] : {};
550550
//热点图支支持传入点对象要素
551-
if (feature.getGeometry() instanceof ol.geom.Point) {
552-
geometry = new GeometryPoint(feature.getGeometry().getCoordinates()[0], feature.getGeometry().getCoordinates()[1]);
551+
if (geometry instanceof ol.geom.Point) {
552+
geometry = new GeometryPoint(geometry.getCoordinates()[0], geometry.getCoordinates()[1]);
553553
//固定属性字段为 "Properties"
554554
}
555555
if (geometry instanceof ol.geom.LineString) {
@@ -561,14 +561,15 @@ export class Theme extends ol.source.ImageCanvas {
561561
geometry = new LineString(points);
562562
}
563563
if (geometry instanceof ol.geom.Polygon) {
564-
let coords = geometry.getCoordinates();
564+
let coords = geometry.getCoordinates()[0];
565565
let points = [];
566566
for (let i = 0; i < coords.length; i++) {
567567
points.push(new GeometryPoint(coords[i][0], coords[i][1]));
568568
}
569569
var linearRings = new LinearRing(points);
570570
geometry = new Polygon([linearRings]);
571571
}
572+
572573
if (geometry && geometry.length === 3) {
573574
geometry = new GeoText(geometry[0], geometry[1], geometry[2]);
574575
}

test/openlayers/overlay/theme/ThemeSpec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,40 @@ describe('openlayers_Theme', () => {
302302
expect(theme.movingOffset).toBeNull();
303303
expect(theme.currentMousePosition).toBeNull();
304304
});
305+
306+
it("toiClientFeature() features instanceof ol.Feature", () => {
307+
let pointFeature = new ol.Feature({
308+
geometry: new ol.geom.Point([0, 0])
309+
});
310+
let lineFeature = new ol.Feature({
311+
geometry: new ol.geom.LineString([[0, 0], [1, 1]])
312+
});
313+
let polygonFeature = new ol.Feature({
314+
geometry: new ol.geom.Polygon([[[0, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 0]]])
315+
});
316+
//ol.geom.Point
317+
const tempPoint = Theme.prototype.toiClientFeature([pointFeature]);
318+
expect(tempPoint).not.toBeNull();
319+
expect(tempPoint[0].geometry.type).toBe("Point");
320+
expect(tempPoint[0].geometry.CLASS_NAME).toBe("SuperMap.Geometry.Point");
321+
expect(tempPoint[0].geometry.x).toEqual(0);
322+
expect(tempPoint[0].geometry.y).toEqual(0);
323+
//ol.geom.LineString
324+
const tempLine = Theme.prototype.toiClientFeature([lineFeature]);
325+
expect(tempLine).not.toBeNull();
326+
expect(tempLine[0].geometry.CLASS_NAME).toBe("SuperMap.Geometry.LineString");
327+
expect(tempLine[0].geometry.components.length).toEqual(2);
328+
expect(tempLine[0].geometry.components[0].x).toEqual(0);
329+
expect(tempLine[0].geometry.components[0].y).toEqual(0);
330+
expect(tempLine[0].geometry.components[1].y).toEqual(1);
331+
expect(tempLine[0].geometry.components[1].y).toEqual(1);
332+
333+
//ol.geom.Polygon
334+
const tempPolygon = Theme.prototype.toiClientFeature([polygonFeature]);
335+
expect(tempPolygon).not.toBeNull();
336+
expect(tempPolygon[0].geometry.CLASS_NAME).toBe("SuperMap.Geometry.Polygon");
337+
expect(tempPolygon[0].geometry.components[0].components.length).toEqual(6);
338+
})
305339
});
306340

307341

0 commit comments

Comments
 (0)