1
1
import Map from "https://js.arcgis.com/4.29/@arcgis/core/Map.js" ;
2
2
import MapView from "https://js.arcgis.com/4.29/@arcgis/core/views/MapView.js" ;
3
3
import CoordinateConversion from "https://js.arcgis.com/4.29/@arcgis/core/widgets/CoordinateConversion.js" ;
4
+ import Conversion from "https://js.arcgis.com/4.29/@arcgis/core/widgets/CoordinateConversion/support/Conversion.js" ;
4
5
import { watch } from "https://js.arcgis.com/4.29/@arcgis/core/core/reactiveUtils.js" ;
5
6
6
7
// -----------------
@@ -24,7 +25,7 @@ const view = new MapView({
24
25
zoom : 10 ,
25
26
} ) ;
26
27
27
- const ccWidget = new CoordinateConversion ( { view, multipleConversions : false } ) ;
28
+ const ccWidget = new CoordinateConversion ( { view, multipleConversions : true } ) ;
28
29
29
30
view . ui . add ( ccWidget , "bottom-left" ) ;
30
31
@@ -55,35 +56,38 @@ const coordinateEditable = document.getElementById(
55
56
"custom-coordinate-editable"
56
57
) ;
57
58
58
- updateFormats ( ) ;
59
- updateCoordinates ( ) ;
60
-
61
59
watch (
62
60
( ) => [ vm . formats . length , vm . conversions . getItemAt ( 0 ) ?. displayCoordinate ] ,
63
61
( ) => {
64
62
updateFormats ( ) ;
65
63
updateCoordinates ( ) ;
66
- }
64
+ } ,
65
+ { initial : true }
67
66
) ;
68
67
69
68
coordinateSelect . addEventListener ( "calciteSelectChange" , ( event ) => {
70
- vm . activeFormat = event . target . selectedOption . value ;
69
+ const value = event . target . value ;
70
+ const format = vm . formats . find ( ( format ) => format . name === value ) ;
71
+ const newConversion = new Conversion ( { format } ) ;
72
+ vm . conversions . removeAt ( 0 ) ;
73
+ vm . conversions . add ( newConversion , 0 ) ;
71
74
} ) ;
72
75
73
76
coordinateMode . addEventListener ( "calciteSegmentedControlChange" , ( event ) => {
74
77
const value = event . target . value ;
75
78
vm . mode = value ;
76
- console . log ( vm . mode ) ;
77
79
} ) ;
78
80
81
+ function findFormatIndex ( name ) {
82
+ return vm . formats . findIndex ( ( format ) => format . name === name ) ?? - 1 ;
83
+ }
84
+
79
85
async function reverseConvert ( ) {
80
86
const value = coordinateInput . value ;
81
87
const selectFormat = vm . conversions . at ( 0 ) ?. format ;
82
- const selectIndex =
83
- vm . formats . findIndex ( ( format ) => format . name === selectFormat ?. name ) ?? - 1 ;
88
+ const selectIndex = findFormatIndex ( selectFormat ?. name ) ;
84
89
const format = vm . formats . getItemAt ( selectIndex ) ;
85
- console . log ( { format } ) ;
86
- const point = await vm . reverseConvert ( value , format ) ;
90
+ const point = await vm . reverseConvert ( value , format ) ; // todo: catch this, add status
87
91
view . goTo ( point ) ;
88
92
}
89
93
@@ -98,18 +102,10 @@ coordinateInput.addEventListener("keydown", (event) => {
98
102
} ) ;
99
103
100
104
function updateFormats ( ) {
101
- // const conversionNames = vm.conversions?.map(
102
- // (conversion) => conversion.format?.name
103
- // );
104
-
105
105
const selectFormat = vm . conversions . at ( 0 ) ?. format ;
106
- const selectIndex =
107
- vm . formats . findIndex ( ( format ) => format . name === selectFormat ?. name ) ?? - 1 ;
108
-
109
- console . log ( { selectIndex } ) ;
106
+ const selectIndex = findFormatIndex ( selectFormat ?. name ) ;
110
107
111
108
const formatsTemplate = vm . formats
112
- //?.filter((format) => !conversionNames.includes(format.name))
113
109
. toArray ( )
114
110
. map (
115
111
( format , index ) =>
@@ -123,6 +119,5 @@ function updateFormats() {
123
119
}
124
120
125
121
function updateCoordinates ( ) {
126
- console . log ( { vm } ) ;
127
122
coordinateInput . value = vm . conversions . getItemAt ( 0 ) ?. displayCoordinate ?? "" ;
128
123
}
0 commit comments