Last active
August 29, 2015 14:09
-
-
Save ahocevar/e3700105214602cd3ac5 to your computer and use it in GitHub Desktop.
Feedback form submission with Geolocation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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