Skip to content

Instantly share code, notes, and snippets.

@ahocevar
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahocevar/e3700105214602cd3ac5 to your computer and use it in GitHub Desktop.
Save ahocevar/e3700105214602cd3ac5 to your computer and use it in GitHub Desktop.
Feedback form submission with Geolocation
var featureType, featureNS;
var form = document.forms[0];
var geolocation = new ol.Geolocation({
projection: 'EPSG:4326'
});
geolocation.setTracking(true);
// Stop tracking once we have a position
geolocation.on('change', function(evt) {
geolocation.setTracking(false);
});
function submitForm() {
var feature = new ol.Feature();
var position = geolocation.getPosition();
if (position) {
feature.setGeometryName('geom');
feature.setGeometry(new ol.geom.Point(position));
}
feature.set('f_name', form.name.value);
feature.set('f_mail', form.email.value);
for (var i = form.geschlecht.length - 1; i >= 0; --i) {
if (form.geschlecht[i].checked) {
feature.set('f_anrede', form.geschlecht[i].value);
break;
}
}
feature.set('f_msg', form.message.value);
feature.set('f_geoweb', form.team.checked ? 1 : 0);
var date = new Date();
feature.set('f_datum',
date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate());
var transaction = new ol.format.WFS().writeTransaction([feature], null, null, {
featureType: featureType,
featureNS: featureNS,
gmlOptions: {srsName: 'CRS:84'}
});
var request = new XMLHttpRequest();
request.open('POST', 'http://student.ifip.tuwien.ac.at/geoserver/wfs', true);
request.onload = function() {
alert(request.responseText);
}
request.send(new XMLSerializer().serializeToString(transaction));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment