Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions src/js/ol3-map-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@
};
}

if (options.style.zIndex == null) {
options.style.zIndex = 0;
}

let style = new ol.style.Style({
image: options.image,
stroke: new ol.style.Stroke({
Expand All @@ -133,7 +137,8 @@
}),
fill: new ol.style.Fill({
color: fill.color
})
}),
zIndex: options.style.zIndex
});

return (feature, resolution) => {
Expand Down Expand Up @@ -286,9 +291,12 @@
hitTolerance: 2
}
);
features.sort((a, b) => {
return b.get('index') - a.get('index');
});

// Normalize return value, undefined should be treated as null
if (features.length > 1) {
if (features.length > 1 && (features[0].get('index') == features[1].get('index'))) {
if (this.selected_feature != null && features.indexOf(this.selected_feature) !== -1) {
unselect.call(this, this.selected_feature);
update_selected_feature.call(this, null);
Expand All @@ -298,7 +306,7 @@
popup_menu.append(new StyledElements.MenuItem(feature.get('title'), null, feature));
});
popup_menu.addEventListener("click", (menu, item) => {
this.select_feature(item.context);
this.centerPoI([item.context]);
});
setTimeout(function () {
popup_menu.show({
Expand All @@ -315,14 +323,10 @@

var feature = features[0];

if (feature != null && feature !== this.selected_feature) {
this.select_feature(feature);
} else if (this.selected_feature != null && this.selected_feature.get('content') == null) {
unselect.call(this, this.selected_feature);
update_selected_feature.call(this, null);
} else if (feature !== this.selected_feature && this.popover != null) {
this.popover.hide();
update_selected_feature.call(this, null);
if (feature == null) {
this.centerPoI([]);
} else {
this.centerPoI([feature]);
}
}.bind(this));

Expand Down Expand Up @@ -382,7 +386,8 @@
iconFeature = new ol.Feature({
geometry: geometry,
point: marker || geometry,
data: poi_info,
data: poi_info || 0,
index: poi_info.style != null ? poi_info.style.zIndex : 0,
title: poi_info.title,
content: poi_info.infoWindow,
// PoI are selectable by default
Expand All @@ -395,7 +400,8 @@
iconFeature.setProperties({
geometry: geometry,
point: marker || geometry,
data: poi_info,
data: poi_info || 0,
index: poi_info.style != null ? poi_info.style.zIndex : 0,
title: poi_info.title,
content: poi_info.infoWindow,
// PoI are selectable by default
Expand Down Expand Up @@ -448,7 +454,7 @@
}

let geometry = new ol.geom.GeometryCollection(poi_info.map((poi) => {
var feature = this.vector_source.getFeatureById(poi.id);
var feature = poi instanceof ol.Feature ? poi : this.vector_source.getFeatureById(poi.id);
return feature.getGeometry();
}));

Expand Down Expand Up @@ -478,7 +484,7 @@
}

if (poi_info.length == 1) {
this.select_feature(this.vector_source.getFeatureById(poi_info[0].id));
this.select_feature(poi_info[0] instanceof ol.Feature ? poi_info[0] : this.vector_source.getFeatureById(poi_info[0].id));
}
};

Expand Down