Fix geometry module field map if one coordinate is missing

This commit is contained in:
Kelani Tolulope
2023-06-23 11:57:00 +01:00
parent 625d02e8d5
commit 60cfddabe7
9 changed files with 56 additions and 35 deletions
@@ -43,6 +43,7 @@
<script>
import { latLng } from 'leaflet'
import { isNumber } from 'lodash'
export default {
props: {
@@ -79,7 +80,11 @@ export default {
},
getLatLng (coordinates = [0, 0]) {
return latLng(coordinates[0], coordinates[1])
const [lat, lng] = coordinates
if (isNumber(lat) && isNumber(lng)) {
return latLng(lat, lng)
}
},
placeMarker ({ latlng = {} }) {
@@ -220,6 +220,7 @@ import { latLng } from 'leaflet'
import { LControl } from 'vue2-leaflet'
import { OpenStreetMapProvider } from 'leaflet-geosearch'
import { components } from '@cortezaproject/corteza-vue'
import { isNumber } from 'lodash'
const { CInputSearch } = components
export default {
@@ -294,8 +295,13 @@ export default {
methods: {
openMap (index) {
this.localValueIndex = index
const firstCoordinates = (index ? this.localValue[index] : (this.field.isMulti ? this.localValue[0] : this.localValue)) || {}
this.map.center = firstCoordinates.coordinates && firstCoordinates.coordinates.length ? firstCoordinates.coordinates : this.field.options.center
const firstCoordinates = (index >= 0 ? this.localValue[index] : this.localValue) || {}
firstCoordinates.coordinates = [...firstCoordinates.coordinates]
this.map.center = firstCoordinates.coordinates &&
firstCoordinates.coordinates.length === 2 &&
firstCoordinates.coordinates.every(isNumber) ? firstCoordinates.coordinates : this.field.options.center
this.map.zoom = index >= 0 ? 13 : this.field.options.zoom
this.map.show = true
@@ -307,7 +313,7 @@ export default {
getLatLng (coordinates = [undefined, undefined]) {
const [lat, lng] = coordinates
if (lat && lng) {
if (isNumber(lat) && isNumber(lng)) {
return latLng(lat, lng)
}
},
@@ -91,6 +91,7 @@ import { latLng } from 'leaflet'
import { LControl } from 'vue2-leaflet'
import { OpenStreetMapProvider } from 'leaflet-geosearch'
import { components } from '@cortezaproject/corteza-vue'
import { isNumber } from 'lodash'
const { CInputSearch } = components
export default {
@@ -152,7 +153,7 @@ export default {
getLatLng (coordinates = [undefined, undefined]) {
const [lat, lng] = coordinates
if (lat && lng) {
if (isNumber(lat) && isNumber(lng)) {
return latLng(lat, lng)
}
},
@@ -70,7 +70,8 @@ import { LPolygon, LControl } from 'vue2-leaflet'
import { compose, NoID } from '@cortezaproject/corteza-js'
import { mapGetters, mapActions } from 'vuex'
import { evaluatePrefilter } from 'corteza-webapp-compose/src/lib/record-filter'
import { throttle } from 'lodash'
import { throttle, isNumber } from 'lodash'
import base from './base'
export default {
@@ -111,12 +112,14 @@ export default {
geo.forEach((value) => {
if (value.displayMarker) {
value.markers.map(subValue => {
values.push({
value: this.getLatLng(subValue),
color: value.color,
recordID: value.recordID,
moduleID: value.moduleID,
})
if (this.getLatLng(subValue)) {
values.push({
value: this.getLatLng(subValue) || {},
color: value.color,
recordID: value.recordID,
moduleID: value.moduleID,
})
}
})
}
})
@@ -208,16 +211,18 @@ export default {
markers = [geometry]
}
return ({
title: record.values[feed.titleField],
geometry: feed.displayPolygon ? geometry : [],
markers,
color: feed.options.color,
displayMarker: feed.displayMarker,
recordID: record.recordID,
moduleID: record.moduleID,
})
})
if (geometry.length && geometry.length === 2) {
return ({
title: record.values[feed.titleField],
geometry: feed.displayPolygon ? geometry : [],
markers,
color: feed.options.color,
displayMarker: feed.displayMarker,
recordID: record.recordID,
moduleID: record.moduleID,
})
}
}).filter(g => g)
}
})
})
@@ -248,13 +253,14 @@ export default {
},
parseGeometryField (value) {
return JSON.parse(value || '{"coordinates":[]}').coordinates || []
value = JSON.parse(value || '{"coordinates":[]}').coordinates || []
return value.every(isNumber) ? value : []
},
getLatLng (coordinates = [undefined, undefined]) {
const [lat, lng] = coordinates
if (lat && lng) {
if (isNumber(lat) && isNumber(lng)) {
return latLng(lat, lng)
}
},
@@ -135,7 +135,6 @@
<script>
import base from '../base'
import { latLng } from 'leaflet'
import { LControl } from 'vue2-leaflet'
export default {
@@ -176,14 +175,6 @@ export default {
},
methods: {
getLatLng (coordinates = [undefined, undefined]) {
const [lat, lng] = coordinates
if (lat && lng) {
return latLng(lat, lng)
}
},
updateCenter (coordinates) {
let { lat = 0, lng = 0 } = coordinates || {}
+1
View File
@@ -28,6 +28,7 @@
"i18next": "^17.0.9",
"i18next-browser-languagedetector": "^3.0.2",
"leaflet": "^1.7.1",
"lodash": "^4.17.21",
"portal-vue": "^2.1.7",
"vue": "2.6.14",
"vue-router": "^3.4.9",
@@ -20,6 +20,7 @@
</template>
<script>
import { isNumber } from 'lodash'
import { latLng } from 'leaflet'
export default {
@@ -69,7 +70,11 @@ export default {
methods: {
getLatLng (coordinates = [0, 0]) {
return latLng(coordinates[0], coordinates[1])
const [lat, lng] = coordinates
if (isNumber(lat) && isNumber(lng)) {
return latLng(lat, lng)
}
},
onMarkerClick (ID) {
+1
View File
@@ -26,6 +26,7 @@
"i18next": "^17.0.9",
"i18next-browser-languagedetector": "^3.0.2",
"leaflet": "^1.7.1",
"lodash": "^4.17.21",
"portal-vue": "^2.1.7",
"vue": "2.6.14",
"vue-grid-layout": "^2.3.12",
@@ -43,6 +43,7 @@
<script>
import { latLng } from 'leaflet'
import { isNumber } from 'lodash'
import { LMap, LTileLayer, LMarker, LTooltip } from 'vue2-leaflet'
export default {
@@ -97,7 +98,11 @@ export default {
},
getLatLng (coordinates = [0, 0]) {
return latLng(coordinates[0], coordinates[1])
const [lat, lng] = coordinates
if (isNumber(lat) && isNumber(lng)) {
return latLng(lat, lng)
}
},
},
}