[OpenLayers-Users] WKT in MySQL
mpriour
mpriour at kestrelcomputer.com
Fri Apr 25 02:51:46 EDT 2008
ok so the problem is that you do not have your WKT enclosed in quotes. Thus
it is being read as if it is a javascript function and when it hits the
first comma in the WKT string, the javascript engine gets confused.
So wrap the WKT strings in quotes and it should.
Also, a hint for performance improvement when you do get it working, is to
only declare the features variable once and then reassign it's value, or to
just directly load them into the vector layer via:
vectors.addFeatures(WKT.read("A WKT string"));
petey1815 wrote:
>
> http://www.nabble.com/file/p16891470/error.jpg
>
> From javascript, line number is 72, but i can't really see anything wrong
> there... Page is available here
>
> www.icoe.be/NW/PHP/LGEMap.php
>
> thx
> Pieter
>
>
>
> mpriour wrote:
>>
>> Are you getting the ')' expected area from javascript or PHP?
>> Do you know approximately where (which line or from which function) the
>> error is occuring?
>> Such information would greatly simplify helping you debug this.
>> Matt Priour
>>
>>
>> petey1815 wrote:
>>>
>>> Hi all,
>>>
>>> I'd like some help on the following. I'm trying to get a table from my
>>> MySql database that contains WKT formatted strings formed as
>>> (POLYGON((x1 y1,x2 y2,...,xn yn)) to show up on a vector feature map as
>>> polygons. I've inserted the code below, using php to loop throught the
>>> table & create a polygon for each line in the table. I'm getting ')'
>>> expected errors & i truly have no idea what could be wrong. I've also
>>> inserted some of the generated code by the php loop. Any pointers will
>>> be greatly appreciated.
>>>
>>> thx
>>> Pieter
>>>
>>> Code: <script type="text/javascript">
>>> var map, vectors, drawControls, wkt;
>>>
>>> function init(){
>>> map = new OpenLayers.Map('map');
>>> var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
>>> "http://labs.metacarta.com/wms/vmap0?", {layers:
>>> 'basic'});
>>>
>>> var options = {maxResolution: 'auto',maxExtent: new
>>> OpenLayers.Bounds(0.5, 0.5, 4125, 3300),numZoomLevels: 6};
>>>
>>> var graphic = new OpenLayers.Layer.Image(
>>> 'NTW2 Campaign Map',
>>>
>>> 'C:/victory/rules/LGE/La_Guerre_Map_new.jpg',
>>> new OpenLayers.Bounds(0.5, 0.5, 4125,
>>> 3300),
>>> new OpenLayers.Size(4125,3300),
>>> options);
>>>
>>> vectors = new OpenLayers.Layer.Vector("Vector
>>> Layer",{layers: 'basic'} );
>>>
>>> map.addLayers([graphic, vectors]);
>>> map.addControl(new OpenLayers.Control.LayerSwitcher());
>>> map.addControl(new OpenLayers.Control.MousePosition());
>>>
>>> wkt = new OpenLayers.Format.WKT();
>>>
>>> map.setCenter(new OpenLayers.LonLat(179, 179), 0);
>>>
>>> }
>>>
>>> function toggleControl(element) {
>>> for(key in drawControls) {
>>> var control = drawControls[key];
>>> if(element.value == key && element.checked) {
>>> control.activate();
>>> } else {
>>> control.deactivate();
>>> }
>>> }
>>> }
>>>
>>>
>>> <?php
>>>
>>> $query="SELECT * from WKT";
>>> $result = mysql_query($query)or die(mysql_error());
>>>
>>> While(list($ID,$Region)=mysql_fetch_row($result))
>>> {
>>> echo "var features = wkt.read$Region);
>>> vectors.addFeatures(features);
>>> ";
>>>
>>> }
>>> ?>
>>>
>>>
>>>
>>> </script>
>>>
>>> code generated by the PHP loop:
>>>
>>>
>>>
>>> var features = wkt.read(POLYGON((792.626629351515 1810.98291830077,
>>> 794.560304290807 1812.01421160173, 802.681739035836 1810.98291830077,
>>> 813.768142021113 1806.98665675956, 827.819513246638 1806.98665675956,
>>> 837.874622930959 1809.04924336148, 846.898439314324 1814.97917984197,
>>> 856.953548998645 1817.04176644389, 866.879747020347 1818.07305974484,
>>> 878.99744330658 1819.1043530458, 890.083846291857 1819.1043530458,
>>> 900.138955976178 1818.07305974484, 915.09270884004 1814.07679820364,
>>> 925.147818524361 1809.04924336148, 935.202928208682 1802.99039521836,
>>> 949.254299434207 1795.90025377429, 961.37199572044 1790.87269893213,
>>> 969.364518802849 1781.84888254876, 978.388335186214 1773.85635946635,
>>> 986.509769931243 1764.83254308299, 989.474738171491 1754.77743339867,
>>> 989.474738171491 1744.72232371435, 992.43970641174 1734.66721403003,
>>> 991.537324773403 1722.67842940641, 990.506031472447 1712.62331972209,
>>> 991.537324773403 1702.56821003777, 991.537324773403 1691.48180705249,
>>> 986.509769931243 1681.42669736817, 987.412151569579 1670.34029438289,
>>> 993.470999712696 1660.41409636119, 1001.4635227951 1653.32395491712,
>>> 1010.61625084109 1642.23755193184, 1019.64006722445 1635.27632215039,
>>> 1033.69143844998 1635.27632215039, 1043.7465481343 1635.27632215039,
>>> 1053.80165781862 1630.24876730823, 1061.79418090103 1621.22495092487,
>>> 1068.75541068248 1609.10725463863, 1072.88058388631 1597.11847001502,
>>> 1072.88058388631 1583.96948042783, 1071.84929058535 1571.98069580422,
>>> 1071.84929058535 1559.86299951798, 1071.84929058535 1548.90550819533,
>>> 1070.8179972844 1537.81910521005, 1070.8179972844 1527.76399552573,
>>> 1070.8179972844 1516.67759254045, 1070.8179972844 1502.62622131493,
>>> 1068.75541068248 1490.63743669131, 1068.75541068248 1479.55103370603,
>>> 1068.75541068248 1469.49592402171, 1065.79044244224 1458.53843269906,
>>> 1062.82547420199 1448.48332301474, 1061.79418090103 1438.42821333041,
>>> 1055.73533275791 1429.40439694705, 1042.71525483334 1429.40439694705,
>>> 1030.59755854711 1429.40439694705, 1020.54244886279 1432.3693651873,
>>> 1007.52237093822 1439.45950663137, 998.498554554856 1448.48332301474,
>>> 986.509769931243 1452.47958455594, 975.423366945966 1459.44081433739,
>>> 966.399550562601 1467.56224908242, 954.281854276368 1475.55477216483,
>>> 945.258037893003 1482.6449136089, 940.230483050842 1492.5711116306,
>>> 934.171634907726 1500.69254637563, 924.245436886024 1504.68880791684,
>>> 914.190327201703 1511.65003769829, 906.068892456675 1519.77147244332,
>>> 898.076369374266 1528.79528882668, 890.083846291857 1539.88169181196,
>>> 885.958673088033 1550.83918313462, 881.060029908492 1561.9255861199,
>>> 881.060029908492 1573.01198910517, 873.969888464419 1586.03206702974,
>>> 868.942333622259 1597.11847001502, 862.883485479142 1605.11099309743,
>>> 854.890962396733 1620.19365762391, 847.800820952661 1628.18618070632,
>>> 843.804559411456 1638.24129039064, 840.839591171208 1648.29640007496,
>>> 839.808297870252 1659.38280306024, 845.867146013368 1667.37532614265,
>>> 843.804559411456 1677.43043582697, 833.749449727135 1672.40288098481,
>>> 821.760665103522 1674.46546758672, 816.733110261361 1683.48928397008,
>>> 825.756926644726 1689.5481321132, 835.812036329047 1689.5481321132,
>>> 845.867146013368 1694.44677529274, 843.804559411456 1706.56447157897,
>>> 835.812036329047 1712.62331972209, 825.756926644726 1717.65087456425,
>>> 815.701816960405 1726.67469094762, 807.709293877996 1735.69850733098,
>>> 798.685477494631 1745.7536170153, 797.654184193675 1758.77369493987,
>>> 794.560304290807 1769.86009792515, 792.626629351515 1780.94650091043,
>>> 789.661661111266 1795.90025377429, 792.626629351515 1810.98291830077)));
>>> vectors.addFeatures(features);
>>> var features = wkt.read(POLYGON((986.509769931243 1764.83254308299,
>>> 978.388335186214 1773.85635946635, 979.41962848717 1781.84888254876,
>>> 985.478476630287 1789.97031729379, 1000.56114115677 1789.97031729379,
>>> 1013.58121908134 1789.97031729379, 1025.57000370495 1790.87269893213,
>>> 1035.62511338927 1794.99787213595, 1043.7465481343 1802.99039521836,
>>> 1053.80165781862 1810.98291830077, 1065.79044244224 1817.04176644389,
>>> 1075.84555212656 1826.06558282725, 1085.90066181088 1830.06184436846,
>>> 1097.88944643449 1830.06184436846, 1107.94455611881 1829.0305510675,
>>> 1117.99966580313 1824.13190788796, 1126.12110054816 1818.07305974484,
>>> 1136.04729856986 1808.01795006052, 1143.13744001394 1800.02542697811,
>>> 1153.19254969826 1791.90399223308, 1163.24765938258 1782.88017584972,
>>> 1172.27147576594 1777.85262100756, 1182.32658545026 1770.8913912261,
>>> 1191.35040183363 1763.80124978203, 1202.43680481891 1756.84002000058,
>>> 1215.45688274347 1749.74987855651, 1225.5119924278 1742.65973711243,
>>> 1237.50077705141 1733.63592072907, 1248.58718003669 1726.67469094762,
>>> 1256.5797031191 1717.65087456425, 1265.73243116508 1710.56073312018,
>>> 1274.75624754844 1704.50188497706, 1285.7137388711 1694.44677529274,
>>> 1285.7137388711 1684.52057727104, 1277.72121578869 1674.46546758672,
>>> 1275.65862918678 1660.41409636119, 1274.75624754844 1650.35898667687,
>>> 1271.66236764558 1640.30387699255, 1271.66236764558 1625.22121246607,
>>> 1271.66236764558 1613.10351617984, 1268.69739940533 1600.08343825527,
>>> 1268.69739940533 1588.09465363165, 1267.66610610437 1574.94566404446,
>>> 1266.63481280342 1564.89055436014, 1265.73243116508 1550.83918313462,
>>> 1265.73243116508 1539.88169181196, 1265.73243116508 1529.82658212764,
>>> 1264.70113786412 1519.77147244332, 1258.64228972101 1507.65377615709,
>>> 1253.61473487885 1498.62995977372, 1253.61473487885 1488.5748500894,
>>> 1252.58344157789 1477.61735876674, 1252.58344157789 1465.49966248051,
>>> 1252.58344157789 1455.44455279619, 1247.55588673573 1445.38944311187,
>>> 1237.50077705141 1442.42447487162, 1226.54328572875 1443.45576817257,
>>> 1218.42185098372 1449.38570465307, 1206.43306636011 1452.47958455594,
>>> 1195.34666337483 1452.47958455594, 1185.29155369051 1452.47958455594,
>>> 1172.27147576594 1452.47958455594, 1161.18507278067 1452.47958455594,
>>> 1150.22758145801 1452.47958455594, 1141.07485341202 1445.38944311187,
>>> 1131.14865539032 1438.42821333041, 1123.02722064529 1431.33807188634,
>>> 1111.03843602168 1430.30677858539, 1099.9520330364 1430.30677858539,
>>> 1089.89692335208 1430.30677858539, 1079.84181366776 1431.33807188634,
>>> 1068.75541068248 1431.33807188634, 1055.73533275791 1429.40439694705,
>>> 1061.79418090103 1438.42821333041, 1062.82547420199 1448.48332301474,
>>> 1065.79044244224 1458.53843269906, 1068.75541068248 1469.49592402171,
>>> 1068.75541068248 1479.55103370603, 1068.75541068248 1490.63743669131,
>>> 1070.8179972844 1502.62622131493, 1070.8179972844 1516.67759254045,
>>> 1070.8179972844 1527.76399552573, 1070.8179972844 1537.81910521005,
>>> 1071.84929058535 1548.90550819533, 1071.84929058535 1559.86299951798,
>>> 1071.84929058535 1571.98069580422, 1072.88058388631 1583.96948042783,
>>> 1072.88058388631 1597.11847001502, 1068.75541068248 1609.10725463863,
>>> 1061.79418090103 1621.22495092487, 1053.80165781862 1630.24876730823,
>>> 1043.7465481343 1635.27632215039, 1033.69143844998 1635.27632215039,
>>> 1019.64006722445 1635.27632215039, 1010.61625084109 1642.23755193184,
>>> 1001.4635227951 1653.32395491712, 993.470999712696 1660.41409636119,
>>> 987.412151569579 1670.34029438289, 986.509769931243 1681.42669736817,
>>> 991.537324773403 1691.48180705249, 991.537324773403 1702.56821003777,
>>> 990.506031472447 1712.62331972209, 991.537324773403 1722.67842940641,
>>> 992.43970641174 1734.66721403003, 989.474738171491 1744.72232371435,
>>> 989.474738171491 1754.77743339867, 986.509769931243 1764.83254308299)));
>>> vectors.addFeatures(features);
>>> var features = wkt.read(POLYGON((794.560304290807 1812.01421160173,
>>> 792.626629351515 1810.98291830077, 781.02457971576 1819.1043530458,
>>> 771.485116681917 1826.19449448987, 777.415053162414 1836.89416248729,
>>> 791.724247713178 1838.18327911348, 771.485116681917 1845.27342055756,
>>> 760.785448684498 1852.36356200163, 750.08578068708 1846.43362552113,
>>> 738.096996063466 1846.43362552113, 728.686444692243 1854.8128835914,
>>> 719.1469816584 1864.35234662524, 710.767723588132 1876.21221958624,
>>> 698.907850627138 1884.5914776565, 689.368387593295 1897.61155558107,
>>> 677.508514632301 1898.77176054465, 664.359525045112 1898.77176054465,
>>> 653.659857047694 1908.31122357849, 651.339447120543 1921.46021316568,
>>> 657.26938360104 1932.1598811631, 667.969051598458 1938.0898176436,
>>> 680.989129523028 1941.69934419694, 671.578578151804 1949.94969060459,
>>> 660.749998491766 1955.87962708509, 647.729920567197 1961.80956356558,
>>> 633.420726016432 1964.25888515535, 639.350662496929 1976.11875811635,
>>> 645.409510640046 1988.10754273996, 659.589793528191 1991.58815763069,
>>> 673.898988078955 1986.81842611377, 685.758861039949 1979.72828466969,
>>> 697.747645663563 1979.72828466969, 709.607518624557 1979.72828466969,
>>> 721.467391585551 1982.04869459685, 733.327264546545 1990.42795266711,
>>> 745.316049170158 1992.74836259426, 756.015717167577 1982.04869459685,
>>> 764.266063575225 1972.63814322562, 776.254848198838 1961.80956356558,
>>> 788.114721159832 1953.55921715794, 799.974594120826 1953.55921715794,
>>> 813.123583708015 1951.10989556817, 826.143661632585 1951.10989556817,
>>> 840.452856183349 1952.39901219436, 853.601845770538 1948.78948564101,
>>> 863.012397141762 1941.69934419694, 869.071245284878 1952.39901219436,
>>> 864.301513767957 1965.41909011893, 864.301513767957 1979.72828466969,
>>> 864.301513767957 1992.74836259426, 861.852192178186 2005.89735218145,
>>> 859.531782251035 2020.20654673222, 859.531782251035 2033.22662465679,
>>> 858.37157728746 2045.2154092804, 864.301513767957 2055.91507727782,
>>> 876.161386728951 2055.91507727782, 888.021259689945 2055.91507727782,
>>> 901.170249277134 2049.98514079732, 905.939980794055 2036.83615121013,
>>> 907.100185757631 2024.97627824914, 917.799853755049 2019.04634176864,
>>> 929.659726716043 2014.27661025172, 942.808716303232 2010.66708369837,
>>> 954.668589264226 2007.05755714503, 964.208052298069 1999.96741570096,
>>> 977.228130222639 1997.51809411119, 991.537324773403 2003.5769422543,
>>> 1004.68631436059 2005.89735218145, 1018.86659724874 2008.2177621086,
>>> 1032.01558683593 2004.73714721788, 1042.71525483334 1996.35788914761,
>>> 1052.25471786719 1988.10754273996, 1051.09451290361 1973.7983481892,
>>> 1049.80539627742 1961.80956356558, 1043.87545979692 1951.10989556817,
>>> 1041.55504986977 1939.25002260717, 1041.55504986977 1927.39014964618,
>>> 1042.71525483334 1915.53027668518, 1042.71525483334 1902.38128709799,
>>> 1041.55504986977 1885.75168262008, 1041.55504986977 1871.44248806931,
>>> 1041.55504986977 1858.42241014475, 1043.87545979692 1846.43362552113,
>>> 1049.80539627742 1834.57375256014, 1055.86424442053 1822.71387959914,
>>> 1053.80165781862 1810.98291830077, 1043.7465481343 1802.99039521836,
>>> 1035.62511338927 1794.99787213595, 1025.57000370495 1790.87269893213,
>>> 1013.58121908134 1789.97031729379, 1000.56114115677 1789.97031729379,
>>> 985.478476630287 1789.97031729379, 979.41962848717 1781.84888254876,
>>> 978.388335186214 1773.85635946635, 969.364518802849 1781.84888254876,
>>> 961.37199572044 1790.87269893213, 949.254299434207 1795.90025377429,
>>> 935.202928208682 1802.99039521836, 925.147818524361 1809.04924336148,
>>> 915.09270884004 1814.07679820364, 900.138955976178 1818.07305974484,
>>> 890.083846291857 1819.1043530458, 878.99744330658 1819.1043530458,
>>> 866.879747020347 1818.07305974484, 856.953548998645 1817.04176644389,
>>> 846.898439314324 1814.97917984197, 837.874622930959 1809.04924336148,
>>> 827.819513246638 1806.98665675956, 813.768142021113 1806.98665675956,
>>> 802.681739035836 1810.98291830077, 794.560304290807 1812.01421160173)));
>>> vectors.addFeatures(features);
>>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/WKT-in-MySQL-tp16852122p16891593.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list