如何在 Openstreetmap 上双击获取坐标? [英] How to get coordinates on double click on Openstreetmap?

查看:28
本文介绍了如何在 Openstreetmap 上双击获取坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 angular-openlayers-directive ,我想获得坐标我双击的点.

I am using angular-openlayers-directive , I want to get coordinates of the point where I double click.

一个类似的问题:

将点转换为经纬度

但我想在 angularjs 中使用它.

But I want to use it in angularjs.

推荐答案

你应该看看这个例子:http://tombatossals.github.io/angular-openlayers-directive/examples/080-events-propagation-example.html.它显示了如何找到鼠标悬停的经纬度坐标.另外,这是我制作的一个小提琴,展示了如何扩展它以进行双击:http://jsfiddle.net/anushamc/6q2az5xz/.简而言之,您需要通过将其包含在默认值中来侦听地图上的事件,例如:

You should check this example out: http://tombatossals.github.io/angular-openlayers-directive/examples/080-events-propagation-example.html. It shows how you can find the lat-long coordinates for mouseover. Also, here is a fiddle I made showing how you can extend it for double click: http://jsfiddle.net/anushamc/6q2az5xz/. Briefly, you need to listen for the events on the map by including it in the defaults like:

defaults: {
      events: {
        map: ['singleclick', 'pointermove', 'dblclick']
      }
    }

<openlayers ol-defaults="defaults"></openlayers>

并在作用域上包含 openlayers.map.dblclick 的侦听器.

and include a listener for openlayers.map.dblclick on the scope.

$scope.$on('openlayers.map.dblclick', function(event, data) {
    $scope.$apply(function() {
      if ($scope.projection === data.projection) {
        $scope.mousedoubleclickposition = data.coord;
      } else {
        var p = ol.proj.transform([data.coord[0], data.coord[1]], data.projection, $scope.projection);
        $scope.mousedoubleclickposition = {
          lat: p[1],
          lon: p[0],
          projection: $scope.projection
        }
      }
    });
  });

这篇关于如何在 Openstreetmap 上双击获取坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆