Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript OpenLayers 5绘制交互-“;n不是构造函数“;在Draw.js:338_Javascript_Openlayers 5 - Fatal编程技术网

Javascript OpenLayers 5绘制交互-“;n不是构造函数“;在Draw.js:338

Javascript OpenLayers 5绘制交互-“;n不是构造函数“;在Draw.js:338,javascript,openlayers-5,Javascript,Openlayers 5,我尝试允许用户绘制和修改功能,如下示例:-但我遇到两个错误: Uncaught TypeError: n is not a constructor at e.r [as geometryFunction_] (Draw.js:338) at e.startDrawing_ (Draw.js:700) at e.handleUpEvent (Draw.js:570) at e.handleEvent (Pointer.js:132) at e.handleE

我尝试允许用户绘制和修改功能,如下示例:-但我遇到两个错误:

Uncaught TypeError: n is not a constructor
    at e.r [as geometryFunction_] (Draw.js:338)
    at e.startDrawing_ (Draw.js:700)
    at e.handleUpEvent (Draw.js:570)
    at e.handleEvent (Pointer.js:132)
    at e.handleEvent (Draw.js:524)
    at e.handleMapBrowserEvent (PluggableMap.js:933)
    at e (events.js:41)
    at e.dispatchEvent (Target.js:101)
    at e.handlePointerUp_ (MapBrowserEventHandler.js:166)
    at e (events.js:41)

当我单击开始绘制特征时,控制台中会出现第一个错误。然后,蓝点保持在原来的位置,当我移动鼠标时,第二个错误会反复触发。在第一次单击之后,单击地图不会做任何事情

我在Draw.js中看不到任何明显的东西,而且据我所知,我的代码完全相同,除了一些小的修改以适合我的应用程序之外,正如我上面提到的示例中所示

我使用的是OpenLayers 5.3.0,通过rawgit加载:

<link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" type="text/css">
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>

我正在通过超链接调用addInteractions()和removeInteractions()。在调用addInteractions()之前或调用removeInteractions()之后不会出现错误。

绘图类型应为字符串

  draw = new ol.interaction.Draw({
    source: drawSource,
    type: 'Polygon'
  });

更好的方法是使用ol/geom中的GeometryType.POLYGON/GeometryType@Snote这仅作为导入可用,它不包括在
ol.js
legacy构建中
var drawSource = new ol.source.Vector();
var drawVector = new ol.layer.Vector({
  source: drawSource,
  style: new ol.style.Style({
    fill: new ol.style.Fill({
      color: 'rgba(255, 255, 255, 0.2)'
    }),
    stroke: new ol.style.Stroke({
      color: '#ffcc33',
      width: 2
    }),
    image: new ol.style.Circle({
      radius: 7,
      fill: new ol.style.Fill({
        color: '#ffcc33'
      })
    })
  })
});
map.addLayer(drawVector);

var modify = new ol.interaction.Modify({source: drawSource});

map.addInteraction(modify);

var draw, snap; // global so we can remove them later

function removeInteractions() {
  map.removeInteraction(draw);
  map.removeInteraction(snap);
}

function addInteractions() {
  draw = new ol.interaction.Draw({
    source: drawSource,
    type: ol.geom.Polygon
  });
  map.addInteraction(draw);
  snap = new ol.interaction.Snap({source: drawSource});
  map.addInteraction(snap);
}
  draw = new ol.interaction.Draw({
    source: drawSource,
    type: 'Polygon'
  });