@@ -29,7 +29,7 @@ ol.format.WKT = function(opt_options) {
29
29
goog . base ( this ) ;
30
30
31
31
/**
32
- * Split GEOMETRYCOLLECTION into multiple features.
32
+ * Split GeometryCollection into multiple features.
33
33
* @type {boolean }
34
34
* @private
35
35
*/
@@ -40,13 +40,23 @@ ol.format.WKT = function(opt_options) {
40
40
goog . inherits ( ol . format . WKT , ol . format . TextFeature ) ;
41
41
42
42
43
+ /**
44
+ * @const
45
+ * @type {string }
46
+ */
47
+ ol . format . WKT . EMPTY = 'EMPTY' ;
48
+
49
+
43
50
/**
44
51
* @param {ol.geom.Point } geom Point geometry.
45
52
* @return {string } Coordinates part of Point as WKT.
46
53
* @private
47
54
*/
48
55
ol . format . WKT . encodePointGeometry_ = function ( geom ) {
49
56
var coordinates = geom . getCoordinates ( ) ;
57
+ if ( goog . array . isEmpty ( coordinates ) ) {
58
+ return '' ;
59
+ }
50
60
return coordinates [ 0 ] + ' ' + coordinates [ 1 ] ;
51
61
} ;
52
62
@@ -154,7 +164,12 @@ ol.format.WKT.encode_ = function(geom) {
154
164
var type = geom . getType ( ) ;
155
165
var geometryEncoder = ol . format . WKT . GeometryEncoder_ [ type ] ;
156
166
goog . asserts . assert ( goog . isDef ( geometryEncoder ) ) ;
157
- return type . toUpperCase ( ) + '(' + geometryEncoder ( geom ) + ')' ;
167
+ var enc = geometryEncoder ( geom ) ;
168
+ type = type . toUpperCase ( ) ;
169
+ if ( enc . length === 0 ) {
170
+ return type + ' ' + ol . format . WKT . EMPTY ;
171
+ }
172
+ return type + '(' + enc + ')' ;
158
173
} ;
159
174
160
175
@@ -479,7 +494,7 @@ ol.format.WKT.Lexer.prototype.readText_ = function() {
479
494
do {
480
495
c = this . nextChar_ ( ) ;
481
496
} while ( this . isAlpha_ ( c ) ) ;
482
- return this . wkt . substring ( index , this . index_ -- ) . toLowerCase ( ) ;
497
+ return this . wkt . substring ( index , this . index_ -- ) . toUpperCase ( ) ;
483
498
} ;
484
499
485
500
@@ -555,7 +570,7 @@ ol.format.WKT.Parser.prototype.parseGeometry_ = function() {
555
570
var token = this . token_ ;
556
571
if ( this . match ( ol . format . WKT . TokenType . TEXT ) ) {
557
572
var geomType = token . value ;
558
- if ( geomType == 'geometrycollection' ) {
573
+ if ( geomType == ol . geom . GeometryType . GEOMETRY_COLLECTION . toUpperCase ( ) ) {
559
574
var geometries = this . parseGeometryCollectionText_ ( ) ;
560
575
return new ol . geom . GeometryCollection ( geometries ) ;
561
576
} else {
@@ -779,7 +794,7 @@ ol.format.WKT.Parser.prototype.parsePolygonTextList_ = function() {
779
794
*/
780
795
ol . format . WKT . Parser . prototype . isEmptyGeometry_ = function ( ) {
781
796
var isEmpty = this . token_ . type == ol . format . WKT . TokenType . TEXT &&
782
- this . token_ . value == 'empty' ;
797
+ this . token_ . value == ol . format . WKT . EMPTY ;
783
798
if ( isEmpty ) {
784
799
this . consume_ ( ) ;
785
800
}
@@ -802,12 +817,12 @@ ol.format.WKT.Parser.prototype.raiseError_ = function() {
802
817
* @private
803
818
*/
804
819
ol . format . WKT . Parser . GeometryConstructor_ = {
805
- 'point ' : ol . geom . Point ,
806
- 'linestring ' : ol . geom . LineString ,
807
- 'polygon ' : ol . geom . Polygon ,
808
- 'multipoint ' : ol . geom . MultiPoint ,
809
- 'multilinestring ' : ol . geom . MultiLineString ,
810
- 'multipolygon ' : ol . geom . MultiPolygon
820
+ 'POINT ' : ol . geom . Point ,
821
+ 'LINESTRING ' : ol . geom . LineString ,
822
+ 'POLYGON ' : ol . geom . Polygon ,
823
+ 'MULTIPOINT ' : ol . geom . MultiPoint ,
824
+ 'MULTILINESTRING ' : ol . geom . MultiLineString ,
825
+ 'MULTIPOLYGON ' : ol . geom . MultiPolygon
811
826
} ;
812
827
813
828
@@ -816,10 +831,10 @@ ol.format.WKT.Parser.GeometryConstructor_ = {
816
831
* @private
817
832
*/
818
833
ol . format . WKT . Parser . GeometryParser_ = {
819
- 'point ' : ol . format . WKT . Parser . prototype . parsePointText_ ,
820
- 'linestring ' : ol . format . WKT . Parser . prototype . parseLineStringText_ ,
821
- 'polygon ' : ol . format . WKT . Parser . prototype . parsePolygonText_ ,
822
- 'multipoint ' : ol . format . WKT . Parser . prototype . parseMultiPointText_ ,
823
- 'multilinestring ' : ol . format . WKT . Parser . prototype . parseMultiLineStringText_ ,
824
- 'multipolygon ' : ol . format . WKT . Parser . prototype . parseMultiPolygonText_
834
+ 'POINT ' : ol . format . WKT . Parser . prototype . parsePointText_ ,
835
+ 'LINESTRING ' : ol . format . WKT . Parser . prototype . parseLineStringText_ ,
836
+ 'POLYGON ' : ol . format . WKT . Parser . prototype . parsePolygonText_ ,
837
+ 'MULTIPOINT ' : ol . format . WKT . Parser . prototype . parseMultiPointText_ ,
838
+ 'MULTILINESTRING ' : ol . format . WKT . Parser . prototype . parseMultiLineStringText_ ,
839
+ 'MULTIPOLYGON ' : ol . format . WKT . Parser . prototype . parseMultiPolygonText_
825
840
} ;
0 commit comments