Correctly parse new place created response

This commit is contained in:
Jonny Barnes 2016-10-07 11:42:22 +01:00
parent c1f7a20ddc
commit 841f076338

View file

@ -206,9 +206,6 @@ function addMap(latitude, longitude, places) {
if (placeJson.error == true) { if (placeJson.error == true) {
throw new Error(placeJson.error_description); throw new Error(placeJson.error_description);
} }
//create the slug from the url
var urlParts = placeJson.split('/');
var slug = urlParts.pop();
//remove un-needed form elements //remove un-needed form elements
form.removeChild(document.querySelector('#place-name')); form.removeChild(document.querySelector('#place-name'));
form.removeChild(document.querySelector('#place-description')); form.removeChild(document.querySelector('#place-description'));
@ -224,28 +221,29 @@ function addMap(latitude, longitude, places) {
map.removeLayer(marker); map.removeLayer(marker);
//add place marker //add place marker
var newOption = document.createElement('option'); var newOption = document.createElement('option');
newOption.setAttribute('value', slug); newOption.setAttribute('value', placeJson.uri);
newOption.appendChild(document.createTextNode(placeJson['name'])); newOption.appendChild(document.createTextNode(placeJson.name));
newOption.dataset.latitude = placeJson['latitude']; newOption.dataset.latitude = placeJson.latitude;
newOption.dataset.longitude = placeJson['longitude']; newOption.dataset.longitude = placeJson.longitude;
selectEl.appendChild(newOption); selectEl.appendChild(newOption);
var newPlaceMarker = L.marker([placeJson['latitude'], placeJson['longitude']], { var newPlaceMarker = L.marker([placeJson.latitude, placeJson.longitude], {
icon: L.mapbox.marker.icon({ icon: L.mapbox.marker.icon({
'marker-size': 'large', 'marker-size': 'large',
'marker-symbol': 'building', 'marker-symbol': 'building',
'marker-color': '#fa0' 'marker-color': '#fa0'
}) })
}).addTo(map); }).addTo(map);
var newName = 'Name: ' + placeJson['name']; map.panTo([placeJson.latitude, placeJson.longitude]);
var newName = 'Name: ' + placeJson.name;
newPlaceMarker.bindPopup(newName, { newPlaceMarker.bindPopup(newName, {
closeButton: true closeButton: true
}); });
newPlaceMarker.on('click', function () { newPlaceMarker.on('click', function () {
map.panTo([placeJson['latitude'], placeJson['longitude']]); map.panTo([placeJson.latitude, placeJson.longitude]);
selectPlace(slug); selectPlace(placeJson.uri);
}); });
//make selected //make selected
selectPlace(slug); selectPlace(placeJson.uri);
}).catch(function (placeError) { }).catch(function (placeError) {
alertify.reset(); alertify.reset();
alertify.error(placeError); alertify.error(placeError);