Hi dear,
I've been trying to implement the ol-ext popup feature into my openlayers test map but I have faced a problem with it. The layer are loaded correctly, even the selection interaction is occurring but the popup don't show up once I select a feature (a country in my example).
The dataset are from the Natural Earth project and Geoserver initial data. I also downloaded the ol-ext.css/ol-ext.js files and linked them to the html. Thanks
Here is that part of the js code :
// GeoJSON layer
var vectorSource = new ol.source.Vector({
url: "asset/ne_110m_admin_0_countries.geojson",
format: new ol.format.GeoJSON(),
});
map.addLayer(
new ol.layer.Vector({
name: "Countries",
source: vectorSource,
})
);
// Select interaction
var select = new ol.interaction.Select({
hitTolerance: 5,
multi: true,
condition: ol.events.condition.singleClick,
});
map.addInteraction(select);
// Select control
var popup = new ol.Overlay.PopupFeature({
popupClass: "default anim",
select: select,
/** /
template: function(f) {
return {
title: function(f) { return f.get('nom')+' ('+f.get('id')+')' },
attributes: {
region: { title: 'Région' },
arrond: 'arrond',
cantons: 'cantons',
communes: 'communes',
pop: 'pop'
}
}
},
//
template: {
title:
// 'nom', // only display the name
function (f) {
return f.get("nom") + " (" + f.get("id") + ")";
},
// [ 'region', 'arrond', 'cantons', 'communes', 'pop' ]
attributes: {
NAME: { title: "NAME" },
TYPE: { title: "TYPE" },
REGION_UN: { title: "CONTINENT" },
//communes: { title: "Communes" },
// with prefix and suffix
// pop: {
// title: "Population", // attribute's title
// before: "", // something to add before
// format: ol.Overlay.PopupFeature.localString(), // format as local string
// after: " hab.", // something to add after
// },
// calculated attribute
// pop2: {
// title: "Population (kHab.)", // attribute's title
// format: function (val, f) {
// return (
// Math.round(parseInt(f.get("pop")) / 100).toLocaleString() +
// " kHab."
// );
// },
// },
/* Using localString with a date * /
'date': {
title: 'Date',
format: ol.Overlay.PopupFeature.localString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })
}
//
},
},
});
map.addOverlay(popup);

Hi dear,
I've been trying to implement the ol-ext popup feature into my openlayers test map but I have faced a problem with it. The layer are loaded correctly, even the selection interaction is occurring but the popup don't show up once I select a feature (a country in my example).
The dataset are from the Natural Earth project and Geoserver initial data. I also downloaded the ol-ext.css/ol-ext.js files and linked them to the html. Thanks
Here is that part of the js code :
// GeoJSON layer
var vectorSource = new ol.source.Vector({
url: "asset/ne_110m_admin_0_countries.geojson",
format: new ol.format.GeoJSON(),
});
map.addLayer(
new ol.layer.Vector({
name: "Countries",
source: vectorSource,
})
);
// Select interaction
var select = new ol.interaction.Select({
hitTolerance: 5,
multi: true,
condition: ol.events.condition.singleClick,
});
map.addInteraction(select);
// Select control
var popup = new ol.Overlay.PopupFeature({
popupClass: "default anim",
select: select,
/** /
template: function(f) {
return {
title: function(f) { return f.get('nom')+' ('+f.get('id')+')' },
attributes: {
region: { title: 'Région' },
arrond: 'arrond',
cantons: 'cantons',
communes: 'communes',
pop: 'pop'
}
}
},
//
template: {
title:
// 'nom', // only display the name
function (f) {
return f.get("nom") + " (" + f.get("id") + ")";
},
// [ 'region', 'arrond', 'cantons', 'communes', 'pop' ]
attributes: {
NAME: { title: "NAME" },
TYPE: { title: "TYPE" },
REGION_UN: { title: "CONTINENT" },
//communes: { title: "Communes" },
// with prefix and suffix
// pop: {
// title: "Population", // attribute's title
// before: "", // something to add before
// format: ol.Overlay.PopupFeature.localString(), // format as local string
// after: " hab.", // something to add after
// },
// calculated attribute
// pop2: {
// title: "Population (kHab.)", // attribute's title
// format: function (val, f) {
// return (
// Math.round(parseInt(f.get("pop")) / 100).toLocaleString() +
// " kHab."
// );
// },
// },
/* Using localString with a date * /
'date': {
title: 'Date',
format: ol.Overlay.PopupFeature.localString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })
}
//
},
},
});
map.addOverlay(popup);