Improve handling of bounds calculation. Layers have to whitelist, vectors/markers can set themselves to ignore.

This commit is contained in:
David Molineus
2015-01-21 18:21:28 +01:00
parent 5d1ccb1d54
commit b3eb4c8e61
12 changed files with 130 additions and 93 deletions

View File

@@ -1 +1 @@
L.Contao=L.Class.extend({includes:L.Mixin.Events,attribution:' | <a href="http://contao-leaflet.netzmacht.de/" title="Leaflet extension for Contao CMS">netzmacht <em>creative</em></a>',maps:{},icons:{},initialize:function(){L.Icon.Default.imagePath="assets/leaflet/libs/leaflet/images",this.setGeoJsonListeners(L.GeoJSON)},addMap:function(t,e){return e.map.attributionControl.setPrefix(e.map.attributionControl.options.prefix+this.attribution),this.maps[t]=e,this.fire("map:added",{id:t,map:e}),this},getMap:function(t){return"undefined"==typeof this.maps[t]?null:this.maps[t]},addIcon:function(t,e){return this.icons[t]=e,this.fire("icon:added",{id:t,icon:e}),this},loadIcons:function(t){for(var e=0;e<t.length;e++){var n=L[t[e].type](t[e].options);this.addIcon(t[e].id,n)}},getIcon:function(t){return"undefined"==typeof this.icons[t]?null:this.icons[t]},load:function(t,e,n,o,i){var s=this.createRequestUrl(t),r=omnivore[e](s,n,o);return i&&(L.stamp(r),i.fire("dataloading",{layer:r}),r.on("ready",function(){i.calculateFeatureBounds(r),i.fire("dataload",{layer:r})}),r.on("error",function(){i.fire("dataload",{layer:r})})),r},pointToLayer:function(t,e){var n="marker",o=null;if(t.properties&&(t.properties.bounds=!0,t.properties.type&&(n=t.properties.type),t.properties.arguments&&(o=L[n].apply(L[n],t.properties.arguments),L.Util.setOptions(o,t.properties.options))),null===o&&(o=L[n](e,t.properties.options)),t.properties){if(t.properties.radius&&o.setRadius(t.properties.radius),t.properties.icon){var i=this.getIcon(t.properties.icon);i&&o.setIcon(i)}this.bindPopupFromFeature(o,t)}return this.fire("point:added",{marker:o,feature:t,latlng:e,type:n}),o},onEachFeature:function(t,e){t.properties&&(L.Util.setOptions(e,t.properties.options),this.bindPopupFromFeature(e,t),this.fire("feature:added",{feature:t,layer:e}))},bindPopupFromFeature:function(t,e){e.properties&&t.bindPopup&&(e.properties.popup?t.bindPopup(e.properties.popup):e.properties.popupContent&&t.bindPopup(e.properties.popupContent))},setGeoJsonListeners:function(t){t&&t.prototype&&(t.prototype.options={pointToLayer:this.pointToLayer.bind(this),onEachFeature:this.onEachFeature.bind(this)})},createRequestUrl:function(t){t=encodeURIComponent(t);var e="leaflet",n=document.location.search.substr(1).split("&");if(""==n)return document.location.pathname+"?"+[e,t].join("=");for(var o,i=n.length;i--;)if(o=n[i].split("="),o[0]==e){o[1]=t,n[i]=o.join("=");break}return 0>i&&(n[n.length]=[e,t].join("=")),document.location.pathname+n.join("&")}}),L.contao=new L.Contao,L.Map.include({_dynamicBounds:null,calculateFeatureBounds:function(t,e){if(t){if(!this.options.adjustBounds&&!e)return;this._scanForBounds(t)}else this.eachLayer(this._scanForBounds,this);this._dynamicBounds&&this.fitBounds(this._dynamicBounds)},_scanForBounds:function(t){var e;t.feature&&t.feature.properties&&t.feature.properties.affectBounds?t.getBounds?(e=t.getBounds(),e.isValid()&&(this._dynamicBounds?this._dynamicBounds.extend(e):this._dynamicBounds=L.latLngBounds(e.getSouthWest(),e.getNorthEast()))):t.getLatLng&&(e=t.getLatLng(),this._dynamicBounds?this._dynamicBounds.extend(e):this._dynamicBounds=L.latLngBounds(e,e)):t.eachLayer&&t.eachLayer(this._scanForBounds,this)}});
L.Contao=L.Class.extend({includes:L.Mixin.Events,attribution:' | <a href="http://contao-leaflet.netzmacht.de/" title="Leaflet extension for Contao CMS">netzmacht <em>creative</em></a>',maps:{},icons:{},initialize:function(){L.Icon.Default.imagePath="assets/leaflet/libs/leaflet/images",this.setGeoJsonListeners(L.GeoJSON)},addMap:function(t,e){return e.map.attributionControl.setPrefix(e.map.attributionControl.options.prefix+this.attribution),this.maps[t]=e,this.fire("map:added",{id:t,map:e}),this},getMap:function(t){return"undefined"==typeof this.maps[t]?null:this.maps[t]},addIcon:function(t,e){return this.icons[t]=e,this.fire("icon:added",{id:t,icon:e}),this},loadIcons:function(t){for(var e=0;e<t.length;e++){var n=L[t[e].type](t[e].options);this.addIcon(t[e].id,n)}},getIcon:function(t){return"undefined"==typeof this.icons[t]?null:this.icons[t]},load:function(t,e,n,o,i){var s=this.createRequestUrl(t),r=omnivore[e](s,n,o);return i&&(L.stamp(r),i.fire("dataloading",{layer:r}),r.on("ready",function(){i.calculateFeatureBounds(r),i.fire("dataload",{layer:r})}),r.on("error",function(){i.fire("dataload",{layer:r})})),r},pointToLayer:function(t,e){var n="marker",o=null;if(t.properties&&(t.properties.bounds=!0,t.properties.type&&(n=t.properties.type),t.properties.arguments&&(o=L[n].apply(L[n],t.properties.arguments),L.Util.setOptions(o,t.properties.options))),null===o&&(o=L[n](e,t.properties.options)),t.properties){if(t.properties.radius&&o.setRadius(t.properties.radius),t.properties.icon){var i=this.getIcon(t.properties.icon);i&&o.setIcon(i)}this.bindPopupFromFeature(o,t)}return this.fire("point:added",{marker:o,feature:t,latlng:e,type:n}),o},onEachFeature:function(t,e){t.properties&&(L.Util.setOptions(e,t.properties.options),this.bindPopupFromFeature(e,t),this.fire("feature:added",{feature:t,layer:e}))},bindPopupFromFeature:function(t,e){e.properties&&(e.properties.popup?t.bindPopup(e.properties.popup):e.properties.popupContent&&t.bindPopup(e.properties.popupContent))},setGeoJsonListeners:function(t){t&&t.prototype&&(t.prototype.options={pointToLayer:this.pointToLayer.bind(this),onEachFeature:this.onEachFeature.bind(this)})},createRequestUrl:function(t){t=encodeURIComponent(t);var e="leaflet",n=document.location.search.substr(1).split("&");if(""==n)return document.location.pathname+"?"+[e,t].join("=");for(var o,i=n.length;i--;)if(o=n[i].split("="),o[0]==e){o[1]=t,n[i]=o.join("=");break}return 0>i&&(n[n.length]=[e,t].join("=")),document.location.pathname+n.join("&")}}),L.contao=new L.Contao,L.Map.include({_dynamicBounds:null,calculateFeatureBounds:function(t,e){if(t){if(!this.options.adjustBounds&&!e)return;this._scanForBounds(t)}else this.eachLayer(this._scanForBounds,this);this._dynamicBounds&&this.fitBounds(this._dynamicBounds)},_scanForBounds:function(t){var e;!t.feature||t.feature.properties&&t.feature.properties.ignoreForBounds?t instanceof L.MarkerClusterGroup&&t.options.affectBounds?(e=t.getBounds(),e.isValid()&&(this._dynamicBounds?this._dynamicBounds.extend(e):this._dynamicBounds=L.latLngBounds(e.getSouthWest(),e.getNorthEast()))):(!t.options||t.options&&t.options.affectBounds)&&t.eachLayer&&t.eachLayer(this._scanForBounds,this):t.getBounds?(e=t.getBounds(),e.isValid()&&(this._dynamicBounds?this._dynamicBounds.extend(e):this._dynamicBounds=L.latLngBounds(e.getSouthWest(),e.getNorthEast()))):t.getLatLng&&(e=t.getLatLng(),this._dynamicBounds?this._dynamicBounds.extend(e):this._dynamicBounds=L.latLngBounds(e,e))}});

View File

@@ -163,6 +163,7 @@ L.Contao = L.Class.extend({
// constructor arguments given, use them.
if (feature.properties.arguments) {
marker = L[type].apply(L[type], feature.properties.arguments);
L.Util.setOptions(marker, feature.properties.options);
}
}

View File

@@ -1,3 +1,4 @@
/**
* Extend map so that it can calculate their bounds depending of the features with the property affectBounds.
*/
@@ -42,7 +43,7 @@ L.Map.include({
_scanForBounds: function(layer) {
var source;
if (layer.feature && layer.feature.properties && layer.feature.properties.affectBounds) {
if (layer.feature && (!layer.feature.properties || !layer.feature.properties.ignoreForBounds)) {
if (layer.getBounds) {
source = layer.getBounds();
@@ -62,7 +63,17 @@ L.Map.include({
this._dynamicBounds = L.latLngBounds(source, source);
}
}
} else if (layer.eachLayer) {
} else if (layer instanceof L.MarkerClusterGroup && layer.options.affectBounds) {
source = layer.getBounds();
if (source.isValid()) {
if (this._dynamicBounds) {
this._dynamicBounds.extend(source);
} else {
this._dynamicBounds = L.latLngBounds(source.getSouthWest(), source.getNorthEast());
}
}
} else if ((!layer.options || (layer.options && layer.options.affectBounds)) && layer.eachLayer) {
layer.eachLayer(this._scanForBounds, this);
}
}

View File

@@ -145,14 +145,15 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
),
'markers extends default' => array(
'+expert' => array('pointToLayer'),
'+active' => array('deferred')
'+active' => array('deferred', 'affectBounds')
),
'group extends default' => array(
'+title' => array('groupType'),
'+active' => array('affectBounds')
),
'vectors extends default' => array(
'+expert' => array('onEachFeature', 'pointToLayer'),
'+active' => array('deferred'),
'+active' => array('deferred', 'affectBounds'),
),
'reference extends default' => array(
'+title' => array('reference', 'standalone')
@@ -173,6 +174,9 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'iconCreateFunction',
'disableDefaultStyle'
),
'+active' => array(
'affectBounds'
)
),
),
@@ -500,5 +504,14 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'eval' => array('tl_class' => 'w50', 'submitOnChange' => false, 'isBoolean' => true),
'sql' => "char(1) NOT NULL default ''"
),
'affectBounds' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['affectBounds'],
'exclude' => true,
'inputType' => 'checkbox',
'default' => false,
'eval' => array('tl_class' => 'w50'),
'sql' => "char(1) NOT NULL default ''"
),
)
);

View File

@@ -116,7 +116,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
'riseOffset',
'customIcon',
),
'active' => array('active', 'affectBounds')
'active' => array('active', 'ignoreForBounds')
),
),
'metasubpalettes' => array(
@@ -286,9 +286,9 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
'eval' => array('maxlength' => 5, 'rgxp' => 'digit', 'tl_class' => 'clr w50', 'nullIfEmpty' => true),
'sql' => "int(5) NULL"
),
'affectBounds' => array
'ignoreForBounds' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['affectBounds'],
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['ignoreForBounds'],
'exclude' => true,
'inputType' => 'checkbox',
'default' => false,

View File

@@ -119,7 +119,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array
'data' => array(),
'popup' => array(':hide','addPopup'),
'config' => array(':hide', 'style', 'className', 'clickable'),
'active' => array('active', 'affectBounds')
'active' => array('active', 'ignoreForBounds')
),
'polyline extends default' => array(
@@ -348,9 +348,9 @@ $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array
),
'sql' => "mediumblob NULL"
),
'affectBounds' => array
'ignoreForBounds' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_vector']['affectBounds'],
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_vector']['ignoreForBounds'],
'exclude' => true,
'inputType' => 'checkbox',
'default' => false,

View File

@@ -76,6 +76,8 @@ $GLOBALS['TL_LANG']['tl_leaflet_layer']['iconCreateFunction'][0] = 'Crea
$GLOBALS['TL_LANG']['tl_leaflet_layer']['iconCreateFunction'][1] = 'Function used to create the cluster icon.';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['disableDefaultStyle'][0] = 'Disable default style';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['disableDefaultStyle'][1] = 'Do not load default marker cluster stylesheets.';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['affectBounds'][0] = 'Affect map bounds';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['affectBounds'][1] = 'If the map support it the marker will be used to affect the initial map bounds.';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes']['layer'][0] = 'Layer group';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes']['layer'][1] = 'Basic layer group. <br> See <a href="http://leafletjs.com/reference.html#layergroup" target="_blank">http://leafletjs.com/reference.html#layergroup</a>';

View File

@@ -20,33 +20,33 @@ $GLOBALS['TL_LANG']['tl_leaflet_marker']['toggle'][1] = 'Toggle marker ID %s act
$GLOBALS['TL_LANG']['tl_leaflet_marker']['icons'][0] = 'Manage icons';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['icons'][1] = 'Manage marker icons.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['title'][0] = 'Title';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['title'][1] = 'Title of the map.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['alias'][0] = 'Alias';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['alias'][1] = 'Alias of the map.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['coordinates'][0] = 'Coordinates';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['coordinates'][1] = 'Coordinates of the marker as comma separated value (Latitude, longitude [, altitude]).';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['tooltip'][0] = 'Tooltip';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['tooltip'][1] = 'Marker tooltip rendered as title attribute.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['alt'][0] = 'Alternative text';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['alt'][1] = 'Text for the alt attribute of the icon image (useful for accessibility).';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['addPopup'][0] = 'Add popup';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['addPopup'][1] = 'Add a popup for the marker';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['popupContent'][0] = 'Popup content';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['popupContent'][1] = 'Content of the popup. Insert tags are replaced.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['clickable'][0] = 'Clickable';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['clickable'][1] = 'If deactivated, the marker will not emit mouse events and will act as a part of the underlying map.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['draggable'][0] = 'Draggable';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['draggable'][1] = 'Whether the marker is draggable with mouse/touch or not.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['keyboard'][0] = 'Keyboard navigation';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['keyboard'][1] = 'Whether the marker can be tabbed to with a keyboard and clicked by pressing enter.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['zIndexOffset'][0] = 'ZIndex offset';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['zIndexOffset'][1] = 'By default, marker images zIndex is set automatically based on its latitude. Use this option if you want to put the marker on top of all others (or below), specifying a high value like 1000 (or high negative value, respectively).';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['customIcon'][0] = 'Custom icon';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['customIcon'][1] = 'Use a custom icon.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['icon'][0] = 'Icon';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['icon'][1] = 'Select a custom icon.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['active'][0] = 'Activate marker';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['active'][1] = 'Only activated markers are rendered on the map.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['affectBounds'][0] = 'Affect map bounds';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['affectBounds'][1] = 'If the map support it the marker will be used to affect the initial map bounds.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['title'][0] = 'Title';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['title'][1] = 'Title of the map.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['alias'][0] = 'Alias';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['alias'][1] = 'Alias of the map.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['coordinates'][0] = 'Coordinates';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['coordinates'][1] = 'Coordinates of the marker as comma separated value (Latitude, longitude [, altitude]).';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['tooltip'][0] = 'Tooltip';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['tooltip'][1] = 'Marker tooltip rendered as title attribute.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['alt'][0] = 'Alternative text';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['alt'][1] = 'Text for the alt attribute of the icon image (useful for accessibility).';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['addPopup'][0] = 'Add popup';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['addPopup'][1] = 'Add a popup for the marker';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['popupContent'][0] = 'Popup content';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['popupContent'][1] = 'Content of the popup. Insert tags are replaced.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['clickable'][0] = 'Clickable';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['clickable'][1] = 'If deactivated, the marker will not emit mouse events and will act as a part of the underlying map.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['draggable'][0] = 'Draggable';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['draggable'][1] = 'Whether the marker is draggable with mouse/touch or not.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['keyboard'][0] = 'Keyboard navigation';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['keyboard'][1] = 'Whether the marker can be tabbed to with a keyboard and clicked by pressing enter.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['zIndexOffset'][0] = 'ZIndex offset';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['zIndexOffset'][1] = 'By default, marker images zIndex is set automatically based on its latitude. Use this option if you want to put the marker on top of all others (or below), specifying a high value like 1000 (or high negative value, respectively).';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['customIcon'][0] = 'Custom icon';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['customIcon'][1] = 'Use a custom icon.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['icon'][0] = 'Icon';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['icon'][1] = 'Select a custom icon.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['active'][0] = 'Activate marker';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['active'][1] = 'Only activated markers are rendered on the map.';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['ignoreForBounds'][0] = 'Ignore for bounds';
$GLOBALS['TL_LANG']['tl_leaflet_marker']['ignoreForBounds'][1] = 'Do not include this item in the bounds calculation.';

View File

@@ -6,52 +6,52 @@ $GLOBALS['TL_LANG']['tl_leaflet_vector']['config_legend'] = 'Configuration';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['data_legend'] = 'Vector data';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['popup_legend'] = 'Popup';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['new'][0] = 'Create vector';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['new'][1] = 'Create new vector';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['edit'][0] = 'Edit vector';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['edit'][1] = 'Edit vector ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['copy'][0] = 'Copy vector';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['copy'][1] = 'Copy vector ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['delete'][0] = 'Delete vector';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['delete'][1] = 'Delete vector ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['show'][0] = 'Show details';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['show'][1] = 'Show vector ID %s details';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['cut'][0] = 'Move vector';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['cut'][1] = 'Move vector ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['toggle'][0] = 'Toggle activation';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['toggle'][1] = 'Toggle vector ID %s activation';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['styles'][0] = 'Manage styles';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['styles'][1] = 'Manage vector styles';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['new'][0] = 'Create vector';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['new'][1] = 'Create new vector';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['edit'][0] = 'Edit vector';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['edit'][1] = 'Edit vector ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['copy'][0] = 'Copy vector';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['copy'][1] = 'Copy vector ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['delete'][0] = 'Delete vector';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['delete'][1] = 'Delete vector ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['show'][0] = 'Show details';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['show'][1] = 'Show vector ID %s details';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['cut'][0] = 'Move vector';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['cut'][1] = 'Move vector ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['toggle'][0] = 'Toggle activation';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['toggle'][1] = 'Toggle vector ID %s activation';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['styles'][0] = 'Manage styles';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['styles'][1] = 'Manage vector styles';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['title'][0] = 'Title';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['title'][1] = 'Title of the vector.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['alias'][0] = 'Alias';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['alias'][1] = 'Alias of the vector.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['type'][0] = 'Type';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['type'][1] = 'Choose the vector type.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['type'][0] = 'Type';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['type'][1] = 'Choose the vector type.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['data'][0] = 'Vector data';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['data'][1] = 'Define each coordinate of the vector on a line. Each line is a comma separated value (latitude, longitude [, altitude]).';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['multiData'][0] = 'Multi data';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['multiData'][1] = 'Define coordinates of each vector in a new textarea.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['addPopup'][0] = 'Add popup';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['addPopup'][1] = 'Add a popup to the vector.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['popupContent'][0] = 'Popup content';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['popupContent'][1] = 'Content of the popup. Insert tags are replaced.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['clickable'][0] = 'Clickable';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['clickable'][1] = 'If deactivated, the vector will not emit mouse events and will act as a part of the underlying map.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['active'][0] = 'Activate vector';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['active'][1] = 'Only activated vector are rendered on the map.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['className'][0] = 'Class name';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['className'][1] = 'Custom class name set on an element.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['coordinates'][0] = 'Coordinates';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['coordinates'][1] = 'Coordinates of the vector as comma separated value (Latitude, longitude [, altitude]).';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['radius'][0] = 'Radius';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['radius'][1] = 'Radius of the element. For a circle its defined in meters, for a circle marker in pixels.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['bounds'][0] = 'Bounds';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['bounds'][1] = 'Each field defines a corner of the bounds as comma separated value (Latitude, longitude [, altitude]).';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['style'][0] = 'Style';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['style'][1] = 'Choose a style. If none defined, the default style of leaflet is used.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['affectBounds'][0] = 'Affect map bounds';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['affectBounds'][1] = 'If the map support it the vector will affect the initial map bounds.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['title'][0] = 'Title';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['title'][1] = 'Title of the vector.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['alias'][0] = 'Alias';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['alias'][1] = 'Alias of the vector.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['type'][0] = 'Type';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['type'][1] = 'Choose the vector type.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['type'][0] = 'Type';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['type'][1] = 'Choose the vector type.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['data'][0] = 'Vector data';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['data'][1] = 'Define each coordinate of the vector on a line. Each line is a comma separated value (latitude, longitude [, altitude]).';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['multiData'][0] = 'Multi data';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['multiData'][1] = 'Define coordinates of each vector in a new textarea.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['addPopup'][0] = 'Add popup';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['addPopup'][1] = 'Add a popup to the vector.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['popupContent'][0] = 'Popup content';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['popupContent'][1] = 'Content of the popup. Insert tags are replaced.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['clickable'][0] = 'Clickable';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['clickable'][1] = 'If deactivated, the vector will not emit mouse events and will act as a part of the underlying map.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['active'][0] = 'Activate vector';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['active'][1] = 'Only activated vector are rendered on the map.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['className'][0] = 'Class name';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['className'][1] = 'Custom class name set on an element.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['coordinates'][0] = 'Coordinates';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['coordinates'][1] = 'Coordinates of the vector as comma separated value (Latitude, longitude [, altitude]).';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['radius'][0] = 'Radius';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['radius'][1] = 'Radius of the element. For a circle its defined in meters, for a circle marker in pixels.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['bounds'][0] = 'Bounds';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['bounds'][1] = 'Each field defines a corner of the bounds as comma separated value (Latitude, longitude [, altitude]).';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['style'][0] = 'Style';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['style'][1] = 'Choose a style. If none defined, the default style of leaflet is used.';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['ignoreForBounds'][0] = 'Ignore for bounds';
$GLOBALS['TL_LANG']['tl_leaflet_vector']['ignoreForBounds'][1] = 'Do not include this item in the bounds calculation.';

View File

@@ -87,6 +87,8 @@ class MarkerClusterLayerMapper extends AbstractLayerMapper
$GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/leaflet-markercluster/MarkerCluster.Default.css||static';
}
$definition->setOption('affectBounds', (bool) $model->affectBounds);
$collection = LayerModel::findBy(
array('pid=?', 'active=1'),
array($model->id),

View File

@@ -66,9 +66,10 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
) {
if ($model->deferred) {
if ($model->pointToLayer) {
if ($model->pointToLayer || $model->affectBounds) {
$layer = new GeoJson($this->getElementId($model, $elementId));
$layer->setPointToLayer(new Expression($model->pointToLayer));
$layer->setOption('affectBounds', (bool) $model->affectBounds);
return array($this->getElementId($model, $elementId), RequestUrl::create($model->id), array(), $layer);
}
@@ -89,6 +90,8 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
LatLngBounds $bounds = null,
Definition $parent = null
) {
$definition->setOption('affectBounds', (bool) $model->affectBounds);
if ($definition instanceof GeoJson) {
$collection = $this->loadMarkerModels($model);
@@ -98,7 +101,7 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
if ($marker instanceof Marker) {
$feature = $marker->toGeoJsonFeature();
$feature->setProperty('affectBounds', ($item->affectBounds));
$feature->setProperty('ignoreForBounds', ($item->ignoreForBounds));
$definition->addData($feature, true);
}

View File

@@ -80,6 +80,10 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
$options['onEachFeature'] = new Expression($model->onEachFeature);
}
if ($model->affectBounds) {
$options['affectBounds'] = (bool) $model->affectBounds;
}
if (!empty($options)) {
$layer = new GeoJson($this->getElementId($model, $elementId));
$layer->setOptions($options);
@@ -105,6 +109,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
) {
if ($definition instanceof GeoJson) {
$collection = $this->loadVectorModels($model);
$definition->setOption('affectBounds', (bool) $model->affectBounds);
if ($collection) {
foreach ($collection as $item) {
@@ -114,7 +119,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
$feature = $vector->toGeoJsonFeature();
if ($feature instanceof Feature) {
$feature->setProperty('affectBounds', (bool) $item->affectBounds);
$feature->setProperty('ignoreForBounds', (bool) $item->ignoreForBounds);
}
$definition->addData($feature, true);
@@ -150,7 +155,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
if ($vector instanceof GeoJsonFeature) {
if ($vector instanceof Feature) {
$vector->setProperty('affectBounds', (bool) $item->affectBounds);
$vector->setProperty('ignoreForBounds', (bool) $item->ignoreForBounds);
}
$feature->addFeature($vector);