I'm trying to get the features of each MultiPoint-point when i click on a point in my openlayers map (4.6.5). The points shows on the map.
I want to add a pop-up on each feature when i click on the points in my MultiPoint array. Each individual point consists of [LON, LAT, TIME].
In have previously achieved this with a "LineString" geometry. So i wonder if this a problem with "MULTIPOINT" as geometry?
My click function looks like this:
map.on('click', function (evt) {
var pointfeature = map.forEachFeatureAtPixel(evt.pixel, function (feature, vectorLayer) {
if (feature) {
console.log(feature)
var coordinate = evt.coordinate;
var hdms =
ol.coordinate.toStringHDMS(ol.proj.transform(coordinate, 'EPSG:3857',
'EPSG:4326'));
var geometry = feature.getGeometry();
var mypoint = geometry.getClosestPoint(coordinate);
var pointtoshow = point[1];
content.innerHTML = '<p>feature </p>';
overlay.setPosition(coordinate);
}
return feature;
});
});
My geojsonObject looks like this:
var geojsonObject = {
'type': 'FeatureCollection',
'crs': {
'type': 'name',
'properties': {
'name': 'EPSG:3857'
}
},
'features':[
'type': 'Feature',
'geometry': {
'type': 'MultiPoint',
'coordinates':
mycoordinates().map(function (x) {
return ol.proj.transform([x[0], x[1]],
'EPSG:4326', 'EPSG:3857')
})
,
"properties": {
"Time": mycoordinates().map(function (x)
{
return x[2]
})
}
},{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': ol.proj.transform([refpointlon, refpointlat],
'EPSG:4326', 'EPSG:3857')
}]
};
What i get from the console.log(feature) is the following:
Hk {Wa: {…}, qa: {…}, oa: {…}, g: 1, xp: 2, …}
N: {geometry: No}
Wa: {}
a: "geometry"
ab: {change:geometry: Array(1), change: Array(1), propertychange:
Array(1)}
c: undefined
f: null
g: 1
i:
Ch: Hk {Wa: {…}, qa: {…}, oa: {…}, g: 1, xp: 2, …}
Dh: ƒ b(b)
Eh: false
listener: ƒ ()
target: No {Wa: {…}, qa: {…}, oa: {…}, g: 1, xp: 1, …}
type: "change"
__proto__: Object
j: undefined
oa: {change:geometry: Array(1), change: Array(1), propertychange:
Array(1)}
qa: {}
xp: 2
__proto__: Vc
But this does not contain the feature coordinates, and not the feature property: TIME, as spesified in the geojsonobject.
Any suggestions for why i don't get the individual feature-information??
feature.getGeometry()
(which you did there, so I don't know where is the problem actually). And the property can be grabbed withfeature.get('time')
.