[OpenLayers-Users] Adding a vector feature from WKT
Derek Watling
derek at cmainfo.co.za
Wed Feb 4 02:24:02 EST 2009
Christopher
I am still in the (re)development stage, implementing OpenLayers and due to
all the dependencies on the page (.NET WebServices /AJAX / obout / GIS
backend...) don't have a page I can link to. Also we run a subscription
service for property information / valuations so don't want to put out a
test site where people could potentially mine data that costs us money to
obtain in the first place.
That said, as I have been refining the map and changed the controls included
on the map. I now get different symptoms when using the
Format.WKT().read(...). Using my own function still works the way I want. I
have refined my original function to include internal holes in a POLYGON and
added a "switch" statement to allow for future extendability, however for
now I only need to handle POLYGONs.
Thank you
Derek
function GeomFromWKT(wkt) {
var geometry = null;
if (typeof wkt != 'undefined') {
var geomType = wkt.substring(0, wkt.indexOf('('));
switch (geomType) {
case "POLYGON":
var aPolygon = new Array();
var aLinearRings = wkt.substring(9, wkt.length -
2).split('), (');
for (var lr = 0; lr < aLinearRings.length; lr++) {
var geomLR = new OpenLayers.Geometry.LinearRing;
var aPoints = aLinearRings[lr].split(', ');
for (var pt = 0; pt < aPoints.length; pt++) {
var aPt = aPoints[pt].split(' ');
var geomPt = new OpenLayers.Geometry.Point(aPt[0],
aPt[1]);
geomLR.addComponent(geomPt, pt);
}
aPolygon[lr] = geomLR;
}
geometry = new OpenLayers.Geometry.Polygon(aPolygon);
break;
}
}
return geometry;
}
--
View this message in context: http://n2.nabble.com/Adding-a-vector-feature-from-WKT-tp2238031p2267513.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list