OpenLayer 功能中属性 "population" 的用途是什么?
What is the purpose of attribute "population" in OpenLayer Features?
在 feature usage example 中,有 2 个属性称为 population
和 rainfall
。
...
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point([0, 0]),
name: 'Null Island',
population: 4000,
rainfall: 500
});
...
这是什么意思?找了一圈也没找到资料。
没有任何意义。 Null Island是一个虚构的特征,定义了一些属性,仅此而已。
这是一个将通用属性添加到您可以在其他地方使用的功能的示例。这个例子并没有让它变得非常明显。在该示例中,您可以添加另一个名为 'numberOfDonkeys' 且值为 20 的 属性,然后您可以在触发弹出窗口的点击事件中使用它。
例子不对,我可以把Feature改成这个
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 属性。
jsFiddle 示例 - https://jsfiddle.net/6vd5gtho/
最终你根本不需要那些属性,你可以摆脱它们,它们只是你可以[=27=的地方的例子] 以这种方式放置您想要重用的属性。
在 feature usage example 中,有 2 个属性称为 population
和 rainfall
。
...
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point([0, 0]),
name: 'Null Island',
population: 4000,
rainfall: 500
});
...
这是什么意思?找了一圈也没找到资料。
没有任何意义。 Null Island是一个虚构的特征,定义了一些属性,仅此而已。
这是一个将通用属性添加到您可以在其他地方使用的功能的示例。这个例子并没有让它变得非常明显。在该示例中,您可以添加另一个名为 'numberOfDonkeys' 且值为 20 的 属性,然后您可以在触发弹出窗口的点击事件中使用它。
例子不对,我可以把Feature改成这个
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 属性。
jsFiddle 示例 - https://jsfiddle.net/6vd5gtho/
最终你根本不需要那些属性,你可以摆脱它们,它们只是你可以[=27=的地方的例子] 以这种方式放置您想要重用的属性。