This project is read-only.

Well Known Text Reader/Writer

Author: Ricky Brundritt

Category: Data

Module Size: 11 kb (minified 4 kb)


This module allows you to easily read and write Well Know Text data. When reading Well Know Text data it is parsed into Bing Maps shapes. MultiPoint, MultiLinstring, MultiPolygon and GeometryCollection are turned into an EntityCollection of shapes.To write Well Known text simply pass in a Bing Maps shape and the Well Known Text equivalent will be returned.

Supported WKT tags:

  • Point
  • Linestring
  • Polygon – Supports Complex Polygons
  • MultiPoint
  • MultiLinestring
  • MultiPolygon
  • Geometrycollection

Loading the Module:

//Register and load the Persistence Module
Microsoft.Maps.registerModule("WKTModule", "scripts/WKTModule.js");

Write Example:

var p = new Microsoft.Maps.Point(new Microsoft.Maps.Location(0,0));
var wkt = WKTModule.Write(p);
--> wkt = 'POINT(0,0)'

Read Example:

var wkt = 'LINESTRING(0 0, 10 10)';
var shape = WKTModule.Read(wkt);
--> shape = Microsoft.Map.Polyline


Style Options - Pass in styles into the Read method to override the default styles options for generating the shapes. These styles will be merged with the default option styles.

Last edited Feb 8, 2014 at 10:43 PM by rbrundritt, version 4


ruiespinho Sep 9, 2012 at 4:22 AM 
I think the sample code doesn't work, it should be:

var p = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(0,0),null);
var wkt = WKTModule.Write(p);