Select to view content in your preferred language

How can I create a custom context menu for right clicking in a map?

1358
3
Jump to solution
05-26-2023 10:43 AM
KyleBPerri
Emerging Contributor

I would like the user to right-click on the map and depending on the feature that was clicked, a custom context menu would show up rather than the default one. I know this is possible using a MapTool, but I don't want the user to have to first click the MapTool before having this functionality. I'd prefer that it is just automatically on at all times. Is that possible?

0 Kudos
1 Solution

Accepted Solutions
CharlesMacleod
Esri Regular Contributor

there are already built-in context menus for the mapview/scene view, depending on which COTS tool is active. Customize the relevant existing context menus to host your custom functionality - whether buttons, tools, menus, etc.

Here is an example of customizing the default map view context menu - shown when the "Explore" tool is active and the 2D selection menu shown when the "Select" tool is active. "<updateModule" goes in your Config.daml

<button id="TestAddin_Button1" caption="Test Addin 1" ... />
...
<updateModule refID="esri_mapping">
 <menus>
  <updateMenu refID="esri_mapping_popupToolContextMenu">
    <deleteButton refID="esri_mapping_prevExtentButton"/>
    <deleteButton refID="esri_mapping_nextExtentButton"/>
    <deleteButton refID="esri_mapping_locateReverseGeocode"/>
    <insertButton refID="TestAddin_Button1" insert="before"
        placeWith="esri_mapping_cameraPropertiesControl"/>
  </updateMenu>
  <updateMenu refID="esri_mapping_selection2DContextMenu">
    <deleteButton refID="esri_core_editCopyButton"/>
    <deleteButton refID="esri_core_editPasteButton"/>
    <deleteButton refID="esri_core_editDeleteButton"/>
    <insertButton refID="TestAddin_Button1" insert="before"
       placeWith="esri_editing_EditVerticesMove" separator="true"/>
   </updateMenu>
  </menus>
</updateModule>
        

Result:

context-menu-1.pngcontext-menu-2.png

View solution in original post

3 Replies
CharlesMacleod
Esri Regular Contributor

there are already built-in context menus for the mapview/scene view, depending on which COTS tool is active. Customize the relevant existing context menus to host your custom functionality - whether buttons, tools, menus, etc.

Here is an example of customizing the default map view context menu - shown when the "Explore" tool is active and the 2D selection menu shown when the "Select" tool is active. "<updateModule" goes in your Config.daml

<button id="TestAddin_Button1" caption="Test Addin 1" ... />
...
<updateModule refID="esri_mapping">
 <menus>
  <updateMenu refID="esri_mapping_popupToolContextMenu">
    <deleteButton refID="esri_mapping_prevExtentButton"/>
    <deleteButton refID="esri_mapping_nextExtentButton"/>
    <deleteButton refID="esri_mapping_locateReverseGeocode"/>
    <insertButton refID="TestAddin_Button1" insert="before"
        placeWith="esri_mapping_cameraPropertiesControl"/>
  </updateMenu>
  <updateMenu refID="esri_mapping_selection2DContextMenu">
    <deleteButton refID="esri_core_editCopyButton"/>
    <deleteButton refID="esri_core_editPasteButton"/>
    <deleteButton refID="esri_core_editDeleteButton"/>
    <insertButton refID="TestAddin_Button1" insert="before"
       placeWith="esri_editing_EditVerticesMove" separator="true"/>
   </updateMenu>
  </menus>
</updateModule>
        

Result:

context-menu-1.pngcontext-menu-2.png

KyleBPerri
Emerging Contributor

Can you use conditions to turn these updates to the context menu on and off depending on the state of the condition?

0 Kudos
CharlesMacleod
Esri Regular Contributor

yes, same as u cld do if they were on the ribbon

0 Kudos