在 MOUSE_MOVE 事件后测量地图上的线的长度

发布于 2024-11-06 11:52:51 字数 466 浏览 1 评论 0原文

用户可以使用ESRI Flex Viewer 应用程序执行的操作之一是在地图上绘制形状(例如线条)。一旦用户完成绘制线条,他们将双击鼠标,从而触发 DrawEvent.DRAW_END 事件。触发此函数后,将通过调用 API 函数geometryService.project([geometryObject], SpatialReference); 来测量直线。

我希望能够在 MouseEvent.MOUSE_MOVE 事件之后调用此函数,以便动态测量线,而不是仅在 DRAW_END 事件之后调用。不幸的是,只有两个被调度的 DrawEvent 是 DrawEvent.DRAW_START 和 DrawEvent.DRAW_END。这些 ESRI 类是编译类,因此我无法对它们进行任何更改。

有没有办法将事件监听器添加到 MOUSE_MOVE 事件中,以获取正在绘制的线的当前几何形状并调用我的 API 函数来进行动态测量?

提前致谢。

One of the actions a user can perform using the ESRI Flex Viewer application is to draw a shape on a map (e.g. a line). Once the user is finished drawing the line, they will double-click the mouse which fires a DrawEvent.DRAW_END event. When this is fired, the line is measured using a call to an API function geometryService.project([geometryObject], spatialReference);.

I want to be able to call this function after a MouseEvent.MOUSE_MOVE event in order to measure the line on the fly, instead of only after the DRAW_END event. Unfortunately, the only two DrawEvents that get dispatched are the DrawEvent.DRAW_START and DrawEvent.DRAW_END. These ESRI classes are compiled classes, so I cannot make any changes to them.

Is there a way to add an eventListener to a MOUSE_MOVE event that can grab the current geometry of the line that is being drawn and call my API function to measure on the fly?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赤濁 2024-11-13 11:52:51

我通过完全绕过几何服务并构建自己的解决方案找到了这个问题的解决方案。有一个 很棒的站点,它实现了 Vincenty 算法来测量两个坐标之间的距离。这是一种非常精确的近似算法(在 Vincenty 地球椭球上的 0.5 毫米以内),并且非常高效,因此可以经常使用(例如,在鼠标移动后)。

以下是实现此目的的基本步骤:

  1. 向地图添加一个事件侦听器,用于侦听鼠标单击
  2. 单击鼠标后,将屏幕上单击位置的坐标转换为地图坐标,并添加一个侦听器来监视鼠标单击鼠标移动事件
  3. 当鼠标移动时,抓取鼠标的坐标(如步骤 2 所示)并执行 Vincenty 计算。在地图上创建自定义工具提示并将 Vincenty 结果添加到工具提示文本中。
  4. 双击后,将结果发送到几何服务并从地图中删除工具提示

I found a solution to this problem by circumventing the geometry service altogether and building a solution of my own. There is a great site that implements the Vincenty algorithm for measuring the distance between two coordinates. This is a very accurate approximation algorithm (within .5mm on Vincenty's earth ellipsoid), and is meant to be very efficient so that it can be used frequently (e.g. after a mouse moves).

Here's the basic steps to implement this:

  1. Add an event listener to the map that listens for a mouse click
  2. Once the mouse is clicked, convert the coordinates of the location of the click on the screen to map coordinates and add a listener to watch for a mouse move event
  3. When the mouse moves, grab the coordinates of the mouse (as in step 2) and perform the Vincenty calculation. Create a custom tooltip on the map and add the Vincenty result to the tooltip text.
  4. Upon double-click, send the result to the Geometry service and remove the tooltip from the map
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文