Javascript “属性”的目的是什么;人口“;在OpenLayer功能中?

Javascript “属性”的目的是什么;人口“;在OpenLayer功能中?,javascript,openlayers-3,Javascript,Openlayers 3,在功能用法中,有两个属性称为人口和降雨 ... var iconFeature = new ol.Feature({ geometry: new ol.geom.Point([0, 0]), name: 'Null Island', population: 4000, rainfall: 500 }); ... 这意味着什么?我四处搜索,没有找到任何信息。这没有任何意义。空岛是一个虚构的特性,定义了一些属性,仅此而已。它没有任何意义。空岛是一个虚构的功能,定义了

功能用法中,有两个属性称为
人口
降雨

...
var iconFeature = new ol.Feature({
    geometry: new ol.geom.Point([0, 0]),
    name: 'Null Island',
    population: 4000,
    rainfall: 500
});
...

这意味着什么?我四处搜索,没有找到任何信息。

这没有任何意义。空岛是一个虚构的特性,定义了一些属性,仅此而已。

它没有任何意义。空岛是一个虚构的功能,定义了一些属性,仅此而已。

这是一个向功能添加通用属性的示例,您可以在其他地方使用。这个例子并没有让它变得非常明显。在该示例中,您可以添加另一个名为'numberOfDonkeys'的属性,其值为20,然后您可以在触发弹出窗口的单击事件中使用该属性

例如,我可以将功能更改为此

var iconFeature = new ol.Feature({
  geometry: new ol.geom.Point([0, 0]),
  name: 'Null Island',
  population: 4000,
  rainfall: 500,
  numberOfDonkeys: 20
});
并将映射单击事件更改为此

// display popup on click
map.on('click', function(evt) {
  var feature = map.forEachFeatureAtPixel(evt.pixel,
      function(feature) {
        return feature;
      });
  if (feature) {
    var coordinates = feature.getGeometry().getCoordinates();
    popup.setPosition(coordinates);
    $(element).popover({
      'placement': 'top',
      'html': true,
      'content': feature.get('name') + ' Pop: ' + feature.get('population') + ' Donkeys: ' + feature.get('numberOfDonkeys')
    });
    $(element).popover('show');
  } else {
    $(element).popover('destroy');
  }
});
您将在弹出窗口中看到Population和numberOfDonkeys属性

JSFIDLE示例-


最终你根本不需要这些属性,你可以去掉它们,它们只是一个例子,你可以把你想用这种方式重用的属性放在哪里。

这是一个向功能添加通用属性的例子,你可以在其他地方使用。这个例子并没有让它变得非常明显。在该示例中,您可以添加另一个名为'numberOfDonkeys'的属性,其值为20,然后您可以在触发弹出窗口的单击事件中使用该属性

例如,我可以将功能更改为此

var iconFeature = new ol.Feature({
  geometry: new ol.geom.Point([0, 0]),
  name: 'Null Island',
  population: 4000,
  rainfall: 500,
  numberOfDonkeys: 20
});
并将映射单击事件更改为此

// display popup on click
map.on('click', function(evt) {
  var feature = map.forEachFeatureAtPixel(evt.pixel,
      function(feature) {
        return feature;
      });
  if (feature) {
    var coordinates = feature.getGeometry().getCoordinates();
    popup.setPosition(coordinates);
    $(element).popover({
      'placement': 'top',
      'html': true,
      'content': feature.get('name') + ' Pop: ' + feature.get('population') + ' Donkeys: ' + feature.get('numberOfDonkeys')
    });
    $(element).popover('show');
  } else {
    $(element).popover('destroy');
  }
});
您将在弹出窗口中看到Population和numberOfDonkeys属性

JSFIDLE示例-


最终,你根本不需要这些属性,你可以去掉它们,它们只是你可以用这种方式将想要重用的属性放在哪里的例子。

@panoet我住在那里,我可以确认我们没有4000@panoet我住在那里,我可以确认我们不是4000人