Zooming into leaflet map on entering fullscreen mode - leaflet

I have a map with markers and clusters. I used the solution from https://stackoverflow.com/a/16845714/2660362 to adapt the size of the map to the markers/clusters shown. I then combined the tutorial example with the fullscreen functionality. Now it would be very good if the map could be zoomed in when I go fullscreen. There is a function that is called but it does not rezoom the map. Is this possible?
var map = L.map( 'map', {
center: [20.0, 5.0],
//minZoom: 1,
//zoom: 1,
fullscreenControl: true,
fullscreenControlOptions: {
position: 'topleft'
}
})
L.tileLayer( 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap',
subdomains: ['a', 'b', 'c']
}).addTo( map )
var myURL = jQuery( 'script[src$="talks.js"]' ).attr( 'src' ).replace( 'talks.js', '' )
var myIcon = L.icon({
iconUrl: myURL + 'images/pin24.png',
iconRetinaUrl: myURL + 'images/pin48.png',
iconSize: [29, 24],
iconAnchor: [9, 21],
popupAnchor: [0, -14]
})
var markerClusters = L.markerClusterGroup({maxClusterRadius:30});
for ( var i=0; i < markers.length; ++i )
{
var m = L.marker( [markers[i].lat, markers[i].lng], {icon: myIcon} )
.bindPopup( markers[i].name );
markerClusters.addLayer( m );
}
map.addLayer( markerClusters );
//map.fitBounds(markers.getBounds());
var bounds = L.latLngBounds(markers);
map.fitBounds(bounds);
// events are fired when entering or exiting fullscreen.
map.on('enterFullscreen', function(){
console.log('entered fullscreen');
bounds = L.latLngBounds(markers);
map.fitBounds(bounds);
});
map.on('exitFullscreen', function(){
console.log('exited fullscreen');
});

EDIT:
the markers variable in your code is an array and not a a leaflet layergroup, so leaflet can't return bounds.
I've changed the code to follow the cluster bounds and it worked :
map.on('enterFullscreen', function(){
console.log('entered fullscreen');
bounds = markerClusters.getBounds();
map.fitBounds(bounds);
});

Related

google charts - Bar color

How can i change color of bar "BLACK"? Now its green
function drawChart() {
var data = google.visualization.arrayToDataTable([
['MODEL', 'CYAN', 'MAGENTA', 'YELLOW', 'BLACK'],
<?php
while($row = mysqli_fetch_array($exec))
{
echo"['$row[1] - $row[0]', $row[5], $row[4], $row[3], $row[2]],";
}
?>
]);
var options = {
chart: {
title: "Stan tonerów z <?php echo $date ?>",
titleTextStyle:{fontSize:76,},
subtitle: ''
},
bars: 'horizontal' // Required for Material Bar Charts.
};
i tried {role: 'style'} but it dosent work
try the config option for: colors
var options = {
chart: {
title: "Stan tonerów z <?php echo $date ?>",
titleTextStyle:{fontSize:76,},
subtitle: ''
},
colors: ['CYAN', 'MAGENTA', 'YELLOW', 'BLACK'],
bars: 'horizontal' // Required for Material Bar Charts.
};

Yii2 ChartJs throws A non-numeric value encountered error at page

I have installed a 2amigos/yii2-chartjs-widget to my yii2 project via composer and after installing it I am trying to tun the example as shown in the documentation.
<?php
ChartJs::widget([
'type' => 'pie',
'id' => 'structurePie',
'options' => [
'height' => 200,
'width' => 400,
],
'data' => [
'radius' => "90%",
'labels' => ['Label 1', 'Label 2', 'Label 3'], // Your labels
'datasets' => [
[
'data' => ['35.6', '17.5', '46.9'], // Your dataset
'label' => '',
'backgroundColor' => [
'#ADC3FF',
'#FF9A9A',
'rgba(190, 124, 145, 0.8)'
],
'borderColor' => [
'#fff',
'#fff',
'#fff'
],
'borderWidth' => 1,
'hoverBorderColor'=>["#999","#999","#999"],
]
]
],
'clientOptions' => [
'legend' => [
'display' => false,
'position' => 'bottom',
'labels' => [
'fontSize' => 14,
'fontColor' => "#425062",
]
],
'tooltips' => [
'enabled' => true,
'intersect' => true
],
'hover' => [
'mode' => false
],
'maintainAspectRatio' => false,
],
'plugins' =>
new \yii\web\JsExpression('
[{
afterDatasetsDraw: function(chart, easing) {
var ctx = chart.ctx;
chart.data.datasets.forEach(function (dataset, i) {
var meta = chart.getDatasetMeta(i);
if (!meta.hidden) {
meta.data.forEach(function(element, index) {
// Draw the text in black, with the specified font
ctx.fillStyle = rgb(0, 0, 0);
var fontSize = 16;
var fontStyle = normal;
var fontFamily = Helvetica;
ctx.font = Chart.helpers.fontString(fontSize, fontStyle, fontFamily);
// Just naively convert to string for now
var dataString = dataset.data[index].toString()+'%';
// Make sure alignment settings are correct
ctx.textAlign = center;
ctx.textBaseline = middle;
var padding = 5;
var position = element.tooltipPosition();
ctx.fillText(dataString, position.x, position.y - (fontSize / 2) - padding);
});
}
});
}
}]')
])
?>
But when I refresh my page I am getting this error
A non-numeric value encountered
The error occurs at var dataString = dataset.data[index].toString()+'%';
I have been trying to solve this issue but I couldn't find anything
Any help would be highly appreciated.
Its because you are not escaping the quotes correctly you need to escape the single quotes in the statement
var dataString = dataset.data[index].toString()+' % ';
because your outer quotes in the new yii\db\Expression() are using single quotes to wrap the whole javascript, so change the line to
var dataString = dataset.data[index].toString()+\' % \';

Pie chart not showing slice

I create a pie chart using google services. the problem is that i want to show credit and debit in pie chart, but output comes only in one color. Here is my query.
$data = mysqli_query($link, "select SUM(pay_payable) as debit, SUM(pay_paid) as credit from purchasers_payment where p_id = '$pur_id'");
and here is my chart setting.
var data = google.visualization.arrayToDataTable([
['Debit', 'Credit'],
<?php
while($row = mysqli_fetch_array($data))
{
echo "['".$row['debit']."',".$row['credit']."],";
}
?>
]);
var options = {
is3D: true,
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
here is mine code output
enter image description here
and i want output like this:
enter image description here
the data format for a PieChart uses rows for each slice
to get two slices, you need two rows of data...
['Label', 'Value'],
['Debit', 10000],
['Credit', 2000]
see following working snippet...
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
var data = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Debit', 10000],
['Credit', 2000]
]);
var options = {
is3D: true,
height: 300
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="piechart"></div>
try the following php...
var data = google.visualization.arrayToDataTable([
['Label', 'Value'],
<?php
while($row = mysqli_fetch_array($data))
{
echo "['Debit',".$row['debit']."],['Credit',".$row['credit']."],";
}
?>
]);

Appcelerator ScrollView and TableView in a Window

i have a Window and i want to have a ScrollableView in the top and a TableView in the bottom area. How to do that?
I have the following code:
var currentWin = Ti.UI.currentWindow;
var dbdata = [
{ title: '' + man.fieldByName('manufacturer') + '', header: 'Manufacturer' },
{ title: '' + rows.fieldByName('series') + '', header: 'Series' },
{ title: '' + rows.fieldByName('engine') + '', header: 'Engine' },
{ title: '' + rows.fieldByName('horsepower') + '' , header: 'Horsepower' },
{ title: '' + rows.fieldByName('yearfrom') + ' to ' + rows.fieldByName('yearto') + '' , header: 'Year' },
{ title: '' + rows.fieldByName('types') + '' , header: 'Engine Type' }
];
var tableView = Ti.UI.createTableView({
data: dbdata,
top: 156
});
var image1 = Ti.UI.createView({width:320,height:156,backgroundImage:'../images/gallery/bmw3er/image1.jpg'});
var image2 = Ti.UI.createView({width:320,height:156,backgroundImage:'../images/gallery/bmw3er/image2.jpg'});
var image3 = Ti.UI.createView({width:320,height:156,backgroundImage:'../images/gallery/bmw3er/image3.jpg'});
var image4 = Ti.UI.createView({width:320,height:156,backgroundImage:'../images/gallery/bmw3er/image4.jpg'});
var image5 = Ti.UI.createView({width:320,height:156,backgroundImage:'../images/gallery/bmw3er/image5.jpg'});
var image6 = Ti.UI.createView({width:320,height:156,backgroundImage:'../images/gallery/bmw3er/image6.jpg'});
var scrollView = Ti.UI.createScrollableView({
views:[image1,image2,image3,image4,image5,image6],
showPagingControl:true,
clipViews:false,
top:0,
left:30,
right:30,
width:320,
height:156,
opacity:0
});
currentWin.add(tableView);
currentWin.add(scrollView);
But when i use the upper code, only my tableView is shown. When i only use currentWin.add(scrollView) and remove the currentWIn.add(tableView), the scrollView is shown - but never both - why?!?!?
Notice: i have removed the database queries from the code sample!!!
Hope you can help?
Thanks,
Sascha
remove the following parameter opacity: 0 in Ti.UI.createScrollableView function call.
Regards.
Adun

cakePHP + extjs row editor and REST

I've implemented REST routing in cakePHP to properly route REST style requests to the proper methods in my controller.
This is what I've added to my routes.php
Router::mapResources(array('object_fields'));
This properly routes the REST requests to my index/add/edit/delete methods inside my controller.
In my EXTJS grid I am using the row editor with a restful store to achieve CRUD behavior.
Here is the code for my grid
myapp.object_field_grid = Ext.extend(Ext.grid.GridPanel, {
closable: true,
stripeRows: true,
frame: true,
viewConfig: {
forceFit: true
},
editor: new Ext.ux.grid.RowEditor({
saveText: 'Update',
}),
onAdd : function(btn, ev){
var u = new this.store.recordType({
name : '',
type: '',
});
this.editor.stopEditing();
this.store.insert(0, u);
this.editor.startEditing(0);
},
onDelete : function(){
},
initComponent: function() {
var proxy = new Ext.data.HttpProxy({
url: 'object_fields/',
});
var reader = new Ext.data.JsonReader({
totalProperty: 'totalCount',
successProperty: 'success',
idProperty: 'id',
root: 'data',
messageProperty: 'message'
}, [
{name: 'id'},
{name: 'name', allowBlank: false},
{name: 'type', allowBlank: false},
]);
var writer = new Ext.data.JsonWriter({
encode: false,
});
var store = new Ext.data.Store({
baseParams: {id: this.object_id},
id: 'object_fields',
restful: true,
proxy: proxy,
reader: reader,
writer: writer,
});
store.load();
var object_field_columns = [
// {header: "id", width: 250, sortable: true, dataIndex: 'id', editor: new Ext.form.TextField({})},
{header: "name", width: 250, sortable: true, dataIndex: 'name', editor: new Ext.form.TextField({})},
{header: "type", width: 250, sortable: true, dataIndex: 'type', editor: new Ext.form.ComboBox({editable: false, store:['STRING', 'NUMBER']})},
];
var config = {
columns: object_field_columns,
store: store,
plugins: [this.editor],
//autoHeight: true,
height: 200,
tbar: [{
text: 'Add',
iconCls: 'silk-add',
handler: this.onAdd,
scope: this,
}, '-', {
text: 'Delete',
iconCls: 'silk-delete',
handler: this.onDelete,
scope: this,
}, '-'],
}
Ext.apply(this, Ext.apply(this.initialConfig, config));
myapp.object_field_grid.superclass.initComponent.apply(this, arguments);
},
onRender: function() {
this.store.load();
myapp.object_field_grid.superclass.onRender.apply(this, arguments);
}
});
Ext.reg('object_field_grid', myapp.object_field_grid); // register xtype
My GET/POST requests are being properly routed to my index/add methods inside my controller and I am able to easily retrieve the paramaters that I pass it in the request.
My problem is with the update functionality PUT request. The PUT request does get successfully routed to my edit method inside the controller.
This is what the request looks like in firebug
http://server.local/object_fields/20
JSON
data
Object { name="test7777777777", more...}
id
"18"
Source
{"id":"18","data":{"name":"test7777777777","id":"20"}}
Inside my edit method I'm not receiving my array that I passed through the PUT request.
When I dump $this->params inside my edit method this is what is in the array.
([id] => 20
[named] => Array
(
)
[pass] => Array
(
[0] => 20
)
[controller] => object_fields
[action] => edit
[[method]] => PUT
[plugin] =>
[url] => Array
(
[ext] => html
[url] => object_fields/20
)
[form] => Array
(
)
[isAjax] => 1
)
How can I properly receive my array through the PUT request inside my edit method?
UPDATE:
I am able to retrieve my array using the following code inside the edit method
function edit($id){
$this->autoRender = false;
echo 'edit';
$raw = '';
$httpContent = fopen('php://input', 'r');
while ($kb = fread($httpContent, 1024)) {
$raw .= $kb;
}
fclose($httpContent);
$params = array();
parse_str($raw, $params);
print_r($params);
}
The question is now why does cakePHP not do this automaticly?
put this in your app_controller.php:
public function beforeFilter() {
if (
isset($this->RequestHandler) &&
$this->RequestHandler->requestedWith('json') &&
(
$this->RequestHandler->isPost() ||
$this->RequestHandler->isPut()
)
) {
$jsonData = json_decode(utf8_encode(trim(file_get_contents('php://input'))), true);
if (is_array($jsonData)) {
$this->data = $jsonData;
unset($jsonData);
}
}
}