JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://openlayers.org/en/v3.9.0/css/ol.css">
<script src="http://openlayers.org/en/v3.9.0/build/ol-debug.js"></script>
<body onload="init()">
<h3>ol3 geojson get Properties of selectes feature</h3>
<div class="row-fluid">
<div class="span12">
<label>Action type </label>
<select id="type" class="form-control">
<option value="none" selected>None</option>
<option value="singleclick" selected>Single-click</option>
<option value="click">Click</option>
<option value="pointermove">Hover</option>
<option value="altclick">Alt+Click</option>
</select> <span id="status"> 0 selected features</span>
<div id="map" class="map"></div>
</div>
</div>
</body>
JavaScript
var test;
function init() {
var raster = new ol.layer.Tile({
source: new ol.source.MapQuest({
layer: 'sat'
})
});
var vector = new ol.layer.Vector({
source: new ol.source.Vector({
url: 'http://openlayers.org/en/v3.9.0/examples/data/geojson/countries.geojson',
format: new ol.format.GeoJSON()
})
});
var map = new ol.Map({
layers: [vector],
target: 'map',
view: new ol.View({
center: [0, 0],
zoom: 2
})
});
// select interaction working on "singleclick"
var select = new ol.interaction.Select();
var Interaction = function () {
if (select !== null) {
map.addInteraction(select);
select.on('select', function (e) {
e.selected.forEach(function (e) {
// get Feature
console.log(e);
// get Properties
console.log(e.getProperties());
// get one specific Property
console.log(e.get('name'));
});
});
}
};
/**
* onchange callback on the select element.
*/
Interaction();
}