WKT and openlayers

Christer picture Christer · Aug 14, 2012 · Viewed 7.4k times · Source

I cant find out how to use the WKT format in OpenLayers.

I have tried finding the solution in the documentation, witch bascily brought me to this: http://jsfiddle.net/Christer/WG8YP/2/

But that gives me the error of :

Uncaught SyntaxError: Unexpected number

I have no clue about what the hazzle is about, as the numbers and everything are copied straight out of openlayers own bounds/points/geo.

Answer

capdragon picture capdragon · Aug 14, 2012

Try this

http://jsfiddle.net/WG8YP/4/

addFeatures takes an array of features.

Code:

var polygonFeature = wkt.read("POLYGON((-15.8203125 2.4609375, -15.8203125 -10.546875, 6.85546875 -11.25, 8.26171875 -3.33984375, -15.8203125 2.4609375))");
polygonFeature.geometry.transform(map.displayProjection, map.getProjectionObject());         
vectors.addFeatures([polygonFeature]);