我试图让该层的“ID”为选定的功能,并可能尝试实现这一目标3点或4的方法,但还没有实现它。
添加我的特点是这样的...
angular.forEach(response.FieldList, function (Field, key) {
if (Field.FieldID != "") {
var shape = response.FieldList[key].Shape;
shape = shape.replace('}', ',"id":' + '"' + Field.FieldID + '"' + '}');
var geoJsonObj = {
'type': 'Feature',
'geometry': JSON.parse(shape),
'name': Field.FieldID,
'id': Field.FieldID
}
var vectorSource = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(geoJsonObj)
});
Fields[Field.FieldID] = new ol.layer.Vector({
projection: 'EPSG:4269',
source: vectorSource,
id: Field.FieldID,
name: 'Fields',
style: function (feature, resolution) {
var text = resolution * 100000 < 10 ? response.FieldList[key].Acres : '';
if (text != "") {
styleCache[text] = [new ol.style.Style({
stroke: new ol.style.Stroke({
color: '#319FD3',
width: 1
}),
text: new ol.style.Text({
font: '12px Calibri,sans-serif',
text: text,
fill: new ol.style.Fill({
color: '#000'
}),
stroke: new ol.style.Stroke({
color: '#fff',
width: 3
})
}),
fill: new ol.style.Fill({
color: rcisWebMapUtilities.convertHex(response.FieldList[key].Shade, '0.5')
})
})];
}
else if (text == "") {
styleCache[text] = [new ol.style.Style({
fill: new ol.style.Fill({
color: rcisWebMapUtilities.convertHex(response.FieldList[key].Shade, '0.5')
})
})
]
} return styleCache[text];
}
});
webMapValues.vectorFieldLayer.push(Fields[Field.FieldID])
webMapValues.fieldValues.push({
color: response.FieldList[key].Shade,
plantingName: response.FieldList[key].CropNickName,
acres: response.FieldList[key].Acres,
cropId: response.FieldList[key].CropID,
cropNumber: response.FieldList[key].CropNumber,
fieldID: response.FieldList[key].FiledID,
fieldName: response.FieldList[key].FieldName,
legalDesc: response.FieldList[key].LegalDesc,
policyNum: response.FieldList[key].PolicyNumber
})
var found = $filter('filter')(webMapValues.legend, { plantingName: response.FieldList[key].CropNickName }, true);
if (found == 0) {
webMapValues.legend.push({
color: response.FieldList[key].Shade,
plantingName: response.FieldList[key].CropNickName
})
}
}
});
你可以看到我正在尝试设置在很多地方的“ID” ......即使改变以GeoJSON包括“身份证”,但它似乎得到某种方式丢弃,是不是有当我想用它?
我使用的是map.on“点击”像这样...
map.on('click', function (evt) {
var pixel = map.getEventPixel(evt.originalEvent);
displayFeatureInfo(evt.pixel, evt.coordinate);
//var coordinate = evt.coordinate;
})
这个代码来执行的亮点...
var highlight;
var displayFeatureInfo = function (pixel,coordinate) {
var feature = map.forEachFeatureAtPixel(pixel, function (feature) {
var id = Opelayers magic to get layer id;
return feature;
});
var info = document.getElementById('info');
if (feature) {
info.innerHTML = feature.getId() + ': ' + feature.get('name');
} else {
info.innerHTML = ' ';
}
if (feature !== highlight) {
if (highlight) {
featureOverlay.getSource().removeFeature(highlight);
}
if (feature) {
featureOverlay.getSource().addFeature(feature);
document.getElementById('popup-content').innerHTML = '<p>It is working</p>';
popup.setPosition(coordinate);
}
highlight = feature;
}
};
feature.getId()
和feature.get('name')
返回undefined?
之后我得到的功能,我想获得该层的“ID”它是。 所以可能在此代码...
var feature = map.forEachFeatureAtPixel(pixel, function (feature) {
var id = Opelayers magic to get layer id;
return feature;
});
这可能吗? 任何帮助是极大的赞赏!!