为什么在 Openlayers 中创建多边形时需要 getPointResolution

问题描述

所以我看到了一个创建多边形圆以进行缩放的示例。即从兴趣点到半径的实际距离。

  map.on('postrender',function (event) {
        const { projection,resolution,center,} = event.frameState.viewState;
        pointResolution = getPointResolution(projection.getCode(),center);
    });

是否有必要这样做 var newradius = radius / pointResolution 因为这并没有给我正确的距离(以米为单位)。 它实际上将它分开。 我不知道这是否有意义。

 function addCirclepolygon(coordinates) {
        if (vectorSource && vectorSource.getFeatures().length > 0) {
            vectorSource.clear();
        }
        var radius = $scope.options.radius;
        if (createpolygon) {
            **var radius = radius / pointResolution;** <---problem
            circle = new Feature(new Circle(coordinates,radius));
            circle.setStyle(new Style({
                stroke: new stroke({
                    color: $scope.options.lcolor,width: $scope.options.lwidth
                }),fill: new Fill({
                    color: $scope.options.fcolor ? $scope.options.fcolor : 'rgba(255,255,0.0)'
                })
            }));
            var geom = circle.get('geometry');
            if (circle instanceof Circle) {
                // We don't like circles,at all.  So here we convert
                // drawn circles to their equivalent polygons.  
                circle.set('geometry',fromCircle(geom));
            }
            vectorSource.addFeature(circle);
            /**
             * Adds a line to show the radius in Units(meters as default)
             * Leaving this here for prosterity
             */
            if (circle) {
                let line = addRadius(circle);
                vectorSource.addFeature(line);
            }
        }
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)