Pass additional parameter to a module
Hi,
I've written a custom module containing a command that, when executed, opens a new browser window with an external site, and passes the clicked coordinate to it: E.g. http://other.server.com/showinfo?x=12345&y=67890. The url is stored in the viewer.xml, in the module's configuration section. This works, but now I need to add a second toolbutton to the viewer, to open another url. My quick and dirty solution was to duplicate the command's code, and have a second url in the configuration.
Obviously this is not ideal, because for every additional tool-button I'd have to modify the module. So is there a way to set an additional parameter in the tool's configuration, and pass that to the command? Something like this: <ToolName="OpenUrl" DisplayName="Open another site" DrawMode="Point" Command="LaunchUrl" UrlTemplate="http://other.server.com/showinfo?x={0}&y={1}<span >http</span><span >://other.server.com/showinfo?x=12345&y=67890</span>" />
Best regards,
-
Yes it is possible, but it is a bit complicated.
Your LaunchUrl command likely has a parameter type of
ESRI.ArcGIS.Client.Geometry.GeometryorESRI.ArcGIS.Client.Geometry.MapPoint. If you change this type to:Geocortex.EssentialsSilverlightViewer.Infrastructure.Events.ToolEventPayload<ESRI.ArcGIS.Client.Draw,ESRI.ArcGIS.Client.DrawEventArgs>then rather than having the geometry passed to your command it will receive the entire tool event payload. This object provides access to both the geometry and the tool object with its child XML configuration.
This allows you to configure your tool like this:
<ToolName="OpenUrl" DisplayName="Open another site" DrawMode="Point" Command="LaunchUrl"><ConfigurationUrlTemplate="http://other.server.com/showinfo?x={0}&y={1}" /></Tool>In your command implementation you can use
payload.Args.Geometryto get the Geometry andpayload.Tool.XmlConfigurationto get the tool's child config element. You'll have to parse the XML yourself.--Ryan
0 -
Ryan,
Actually it isn't that hard once you know how to do it... The hardest part in this case is to find out about ToolEventPayLoad. Is this documented somewhere?
Thanks a lot,
Berend
0 -
I spoke too soon /customer/servlet/servlet.FileDownload?file=00P6000000e88GMEAY
It works perfectly for a tool, but not for a menu item in the map's context menu.
When the command parameter was a Geometry it did work, and the clicked coordinate was passed to the command, but now that I've changed it to ToolEventPayLoad, the parameter is empty:
privatevoid ExecuteUrl(ToolEventPayload<Draw, DrawEventArgs> args)<p> </p> {//args = null herewhenAnd this is from my viewer.xml
<MenuId="MapMenu"><p> </p> <Items><p> </p> <Item Text="Open cyclomedia" Command="LaunchUrl"><p> </p> <Configuration UrlTemplate="http://my.server.com/page.html?X={0}&Y={1}" /> <p> </p> </Item>Can this also be done? Is there something like ItemEventPayLoad?
0 -
I figured it out. My module now listens to the map's MouseRightButtonDown event, so I can retrieve the location of the context menu. I use the item's CommandParameter value to store the urlTemplate. The only downside is that I now need two NamedCommands: one that can be called as a tool from a toolbar, and the other that can be called from the context menu. I think I can live with that.
0
Du måste logga in om du vill lämna en kommentar.
Kommentarer
4 kommentarer