1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| var displayFeature = function (pixel) { var features = []; map.forEachFeatureAtPixel(pixel, function (feature, layer) { if (layer.getVisible()) { features.push(feature); } });
var len = features.length; if (len > 1) { for (var i = 0; i < len; i++) { var text = features[i].getProperties().text; var type = features[i].getGeometry().getType(); features[i].setStyle(getSelectedPropertyStyle(type, text)); } } else { var featureArr = map.getLayers().getArray(); var featureArr_len = featureArr.length; for (var j = 0; j < featureArr_len; j++) { if (typeof featureArr[j].setStyle !== 'undefined') { var source = featureArr[j].getSource(); features_by_source = source.getFeatures();
var feature_len = features_by_source.length;
for (var m = 0; m < feature_len; m++) { if (typeof features_by_source[m].getProperties().text === 'undefined') { text = 'none'; } else { var text = features_by_source[m].getProperties().text } var type = features_by_source[m].getGeometry().getType(); features_by_source[m].setStyle(getUnselectedPropertyStyle(type, text)); } } } } };
var getUnselectedPropertyStyle = function (type, text) { var style = null; if (type == 'Circle') { style = new ol.style.Style({ fill: new ol.style.Fill({ color: 'rgba(57,172,106,0.9)', opacity: '0.05' }), text: new ol.style.Text({ font: '14px sans-serif', text: text, textAlign: 'center', rotateWithView: true, fill: new ol.style.Fill({ color: '#FFFFFF' }), stroke: new ol.style.Stroke({ color: '#FFFFFF', width: 1 }) }) }) } if (type == 'MultiPolygon' || type == 'Polygon') { style = new ol.style.Style({ stroke: new ol.style.Stroke({ color: 'rgba(255, 255, 0, 0)', width: 2 }), fill: new ol.style.Fill({ color: 'rgba(255, 255, 0, 0)' }) }) } return style; };
var getSelectedPropertyStyle = function (type, text) { var style = null; if (type == 'Circle') { style = new ol.style.Style({ fill: new ol.style.Fill({ color: 'rgba(228,57,60,0.9)', opacity: '0.05' }), text: new ol.style.Text({ font: '14px sans-serif', text: text, textAlign: 'center', fill: new ol.style.Fill({ color: '#FFFFFF' }), stroke: new ol.style.Stroke({ color: '#FFFFFF', width: 1 }) }) }) } if (type == 'MultiPolygon' || type == 'Polygon') { style = new ol.style.Style({ stroke: new ol.style.Stroke({ color: 'green', width: 2 }), fill: new ol.style.Fill({ color: 'rgba(57,172,106,0.1)' }) }) } return style; };
|