Hello,
I’ve seen that it is possible to update features through georest. This looks great and very interesting !
I’ve tried with the buildings of the Sheybogan MapGuide samples. Currently my data source is a mapguide feature source.
I’ve set READONLY to FALSE. I’ve added the PUT method on the XML :
<Representation renderer="XML" pattern=".xml"><Method name="PUT" /><Method name="POST" /><Method name="GET" /></Representation>
I’ve modifeied a template in order to be able to update the features as follow :
Created a javascript function following the Wiki example :
function UpdateFeature()
{
var xml = '<?xml version="1.0" encoding="UTF-8"?><FeatureSet><Features><Feature>';
xml = xml+'<Property><Name>NAME</Name><Value>'+document.getElementById('feature_NAME').value+'</Value></Property>';
xml = xml+'</Feature></Features></FeatureSet>';
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange = function(evt)
{
if(this.readyState == 4)
{
alert(this.responseText);
}
};
xmlhttp.open("PUT",'/rest/data/building/{{BUILDING_ID}}.xml',true);
xmlhttp.setRequestHeader("Content-Type","application/xml; charset=UTF-8");
xmlhttp.send(xml);
}
}
And add a simple table with a button :
<table width="100%" height="50" id="feature_TABLE" class="mainfont">
<tr>
<th height="10" align="left" valign="left" bgcolor="#E6E6E6" >Edit building data</th>
</tr>
<tr>
<td class="mainfont" height="10" >
<strong ><em>ID: </em></strong><input type="text" name="feature_ID" id="feature_ID" value="{{BUILDING_ID}}" size="17"/></td>
</tr>
<tr>
<td class="mainfont" height="10" >
<strong ><em>Name: </em></strong><input type="text" name="feature_NAME" id="feature_NAME" value="{{BUILDING_NAME}}" size="17"/></td>
</td>
</tr>
</table>
<input type="button" name="send" id="button" value="Send" onClick="UpdateFeature()" size="17"/>
{{/BUILDING}}
</td>
</tr>
</table>
When cliking on the button send, the following lines are displayed in the Georest server window :
PUT(277): http://localhost:99/rest/data/building/15462.xml
Post Data...<?xml version="1.0" encoding="UTF-8"?><FeatureSet><Features><Feature
><Property><Name>NAME</Name><Value>tttttttt</Value></Property></Feature></Featur
es></FeatureSet>...
200(277) Time (0.050005)
And a message box is displayed in the webpage : Update Done
Though when refreshing the webpage same … I was expecting to see the value I entered in the field . But the field remains balk … any idea .. what is going wrong ?
Is this update function of georest reliable ? I was at the end forecasting to do this on a sqlite data source … would it work also ?
Thanks for your help,
Pierre-Nicolas
Hi guys,
Just to notify you that it worked immediately with a feature source pointing to a sqlite file !
Looks great !
Don’t know why it didn’t worked with the buildings of Sheybogan …
Have a great day !
Pierre-Nicolas