forked from Snck3rs/contao-leaflet-maps
Refactor popup handling
This commit is contained in:
@@ -104,32 +104,37 @@ L.Contao = L.Class.extend( {
|
|||||||
pointToLayer: function(feature, latlng) {
|
pointToLayer: function(feature, latlng) {
|
||||||
var marker = L.marker(latlng, feature.properties.options);
|
var marker = L.marker(latlng, feature.properties.options);
|
||||||
|
|
||||||
if (feature.properties && feature.properties.icon) {
|
if (feature.properties) {
|
||||||
var icon = this.getIcon(feature.properties.icon);
|
if (feature.properties.icon) {
|
||||||
|
var icon = this.getIcon(feature.properties.icon);
|
||||||
|
|
||||||
if (icon) {
|
if (icon) {
|
||||||
marker.setIcon(icon);
|
marker.setIcon(icon);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.bindPopupFromFeature(marker, feature);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.applyFeatureMethods(marker, feature);
|
|
||||||
this.fire('marker:created', { marker: marker, feature: feature, latlng: latlng });
|
this.fire('marker:created', { marker: marker, feature: feature, latlng: latlng });
|
||||||
|
|
||||||
return marker;
|
return marker;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply feature methods.
|
* Bind popup from feature definitions.
|
||||||
*
|
*
|
||||||
* @param obj
|
* It accepts popup or popupContent as property.
|
||||||
* @param feature
|
*
|
||||||
|
* @param obj The object
|
||||||
|
* @param feature The geo json feature.
|
||||||
*/
|
*/
|
||||||
applyFeatureMethods: function(obj, feature) {
|
bindPopupFromFeature: function (obj, feature) {
|
||||||
if (feature.properties && feature.properties.methods) {
|
if (feature.properties) {
|
||||||
for (var i=0; i < feature.properties.methods.length; i++) {
|
if (feature.properties.popup) {
|
||||||
var method = feature.properties.methods[i];
|
obj.bindPopup(feature.properties.popup);
|
||||||
|
} else if (feature.properties.popupContent) {
|
||||||
obj[method[0]].apply(obj, method[1]);
|
obj.bindPopup(feature.properties.popupContent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user