How to get coordinates on double click on Openstreetmap?

巧了我就是萌 提交于 2019-12-20 07:48:01

问题


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

A similar question:

Convert point to lat lon

But I want to use it in angularjs.


回答1:


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']
      }
    }

and

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

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
        }
      }
    });
  });


来源:https://stackoverflow.com/questions/36435689/how-to-get-coordinates-on-double-click-on-openstreetmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!