mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +00:00
Fixed: Fix map center on opening or editing address
This commit is contained in:
parent
ce17f5f5c0
commit
4d3d9db1b3
@ -311,7 +311,7 @@ export default {
|
|||||||
// cfr https://macwright.com/lonlat/
|
// cfr https://macwright.com/lonlat/
|
||||||
center : [
|
center : [
|
||||||
this.context.defaults.map_center.x,
|
this.context.defaults.map_center.x,
|
||||||
this.context.defaults.map_center.y
|
this.context.defaults.map_center.y,
|
||||||
],
|
],
|
||||||
zoom: this.context.defaults.map_center.z
|
zoom: this.context.defaults.map_center.z
|
||||||
},
|
},
|
||||||
|
@ -8,6 +8,10 @@ import L from 'leaflet';
|
|||||||
import markerIconPng from 'leaflet/dist/images/marker-icon.png'
|
import markerIconPng from 'leaflet/dist/images/marker-icon.png'
|
||||||
import 'leaflet/dist/leaflet.css';
|
import 'leaflet/dist/leaflet.css';
|
||||||
|
|
||||||
|
const lonLatForLeaflet = (coordinates) => {
|
||||||
|
return [coordinates[1], coordinates[0]];
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'AddressMap',
|
name: 'AddressMap',
|
||||||
props: ['entity'],
|
props: ['entity'],
|
||||||
@ -21,10 +25,47 @@ export default {
|
|||||||
center() {
|
center() {
|
||||||
return this.entity.addressMap.center;
|
return this.entity.addressMap.center;
|
||||||
},
|
},
|
||||||
|
hasAddressPoint() {
|
||||||
|
if (Object.keys(this.entity.address).length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (null !== this.entity.address.addressReference) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (null !== this.entity.address.postcode && null !== this.entity.address.postcode.center) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @returns {coordinates: [float, float], type: "Point"}
|
||||||
|
*/
|
||||||
|
addressPoint() {
|
||||||
|
if (Object.keys(this.entity.address).length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== this.entity.address.addressReference) {
|
||||||
|
return this.entity.address.addressReference.point;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== this.entity.address.postcode && null !== this.entity.address.postcode.center) {
|
||||||
|
return this.entity.address.postcode.center;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods:{
|
methods:{
|
||||||
init() {
|
init() {
|
||||||
this.map = L.map('address_map').setView([46.67059, -1.42683], 12);
|
this.map = L.map('address_map');
|
||||||
|
|
||||||
|
if (!this.hasAddressPoint) {
|
||||||
|
this.map.setView(lonLatForLeaflet(this.entity.addressMap.center), this.entity.addressMap.zoom);
|
||||||
|
} else {
|
||||||
|
this.map.setView(lonLatForLeaflet(this.addressPoint.coordinates), 15);
|
||||||
|
}
|
||||||
|
|
||||||
this.map.scrollWheelZoom.disable();
|
this.map.scrollWheelZoom.disable();
|
||||||
|
|
||||||
@ -37,27 +78,22 @@ export default {
|
|||||||
iconAnchor: [12, 41],
|
iconAnchor: [12, 41],
|
||||||
});
|
});
|
||||||
|
|
||||||
this.marker = L.marker([48.8589, 2.3469], {icon: markerIcon});
|
if (!this.hasAddressPoint) {
|
||||||
|
this.marker = L.marker(lonLatForLeaflet(this.entity.addressMap.center), {icon: markerIcon});
|
||||||
|
} else {
|
||||||
|
this.marker = L.marker(lonLatForLeaflet(this.addressPoint.coordinates), {icon: markerIcon});
|
||||||
|
}
|
||||||
this.marker.addTo(this.map);
|
this.marker.addTo(this.map);
|
||||||
},
|
},
|
||||||
update() {
|
update() {
|
||||||
/*<<<<<<< HEAD
|
|
||||||
//console.log('update map with : ', this.entity.addressMap.center)
|
|
||||||
if (this.marker && this.entity.addressMap.center) {
|
if (this.marker && this.entity.addressMap.center) {
|
||||||
this.marker.setLatLng(this.entity.addressMap.center);
|
this.marker.setLatLng(lonLatForLeaflet(this.entity.addressMap.center));
|
||||||
this.map.setView(this.entity.addressMap.center, this.entity.addressMap.zoom);
|
this.map.panTo(lonLatForLeaflet(this.entity.addressMap.center));
|
||||||
=======*/
|
|
||||||
console.log('update map with : ', this.center)
|
|
||||||
if (this.marker && this.center) {
|
|
||||||
this.marker.setLatLng(this.center);
|
|
||||||
this.map.setView(this.center, 15);
|
|
||||||
//>>>>>>> 52512e45f (Fixed: [vue][add-address] fix map center when editing existing address)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted(){
|
mounted() {
|
||||||
this.init();
|
this.init();
|
||||||
this.update();
|
},
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -98,11 +98,6 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
|
||||||
if (typeof this.value.point !== 'undefined') {
|
|
||||||
this.updateMapCenter(this.value.point);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
transName(value) {
|
transName(value) {
|
||||||
return value.streetNumber === undefined ? value.street : `${value.streetNumber}, ${value.street}`
|
return value.streetNumber === undefined ? value.street : `${value.streetNumber}, ${value.street}`
|
||||||
|
@ -45,14 +45,12 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.init();
|
console.log('country selection mounted', this.value);
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
init() {
|
|
||||||
if (this.value !== undefined) {
|
if (this.value !== undefined) {
|
||||||
this.selectCountry(this.value);
|
this.selectCountry(this.value);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
methods: {
|
||||||
selectCountryByCode(countryCode) {
|
selectCountryByCode(countryCode) {
|
||||||
return this.entity.loaded.countries.filter(c => c.countryCode === countryCode)[0];
|
return this.entity.loaded.countries.filter(c => c.countryCode === countryCode)[0];
|
||||||
},
|
},
|
||||||
|
@ -174,8 +174,8 @@ export default {
|
|||||||
},
|
},
|
||||||
updateMapCenter(point) {
|
updateMapCenter(point) {
|
||||||
console.log('point', point);
|
console.log('point', point);
|
||||||
this.addressMap.center[0] = point.coordinates[1]; // TODO use reverse()
|
this.addressMap.center[0] = point.coordinates[0];
|
||||||
this.addressMap.center[1] = point.coordinates[0];
|
this.addressMap.center[1] = point.coordinates[1];
|
||||||
this.$refs.addressMap.update(); // cast child methods
|
this.$refs.addressMap.update(); // cast child methods
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user