无法在字符串 '' 上创建属性 'fillColor'

新百伦

我使用谷歌地图绘制多边形并具有添加多边形对象的功能

这是多边形的侦听器

drawingManager = new google.maps.drawing.DrawingManager({
  drawingMode: google.maps.drawing.OverlayType.RECTANGLE,
  drawingControlOptions: {
    drawingModes: [
      google.maps.drawing.OverlayType.RECTANGLE,
      google.maps.drawing.OverlayType.POLYGON

    ]
  }
});

drawingManager.addListener('polygoncomplete', function(polygon) {

  currentShape = addPolygonPlace('unsaved', polygon.getPath().getArray(), '');
  polygon.setMap(null);
  drawingManager.setMap();
});

这是添加多边形的功能。

function addPolygonPlace(id, paths, colors) {

  var place = new Polygon(id, paths, colors);
  mapWrapper.addPlace(place);

  place.addEventListener('mouseover', function() {
    placeInfobox.update(place);
    placeInfobox.show();
  });

  place.addEventListener('mouseout', function() {
    placeInfobox.hide();
  });

  place.addEventListener('click', function() {
    if (selectedShape) {
      selectedShape.setEditable(false);
      google.maps.event.trigger(selectedShape, 'edit_end');
    }

    place.setEditable(true);
    selectedShape = place;
  });

  google.maps.event.addListener(place, 'edit_end', function() {
    if (place.id === 'unsaved') {
      return;
    }
    var placeToEdit = getPlaceByDescription(place.id);
    var path = place.googleEntity.getPath().getArray();

    updatePlace(place.id);
  });

  return place;
}

从这一行也可以看出 var place = new Polygon(id, paths, colors);

我使用了带有属性的 Polygon 对象,这是它的代码。

var Polygon = (function() {

  'use strict';

  function Polygon(id, paths, colors) {

    this._visible = true;
    this.id = id;
    this.paths = paths;
    // this.infoboxDescription = infoboxDescription;

    if (colors === undefined || colors === null) {
      colors = {
        fillColor: '#006400',
        strokeColor: '#646464'
      };
    }

    if (colors.fillColor === undefined || colors.fillColor === null) {
      colors.fillColor = '#006400';
    }

    if (colors.strokeColor === undefined || colors.strokeColor === null) {
      colors.strokeColor = '#646464';
    }

    this.googleEntity = new google.maps.Polygon({
      strokeColor: colors.strokeColor,
      fillColor: colors.fillColor,
      paths: paths
    });
  }

  Object.defineProperty(Polygon.prototype, 'visible', {
    get: function() {
      return this._visible || (this._visible = false);
    },
    enumerable: true,
    configurable: true
  });

  Polygon.prototype.remove = function() {
    this.googleEntity.setMap(null);
  }

  Polygon.prototype.addEventListener = function(eventName, callback) {
    this.googleEntity.addListener(eventName, callback.bind(this));
  }

  Polygon.prototype.setEditable = function(editable) {
    this.googleEntity.setEditable(editable);
  }

  return Polygon
})()

但我有错误。在这一行

if (colors.fillColor === undefined || colors.fillColor === null) { colors.fillColor = '#006400'; }

我有这个

无法在 addPolygonPlace (Index.js:1895) 处的新多边形 (Place.js:65) 处的字符串 '' 上创建属性 'fillColor'

我该如何解决?

颠倒先生
"use strict";

var colors = 'string';
colors.fillColor = 'abc';

未捕获的类型错误:无法在字符串 'string' 上创建属性 'fillColor'

"use strict";

var colors = {};
colors.fillColor = 'abc';

没有错误

如果这需要任何评论:您不能在类型为 的变量上创建对象属性string

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

动画fillColor属性

无法处理属性android:fillColor =“ @ android:color / white”

Angular TypeError:无法在字符串''上创建属性

类型错误:无法在字符串 'a' 上创建属性 'style'

TypeError:无法在字符串“ /:id”上创建属性“ next”

通过颜色特征属性设置MGLFillStyleLayer的FillColor

无法使用组件工厂在字符串“ userForm”上创建属性“ validator”

TypeError:无法在setUpControl的字符串“ [email protected]”上创建属性“ validator”

无法在字符串'__zone_symbol__optimizedZoneEventTask'上创建属性'__creationTrace__'

使用gmail的Nodemailer,无法在字符串“ SMTP”上创建属性“ mailer”

无法在字符串“ Information Technology” angularjs上创建“ selected”属性

未被捕获的TypeError:无法在字符串'上创建属性'guid'

未捕获的TypeError:无法在字符串“ wtd_background_image”上创建属性“ style”

收到错误“ TypeError:无法在字符串'control'上创建属性'validator'”

未被捕获的TypeError:无法在字符串“”上创建属性“ empFirstName”

无法从字符串数组创建Set

无法从字符串创建react元素

无法在字符串上创建属性

无法在字符串上创建属性“键”

无法从查询字符串读取params属性?

无法访问原始类型值(字符串)的属性

无法读取未定义的属性子字符串

无法匹配从 Java 中的属性文件获取的字符串

无法读取 null 的属性“子字符串”

C#无法从字符串属性获取char

字符串包含src =“”或id =“”属性时无法$ .parseJSON()

jsp无法将会话属性放入字符串

无法在属性结构中插入来自 json 的字符串

无法解析JSON的字符串属性中存在的XML