本文介绍了打开第3层-从拖放到矢量数据中获取矢量类型(线,多边形,点)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OpenLayers 3具有出色的拖放功能.示例在这里给出:

OpenLayers 3 has a great drag and drop feature. The example is given here:

http://openlayers.org/en/master/examples/drag-and-drop.html

在这种情况下,您可以在拖放的事件处理程序中访问已拖入(vectorSource)的矢量层:

Within the event handler for the drag and drop you can access the vector layer that has been dragged in (vectorSource) in this case:

dragAndDropInteraction.on('addfeatures', function(event) {
    var vectorSource = new ol.source.Vector({
      features: event.features
    });
    map.addLayer(new ol.layer.Vector({
      source: vectorSource,
      style: styleFunction
    }));
    map.getView().fit(
        vectorSource.getExtent(), /** @type {ol.Size} */ (map.getSize()));
  });

可以看到

vectorSource是从event.features创建的,但是我找不到一种方法来判断放入地图的矢量是否为多边形 point类型 line .

我的问题是,有没有办法告诉数据是什么矢量类型?

My question is, is there a way of telling what vector type the data is?

console.log(event.features);显示其中存在一个几何术语,但是我不确定这如何可靠地给出我的数据类型.

console.log(event.features); shows that there is a geometry term in there, but I'm not sure how that reliably gives me data type.

我需要了解我的图层管理工具,以便可以正确表示矢量图层.

I need to know for my layer management tool so that I can correctly represent the vector layer.

我尝试过:

event.features[0].getGeometry();
event.features[0].getGeometryName();

似乎都无法提供我需要的信息.

Neither seem to produce the information I need.

推荐答案

如果具有要素,则可以检索其几何图形,然后检索其类型:

If you have a feature, you can retrieve its Geometry and then its Type:

feature.getGeometry().getType()

参考: http://openlayers.org/en/v3.0.0/apidoc/ol.geom.html#GeometryType

这篇关于打开第3层-从拖放到矢量数据中获取矢量类型(线,多边形,点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 13:10