使用 ComboBox 下拉式選單在 Graph Builder 中動態變更緯度和經度注意:資料和腳本已上傳至下方...
我開發了以下腳本,首先繪製一個顯示路線的廣大區域。然後會彈出一個模態窗口,允許使用者輸入特定位置的代碼-在本例中是1或2。輸入此代碼後,圖表會放大到該位置。雖然一切正常,但這並不是我真正需要的。最重要的是,一旦做出選擇並結束腳本,對話方塊就會消失。其次,我一直嘗試將其與ComboBox下拉式選單配合使用。菜單本身可以正常工作,但不知何故,我似乎無法選擇更改圖表。
以下是我所擁有的模態文字方塊...
Names Default To Here( 1 );
dt = Data Table( "Test Data" );
gb = Graph Builder(
Graph Spacing( 10 ),
Spacing Borders( 1 ),
Variables( X( :Longitude ), Y( :Latitude ) ),
Elements( Points( X, Y, Legend( 3 ) ) ),
SendToReport(
Dispatch( {}, "Longitude", ScaleBox, {Min( -104 ), Max( -98.47 )} ),
Dispatch( {}, "Latitude", ScaleBox, {Min( 29.21 ), Max( 33.30 )} ),
Dispatch( {}, "Graph Builder", FrameBox,
{Background Map( Images( "Street Map Service", "Mapbox Satellite", "" ) )}
)
)
);
// Build the modal input window
New Window( "Pick a spot",
Modal,
H List Box(
V List Box( Text Box( "Location Number:" ), ),
V List Box( box = Number Edit Box( "Enter location number..." ), )
),
Button Box( "OK",
// Script to run when "OK" is clicked
locNum = box << Get;
Print( "Location Number: " || Char( locNum ) );
),
Button Box( "Cancel",
// Script to run when "Cancel" is clicked
Throw()
)
);
If(
locNum == 1,
minLat = 30.99;
maxLat = 31.06;
minLong = -101.21;
maxLong = -101.11;
run = "1|1";,
locNum == 2,
minLat = 31.34;
maxLat = 31.41;
minLong = -101.81;
maxLong = -101.71;
run = "2|1";
);
gb << Dispatch( {}, "Longitude", ScaleBox, {Min( minLong ), Max( maxLong )} );
gb << Dispatch( {}, "Latitude", ScaleBox, {Min( minLat ), Max( maxLat )} );
初始地圖看起來像這樣…

放大後的視圖如下圖...

所以我的困境是 1)如何讓 ComboBox 與此一起工作,以及 2)如何阻止腳本完成,以便用戶可以繼續從下拉式選單中選擇不同的項目。
我感覺這與設定函數命令有關,但我多次嘗試讓它工作但都沒有結果。
任何有關此事的指導都將不勝感激。
謝謝。
自動化和腳本回覆:使用組合方塊下拉式選單動態變更圖形產生器中的緯度和經度我不會用模態視窗來做這樣的事情
Names Default To Here(1);
dt = Data Table("Test Data");
gb = dt << Graph Builder(
Graph Spacing(10),
Spacing Borders(1),
Variables(X(:Longitude), Y(:Latitude)),
Elements(Points(X, Y, Legend(3))),
SendToReport(
Dispatch({}, "Longitude", ScaleBox, {Min(-104), Max(-98.47)}),
Dispatch({}, "Latitude", ScaleBox, {Min(29.21), Max(33.30)}),
Dispatch({}, "Graph Builder", FrameBox,
{Background Map(Images("Street Map Service", "Mapbox Satellite", ""))}
)
)
);
wait(0);
cb_expr = Expr(
locNum = cb_option << get;
show(locNum);
If(
locNum == 1,
minLat = 30.99;
maxLat = 31.06;
minLong = -101.21;
maxLong = -101.11;
run = "1|1";,
locNum == 2,
minLat = 31.34;
maxLat = 31.41;
minLong = -101.81;
maxLong = -101.71;
run = "2|1";
);
gb << Dispatch({}, "Longitude", ScaleBox, {Min(minLong), Max(maxLong)});
gb << Dispatch({}, "Latitude", ScaleBox, {Min(minLat), Max(maxLat)});
);
// Build the modal input window
nw = New Window("Pick a spot",
Lineup Box(N Col(2),
Text Box("Location Number:"),
cb_option = Combo Box({"1", "2"},
cb_expr
),
),
Button Box("OK",
cb_expr; // not necessary if you wish to run when combo box is changed
Print("Location Number: " || Char(locNum));
),
Button Box("Cancel",
// Script to run when "Cancel" is clicked
Throw()
)
);
您也可以將選項移至關聯數組中,以便以後更輕鬆地添加更多選項
回覆:使用組合方塊下拉式選單動態變更圖形產生器中的緯度和經度謝謝@jthi 。這太完美了。
因此,我們的想法是將 ComboBox 操作包裝在 Eval() 區塊中,然後在執行 ComboBox 時將區塊作為腳本運行。我想我的理解是正確的。
回覆:使用組合方塊下拉式選單動態變更圖形產生器中的緯度和經度您可以在組合框內移動表達式,但如果您將其分開,修改通常會容易得多,特別是當您在多個地方使用相同的操作時
看更多...
Names Default To Here(1);
dt = Data Table("Test Data");
gb = dt << Graph Builder(
Graph Spacing(10),
Spacing Borders(1),
Variables(X(:Longitude), Y(:Latitude)),
Elements(Points(X, Y, Legend(3))),
SendToReport(
Dispatch({}, "Longitude", ScaleBox, {Min(-104), Max(-98.47)}),
Dispatch({}, "Latitude", ScaleBox, {Min(29.21), Max(33.30)}),
Dispatch({}, "Graph Builder", FrameBox,
{Background Map(Images("Street Map Service", "Mapbox Satellite", ""))}
)
)
);
wait(0);
// Build the modal input window
nw = New Window("Pick a spot",
Lineup Box(N Col(2),
Text Box("Location Number:"),
cb_option = Combo Box({"1", "2"},
locNum = cb_option << get;
show(locNum);
If(
locNum == 1,
minLat = 30.99;
maxLat = 31.06;
minLong = -101.21;
maxLong = -101.11;
run = "1|1";,
locNum == 2,
minLat = 31.34;
maxLat = 31.41;
minLong = -101.81;
maxLong = -101.71;
run = "2|1";
);
gb << Dispatch({}, "Longitude", ScaleBox, {Min(minLong), Max(maxLong)});
gb << Dispatch({}, "Latitude", ScaleBox, {Min(minLat), Max(maxLat)});
),
),
Button Box("OK",
locNum = cb_option << get;
show(locNum);
If(
locNum == 1,
minLat = 30.99;
maxLat = 31.06;
minLong = -101.21;
maxLong = -101.11;
run = "1|1";,
locNum == 2,
minLat = 31.34;
maxLat = 31.41;
minLong = -101.81;
maxLong = -101.71;
run = "2|1";
);
gb << Dispatch({}, "Longitude", ScaleBox, {Min(minLong), Max(maxLong)});
gb << Dispatch({}, "Latitude", ScaleBox, {Min(minLat), Max(maxLat)});
Print("Location Number: " || Char(locNum));
),
Button Box("Cancel",
// Script to run when "Cancel" is clicked
Throw()
)
);
您也可以使用 << 設定函數來代替 < 您可以使用的參數, 組合方塊)
Names Default To Here(1);
aa_options = Associative Array();
aa_options[1] = [
"minLat" => 30.99,
"maxLat" => 31.06,
"minLong" => -101.21,
"maxLong" => -101.11,
"run" => "1|1"
];
aa_options[2] = [
"minLat" => 31.34,
"maxLat" => 31.41,
"minLong" => -101.81,
"maxLong" => -101.71,
"run" => "2|1"
];
update_graph = Function({cb_ref, idx}, {Default Local},
s = aa_options[idx];
show(s);
gb << Dispatch({}, "Longitude", ScaleBox, {Min(s["minLong"]), Max(s["maxLong"])});
gb << Dispatch({}, "Latitude", ScaleBox, {Min(s["minLat"]), Max(s["maxLat"])});
);
dt = Data Table("Test Data");
gb = dt << Graph Builder(
Graph Spacing(10),
Spacing Borders(1),
Variables(X(:Longitude), Y(:Latitude)),
Elements(Points(X, Y, Legend(3))),
SendToReport(
Dispatch({}, "Longitude", ScaleBox, {Min(-104), Max(-98.47)}),
Dispatch({}, "Latitude", ScaleBox, {Min(29.21), Max(33.30)}),
Dispatch({}, "Graph Builder", FrameBox,
{Background Map(Images("Street Map Service", "Mapbox Satellite", ""))}
)
)
);
wait(0);
options = Transform Each({item}, aa_options << get keys, Char(item)); // combo box requires strings
nw = New Window("Pick a spot",
Lineup Box(N Col(2),
Text Box("Location Number:"),
cb_option = Combo Box(options,
<< Set Function(Function({this, idx},
update_graph(this, idx);
))
)
),
Button Box("Cancel",
<< Set Function(function({this},
this << close window;
))
)
);