我有这个图层
$.getJSON("/g_estados/GetPrediosJson", null, function (data) { var format = new ol.format.WKT(); var feature = new Array(); for (i = 0, len = data.length; i < len; i++) { var fea = format.readFeature(data[i].wkt , { dataProjection: 'EPSG:3857', featureProjection: 'EPSG:3857', id: data[i].clave_catastral_g } ); //fea.attributes if (i < 10) { console.log(fea) } feature.push(fea); } c_estados = new ol.layer.Vector({ name: 'estados', source: new ol.source.Vector({ features: feature }), 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' }) }) }) });
和一些选择这样的选项:
featuresSelect = new ol.Collection();
select = null; // ref to currently selected interaction // select interaction working on "singleclick" var selectSingleClick = new ol.interaction.Select({ features: >featuresSelect }); // select interaction working on "click" var selectClick = new ol.interaction.Select({ condition: ol.events.condition.click, features: featuresSelect }); // select interaction working on "pointermove" var selectPointerMove = new ol.interaction.Select({ condition: ol.events.condition.pointerMove, features: featuresSelect }); var selectAltClick = new ol.interaction.Select({ condition: function (mapBrowserEvent) { return ol.events.condition.click(mapBrowserEvent) && ol.events.condition.altKeyOnly(mapBrowserEvent); } }); var changeInteraction = function () { if (select !== null) { map.removeInteraction(select); } var value = 'singleclick'; if (value == 'singleclick') { select = selectSingleClick; } else if (value == 'click') { select = selectClick; } else { select = null; } if (select !== null) { map.addInteraction(select); select.on('select', function (e) { document.getElementById('status').innerHTML = ' ' > e.target.getFeatures().getLength() + ' selected features (last operation selected ' + >e.selected.length + ' and deselected ' + e.deselected.length + ' >features)'; //document.getElementById('id01').style.display = >'block'; //console.log(e.selected); //console.log(e.target.getFeatures()[0]); console.log(featuresSelect); //console.log(featuresSelect[0]); var features2 = new Array; feature2 = featuresSelect; console.log(features2) for (i = 0, len = featuresSelect.getLength() ; i < len; >i++) { console.log(featuresSelect[i]); } //{
所以在我选择一个功能之后我想知道基于这个id调用其他函数的id,但是我已经被困在这里几个小时了,openlayers的样本和文档都没有得到我的支持。
注意:我不寻求jquery(我不知道)或其他框架,只是纯粹的javascript,html,css。
我正在使用最新版本的openlayers,感谢您的帮助。