internal class MapTool_WithControl : MapTool { public MapTool_WithControl() { ControlID = "mapTool_EmbeddableControl"; } protected override void OnToolMouseDown(MapViewMouseButtonEventArgs e) { e.Handled = true; } protected override Task HandleMouseDownAsync(MapViewMouseButtonEventArgs e) { //Get the instance of the ViewModel var vm = EmbeddableControl as EmbeddedControlViewModel; if (vm == null) return Task.FromResult(0); //Get the map coordinates from the click point and set the property on the ViewMode. return QueuedTask.Run(() => { var mapPoint = MapView.Active.ClientToMap(e.ClientPoint); vm.ClickText = string.Format("X: {0}, Y: {1}, Z: {2}", mapPoint.X, mapPoint.Y, mapPoint.Z); }); } }
<!-- Copyright 2018 Esri Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <UserControl x:Class="Examples.EmbeddedControlView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <Grid> <TextBlock Text="{Binding ClickText}" HorizontalAlignment="Center"/> </Grid> </UserControl>
/* Copyright 2018 Esri Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using ArcGIS.Desktop.Framework; using ArcGIS.Desktop.Framework.Contracts; using ArcGIS.Desktop.Framework.Controls; using System.Xml.Linq; namespace Examples { /// <summary> /// Derive from ArcGIS.Desktop.Framework.Controls.EmbeddableControl /// </summary> internal class EmbeddedControlViewModel : EmbeddableControl { public EmbeddedControlViewModel(XElement options, bool canChangeOptions) : base(options, canChangeOptions) { } private string _clickText = "Click in view to show coordinates"; public string ClickText { get { return _clickText; } set { SetProperty(ref _clickText, value, () => ClickText); } } } }
<?xml version="1.0" encoding="utf-8" ?> <!-- Copyright 2018 Esri Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <ArcGIS defaultAssembly="Examples.dll" defaultNamespace="Examples" xmlns="http://schemas.esri.com/DADF/Registry" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.esri.com/DADF/Registry file:///C:/Program%20Files/ArcGIS/Pro/bin/ArcGIS.Desktop.Framework.xsd"> <AddInInfo id="{40c18dbd-a8ac-46a1-93ae-4c3ccc618616}"> <Name>Examples</Name> <Description>Examples</Description> </AddInInfo> <!--Define the embeddable control in the Config.daml--> <categories> <updateCategory refID="esri_embeddableControls"> <insertComponent id="mapTool_EmbeddableControl" className="EmbeddedControlViewModel"> <content className="EmbeddedControlView" /> </insertComponent> </updateCategory> </categories> </ArcGIS>
Target Platforms: Windows 10, Windows 8.1