diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue index e351109a8..fcd64ed70 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue @@ -628,6 +628,10 @@ export default { newAddress = Object.assign(newAddress, { 'addressReference': this.entity.selected.address.addressReference }); + } else { + newAddress = Object.assign(newAddress, { + 'addressReference': null + }); } if (this.validFrom) { diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/AddressMap.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/AddressMap.vue index c6abd92d5..80d2ca01a 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/AddressMap.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/AddressMap.vue @@ -8,12 +8,15 @@ import L from 'leaflet'; import markerIconPng from 'leaflet/dist/images/marker-icon.png' import 'leaflet/dist/leaflet.css'; -let map; -let marker; - export default { name: 'AddressMap', props: ['entity'], + data() { + return { + map: null, + marker: null + } + }, computed: { center() { return this.entity.selected.addressMap.center; @@ -21,30 +24,33 @@ export default { }, methods:{ init() { - map = L.map('address_map').setView([46.67059, -1.42683], 12); + this.map = L.map('address_map').setView([46.67059, -1.42683], 12); - map.scrollWheelZoom.disable(); + this.map.scrollWheelZoom.disable(); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap contributors' - }).addTo(map); + }).addTo(this.map); const markerIcon = L.icon({ iconUrl: markerIconPng, iconAnchor: [12, 41], }); - marker = L.marker([48.8589, 2.3469], {icon: markerIcon}).addTo(map); - + this.marker = L.marker([48.8589, 2.3469], {icon: markerIcon}); + this.marker.addTo(this.map); }, update() { - //console.log('update map with : ', this.address.addressMap.center) - marker.setLatLng(this.entity.addressMap.center); - map.setView(this.entity.addressMap.center, 15); + //console.log('update map with : ', this.entity.addressMap.center) + if (this.marker && this.entity.addressMap.center) { + this.marker.setLatLng(this.entity.addressMap.center); + this.map.setView(this.entity.addressMap.center, 15); + } } }, mounted(){ - this.init() + this.init(); + this.update(); } } diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CitySelection.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CitySelection.vue index ca5d01b50..9dd85fa73 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CitySelection.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CitySelection.vue @@ -106,6 +106,9 @@ export default { this.$emit('getReferenceAddresses', this.value); if (this.value.center) { this.updateMapCenter(this.value.center); + if (this.value.center.coordinates) { + this.entity.selected.postcode.coordinates = this.value.center.coordinates; + } } } }, diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/AddressNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/AddressNormalizer.php index ccb48c160..0809863f6 100644 --- a/src/Bundle/ChillMainBundle/Serializer/Normalizer/AddressNormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/AddressNormalizer.php @@ -71,6 +71,7 @@ class AddressNormalizer implements ContextAwareNormalizerInterface, NormalizerAw 'id' => $address->getPostCode()->getId(), 'name' => $address->getPostCode()->getName(), 'code' => $address->getPostCode()->getCode(), + 'center' => $address->getPostcode()->getCenter(), ], 'country' => [ 'id' => $address->getPostCode()->getCountry()->getId(),