mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2026-10-14 22:56:00 +02:00
Support popups.
This commit is contained in:
1 parent
f462a11c1d
commit
cb370f6723
4 files changed
+26
-3
No files matched your search
@@ -1 +1 @@
|
|||||||
L.Contao=L.Class.extend({includes:L.Mixin.Events,statics:{ATTRIBUTION:' | <a href="https://netzmacht.de/contao-leaflet" title="Powered by Leaflet extension for Contao CMS developed by netzmacht David Molineus">netzmacht</a>'},maps:{},icons:{},initialize:function(){L.Icon.Default.imagePath="assets/leaflet/libs/leaflet/images/",this.setGeoJsonListeners(L.GeoJSON)},addMap:function(t,o){return this.maps[t]=o,this.fire("map:added",{id:t,map:o}),this},getMap:function(t){return"undefined"==typeof this.maps[t]?null:this.maps[t]},addIcon:function(t,o){return this.icons[t]=o,this.fire("icon:added",{id:t,icon:o}),this},loadIcons:function(t){for(var o=0;o<t.length;o++){var e=L[t[o].type](t[o].options);this.addIcon(t[o].id,e)}},getIcon:function(t){return"undefined"==typeof this.icons[t]?null:this.icons[t]},load:function(t,o,e,n,i){var s=this.createRequestUrl(t,i),a=omnivore[o](s,e,n);return i&&(L.stamp(a),i.options.dynamicLoad&&"fit"==a.options.boundsMode&&(a.options.requestHash=t,i.on("moveend",a.refreshData,a),i.on("layerremove",function(t){t.layer===a&&i.off("moveend",a.updateBounds,a)})),i.fire("dataloading",{layer:a}),a.on("ready",function(){i.calculateFeatureBounds(a),i.fire("dataload",{layer:a})}),a.on("error",function(){i.fire("dataload",{layer:a})})),a},pointToLayer:function(t,o){var e="marker",n=null;if(t.properties&&(t.properties.bounds=!0,t.properties.type&&(e=t.properties.type),t.properties.arguments&&(n=L[e].apply(L[e],t.properties.arguments),L.Util.setOptions(n,t.properties.options))),null===n&&(n=L[e](o,t.properties.options)),t.properties){if(t.properties.radius&&n.setRadius(t.properties.radius),t.properties.icon){var i=this.getIcon(t.properties.icon);i&&n.setIcon(i)}this.bindPopupFromFeature(n,t)}return this.fire("point:added",{marker:n,feature:t,latlng:o,type:e}),n},onEachFeature:function(t,o){t.properties&&(L.Util.setOptions(o,t.properties.options),this.bindPopupFromFeature(o,t),this.fire("feature:added",{feature:t,layer:o}))},bindPopupFromFeature:function(t,o){o.properties&&(o.properties.popup?t.bindPopup(o.properties.popup,o.properties.popupOptions):o.properties.popupContent&&t.bindPopup(o.properties.popupContent,o.properties.popupOptions))},setGeoJsonListeners:function(t){t&&t.prototype&&(t.prototype.options={pointToLayer:this.pointToLayer.bind(this),onEachFeature:this.onEachFeature.bind(this)})},createRequestUrl:function(t,o){var e,n="leaflet",i=document.location.search.substr(1).split("&");if(t=encodeURIComponent(t),""==i)t=document.location.pathname+"?"+[n,t].join("=");else{for(var s,a=i.length;a--;)if(s=i[a].split("="),s[0]==n){s[1]=t,i[a]=s.join("=");break}a<0&&(i[i.length]=[n,t].join("=")),t=document.location.pathname+"?"+i.join("&")}return o&&o.options.dynamicLoad&&(e=o.getBounds(),t+="&f=bbox&v=",t+=e.getSouth()+","+e.getWest(),t+=","+e.getNorth()+","+e.getEast()),t}}),L.contao=new L.Contao,L.Control.Attribution.addInitHook(function(){this.options.prefix+=L.Contao.ATTRIBUTION}),L.Control.Attribution.include({setPrefix:function(t){return t.indexOf(L.Contao.ATTRIBUTION)===-1&&(t+=L.Contao.ATTRIBUTION),this.options.prefix=t,this._update(),this}}),L.GeoJSON.include({refreshData:function(t){var o=L.geoJson(),e=this;o.on("ready",function(){var t,o=e.getLayers();for(t=0;t<o.length;t++)e.removeLayer(o[t]);for(o=this.getLayers(),t=0;t<o.length;t++)this.removeLayer(o[t]),e.addLayer(o[t])}),omnivore.geojson(L.contao.createRequestUrl(this.options.requestHash,t.target),null,o)}}),L.Map.include({_dynamicBounds:null,calculateFeatureBounds:function(t,o){if(t){if(!this.options.adjustBounds&&!o)return;this._scanForBounds(t)}else this.eachLayer(this._scanForBounds,this);this._dynamicBounds&&this.fitBounds(this._dynamicBounds,this.getBoundsOptions())},getBoundsOptions:function(){return options={},this.options.boundsPadding?options.padding=this.options.boundsPadding:(this.options.boundsPaddingTopLeft&&(options.paddingTopLeft=this.options.boundsPaddingTopLeft),this.options.boundsPaddingBottomRight&&(options.paddingBottomRight=this.options.boundsPaddingBottomRight)),options},_scanForBounds:function(t){var o;!t.feature||t.feature.properties&&t.feature.properties.ignoreForBounds?L.MarkerClusterGroup&&t instanceof L.MarkerClusterGroup&&t.options.boundsMode&&"extend"==t.options.boundsMode?(o=t.getBounds(),o.isValid()&&(this._dynamicBounds?this._dynamicBounds.extend(o):this._dynamicBounds=L.latLngBounds(o.getSouthWest(),o.getNorthEast()))):(!t.options||t.options&&t.options.boundsMode&&!t.options.ignoreForBounds)&&t.eachLayer&&t.eachLayer(this._scanForBounds,this):t.getBounds?(o=t.getBounds(),o.isValid()&&(this._dynamicBounds?this._dynamicBounds.extend(o):this._dynamicBounds=L.latLngBounds(o.getSouthWest(),o.getNorthEast()))):t.getLatLng&&(o=t.getLatLng(),this._dynamicBounds?this._dynamicBounds.extend(o):this._dynamicBounds=L.latLngBounds(o,o))}}),L.LatLngBounds.prototype.toOverpassBBoxString=function(){var t=this._southWest,o=this._northEast;return[t.lat,t.lng,o.lat,o.lng].join(",")},L.OverPassLayer=L.FeatureGroup.exLine truncated
|
L.Contao=L.Class.extend({includes:L.Mixin.Events,statics:{ATTRIBUTION:' | <a href="https://netzmacht.de/contao-leaflet" title="Powered by Leaflet extension for Contao CMS developed by netzmacht David Molineus">netzmacht</a>'},maps:{},icons:{},initialize:function(){L.Icon.Default.imagePath="assets/leaflet/libs/leaflet/images/",this.setGeoJsonListeners(L.GeoJSON)},addMap:function(t,o){return this.maps[t]=o,this.fire("map:added",{id:t,map:o}),this},getMap:function(t){return"undefined"==typeof this.maps[t]?null:this.maps[t]},addIcon:function(t,o){return this.icons[t]=o,this.fire("icon:added",{id:t,icon:o}),this},loadIcons:function(t){for(var o=0;o<t.length;o++){var e=L[t[o].type](t[o].options);this.addIcon(t[o].id,e)}},getIcon:function(t){return"undefined"==typeof this.icons[t]?null:this.icons[t]},load:function(t,o,e,n,i){var s=this.createRequestUrl(t,i),a=omnivore[o](s,e,n);return i&&(L.stamp(a),i.options.dynamicLoad&&"fit"==a.options.boundsMode&&(a.options.requestHash=t,i.on("moveend",a.refreshData,a),i.on("layerremove",function(t){t.layer===a&&i.off("moveend",a.updateBounds,a)})),i.fire("dataloading",{layer:a}),a.on("ready",function(){i.calculateFeatureBounds(a),i.fire("dataload",{layer:a})}),a.on("error",function(){i.fire("dataload",{layer:a})})),a},pointToLayer:function(t,o){var e="marker",n=null;if(t.properties&&(t.properties.bounds=!0,t.properties.type&&(e=t.properties.type),t.properties.arguments&&(n=L[e].apply(L[e],t.properties.arguments),L.Util.setOptions(n,t.properties.options))),null===n&&(n=L[e](o,t.properties.options)),t.properties){if(t.properties.radius&&n.setRadius(t.properties.radius),t.properties.icon){var i=this.getIcon(t.properties.icon);i&&n.setIcon(i)}this.bindPopupFromFeature(n,t)}return this.fire("point:added",{marker:n,feature:t,latlng:o,type:e}),n},onEachFeature:function(t,o){t.properties&&(L.Util.setOptions(o,t.properties.options),this.bindPopupFromFeature(o,t),this.fire("feature:added",{feature:t,layer:o}))},bindPopupFromFeature:function(t,o){o.properties&&(o.properties.popup?t.bindPopup(o.properties.popup,o.properties.popupOptions):o.properties.popupContent&&t.bindPopup(o.properties.popupContent,o.properties.popupOptions))},setGeoJsonListeners:function(t){t&&t.prototype&&(t.prototype.options={pointToLayer:this.pointToLayer.bind(this),onEachFeature:this.onEachFeature.bind(this)})},createRequestUrl:function(t,o){var e,n="leaflet",i=document.location.search.substr(1).split("&");if(t=encodeURIComponent(t),""==i)t=document.location.pathname+"?"+[n,t].join("=");else{for(var s,a=i.length;a--;)if(s=i[a].split("="),s[0]==n){s[1]=t,i[a]=s.join("=");break}a<0&&(i[i.length]=[n,t].join("=")),t=document.location.pathname+"?"+i.join("&")}return o&&o.options.dynamicLoad&&(e=o.getBounds(),t+="&f=bbox&v=",t+=e.getSouth()+","+e.getWest(),t+=","+e.getNorth()+","+e.getEast()),t}}),L.contao=new L.Contao,L.Control.Attribution.addInitHook(function(){this.options.prefix+=L.Contao.ATTRIBUTION}),L.Control.Attribution.include({setPrefix:function(t){return t.indexOf(L.Contao.ATTRIBUTION)===-1&&(t+=L.Contao.ATTRIBUTION),this.options.prefix=t,this._update(),this}}),L.GeoJSON.include({refreshData:function(t){var o=L.geoJson(),e=this;o.on("ready",function(){var t,o=e.getLayers();for(t=0;t<o.length;t++)e.removeLayer(o[t]);for(o=this.getLayers(),t=0;t<o.length;t++)this.removeLayer(o[t]),e.addLayer(o[t])}),omnivore.geojson(L.contao.createRequestUrl(this.options.requestHash,t.target),null,o)}}),L.Map.include({_dynamicBounds:null,calculateFeatureBounds:function(t,o){if(t){if(!this.options.adjustBounds&&!o)return;this._scanForBounds(t)}else this.eachLayer(this._scanForBounds,this);this._dynamicBounds&&this.fitBounds(this._dynamicBounds,this.getBoundsOptions())},getBoundsOptions:function(){return options={},this.options.boundsPadding?options.padding=this.options.boundsPadding:(this.options.boundsPaddingTopLeft&&(options.paddingTopLeft=this.options.boundsPaddingTopLeft),this.options.boundsPaddingBottomRight&&(options.paddingBottomRight=this.options.boundsPaddingBottomRight)),options},_scanForBounds:function(t){var o;!t.feature||t.feature.properties&&t.feature.properties.ignoreForBounds?L.MarkerClusterGroup&&t instanceof L.MarkerClusterGroup&&t.options.boundsMode&&"extend"==t.options.boundsMode?(o=t.getBounds(),o.isValid()&&(this._dynamicBounds?this._dynamicBounds.extend(o):this._dynamicBounds=L.latLngBounds(o.getSouthWest(),o.getNorthEast()))):(!t.options||t.options&&t.options.boundsMode&&!t.options.ignoreForBounds)&&t.eachLayer&&t.eachLayer(this._scanForBounds,this):t.getBounds?(o=t.getBounds(),o.isValid()&&(this._dynamicBounds?this._dynamicBounds.extend(o):this._dynamicBounds=L.latLngBounds(o.getSouthWest(),o.getNorthEast()))):t.getLatLng&&(o=t.getLatLng(),this._dynamicBounds?this._dynamicBounds.extend(o):this._dynamicBounds=L.latLngBounds(o,o))}}),L.LatLngBounds.prototype.toOverpassBBoxString=function(){var t=this._southWest,o=this._northEast;return[t.lat,t.lng,o.lat,o.lng].join(",")},L.OverPassLayer=L.FeatureGroup.exLine truncated
|
||||||
@@ -110,8 +110,10 @@ L.OverPassLayer = L.FeatureGroup.extend({
|
|||||||
if (icon) {
|
if (icon) {
|
||||||
marker.setIcon(icon);
|
marker.setIcon(icon);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
L.contao.bindPopupFromFeature(marker, feature);
|
if (this.options.overpassPopup) {
|
||||||
|
marker.bindPopup(this.options.overpassPopup(feature, marker));
|
||||||
}
|
}
|
||||||
|
|
||||||
this._map.fire('point:added', {marker: marker, feature: feature, latlng: latlng, type: type});
|
this._map.fire('point:added', {marker: marker, feature: feature, latlng: latlng, type: type});
|
||||||
@@ -122,7 +124,9 @@ L.OverPassLayer = L.FeatureGroup.extend({
|
|||||||
if (feature.properties) {
|
if (feature.properties) {
|
||||||
L.Util.setOptions(layer, feature.properties.options);
|
L.Util.setOptions(layer, feature.properties.options);
|
||||||
|
|
||||||
L.contao.bindPopupFromFeature(layer, feature);
|
if (this.options.overpassPopup) {
|
||||||
|
layer.bindPopup(this.options.overpassPopup(feature, layer));
|
||||||
|
}
|
||||||
|
|
||||||
this._map.fire('feature:added', {feature: feature, layer: layer});
|
this._map.fire('feature:added', {feature: feature, layer: layer});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,6 +221,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
|
|||||||
'boundsMode',
|
'boundsMode',
|
||||||
'minZoom',
|
'minZoom',
|
||||||
'overpassEndpoint',
|
'overpassEndpoint',
|
||||||
|
'overpassPopup'
|
||||||
),
|
),
|
||||||
'style' => array(
|
'style' => array(
|
||||||
'amenityIcons'
|
'amenityIcons'
|
||||||
@@ -911,5 +912,19 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
|
|||||||
),
|
),
|
||||||
'sql' => "blob NULL",
|
'sql' => "blob NULL",
|
||||||
),
|
),
|
||||||
|
'overpassPopup' => array
|
||||||
|
(
|
||||||
|
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['overpassPopup'],
|
||||||
|
'exclude' => true,
|
||||||
|
'inputType' => 'textarea',
|
||||||
|
'eval' => array(
|
||||||
|
'preserveTags' => true,
|
||||||
|
'decodeEntities' => true,
|
||||||
|
'allowHtml' => true,
|
||||||
|
'rte' => 'ace|javascript',
|
||||||
|
'tl_class' => 'clr'
|
||||||
|
),
|
||||||
|
'sql' => "mediumtext NULL"
|
||||||
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -77,6 +77,10 @@ class OverpassLayerMapper extends AbstractLayerMapper
|
|||||||
if ($model->onEachFeature) {
|
if ($model->onEachFeature) {
|
||||||
$definition->setOnEachFeature(new Expression($model->onEachFeature));
|
$definition->setOnEachFeature(new Expression($model->onEachFeature));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($model->overpassPopup) {
|
||||||
|
$definition->setOption('overpassPopup', new Expression($model->overpassPopup));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user