How can I change the center point and zoom factor of the "navbar"? - leaflet

When changing map layer (addoverlay) I change the setView, however, the Home button of the "navbar" does not change with it. If I press it on a different map layer than the first (default overlay), the value of the first map layer is used when using the home button.
First (default) overlay = "ReizenL".
var map = L.map('map', {
messagebox: true,
fullscreenControl: true,
layers: [Esri_NatGeo, ReizenL],
minZoom: 3,
maxZoom: 20,
center: [<?php printf($XcoorL) ?>,<?php printf($YcoorL) ?>],
zoom: 3,
});
Navbar code:
var navbar = L.control.navbar({
center: [<?php printf($XcoorL) ?>,<?php printf($YcoorL) ?>],
zoom: 3,
}).addTo(map);
Addoverlay code:
map.on('overlayadd', function(e) {
// alert(e.layer._leaflet_id);
switch (e.layer._leaflet_id){
case 181:
map.setView([<?php printf($XcoorL) ?>,<?php printf($YcoorL) ?>], 3);
break;
case 196:
// map.setView([48.01932, 5.36133], 5);
map.setView([<?php printf($XcoorS) ?>,<?php printf($YcoorS) ?>], 5);
break;
case 197:
//map.setView([52.30512, 4.77081], 9);
map.setView([<?php printf($XcoorH) ?>,<?php printf($YcoorH) ?>], 9);
break;
case 198:
//map.setView([50.80593, 4.68567], 8);
map.setView([<?php printf($XcoorW) ?>,<?php printf($YcoorW) ?>], 8);
break;
}
});
I change the code for map.setView while de Leaflet_id is not trustworthy:
map.on('overlayadd', function(e) {
// alert(e.name);
switch (e.name){
case "<?php printf($legend02) ?>":
map.setView([<?php printf($XcoorL) ?>,<?php printf($YcoorL) ?>], 3);
break;
case "<?php printf($legend03) ?>":
// map.setView([48.01932, 5.36133], 5);
map.setView([<?php printf($XcoorS) ?>,<?php printf($YcoorS) ?>], 5);
break;
case "<?php printf($legend04) ?>":
//map.setView([52.30512, 4.77081], 9);
map.setView([<?php printf($XcoorH) ?>,<?php printf($YcoorH) ?>], 9);
break;
case "<?php printf($legend05) ?>":
//map.setView([50.80593, 4.68567], 8);
map.setView([<?php printf($XcoorW) ?>,<?php printf($YcoorW) ?>], 8);
break;
}
});
Every time I click on a map layer and the value "e" is requested in the function: "map.on('overlayadd', function(e) {" the coordinates are adjusted with "map.setView" in addition the coordinates must also be and the zoom factor in "L.control.navbar" can be adjusted.
I used php while the names are different in the possible three languages.
Link to the map

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.
};

Zooming into leaflet map on entering fullscreen mode

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);
});

Removing stop words from single string

My query is string = 'Alligator in water' where in is a stop word. How can I remove it so that I get stop_remove = 'Alligator water' as output. I have tried it with ismember but it returns integer value for matching word, I want to get the remaining words as output.
in is just an example, I'd like to remove all possible stop words.
A slightly more elegant way than Luis Mendo's solution is to use regexprep that does exactly what you want
>> result = regexprep( 'Alligator in water', 'in\s*', '' ); % replace with an empty string
result =
Alligator water
If you have several stop words you can simply add them to the pattern (in this example I consider 'in' and 'near' as stop words):
>> result = regexprep( 'Alligator in water near land', {'in\s*','near\s*'}, '' )
result =
Alligator water land
Use this for removing all stop-words.
Code
% Source of stopwords- http://norm.al/2009/04/14/list-of-english-stop-words/
stopwords_cellstring={'a', 'about', 'above', 'above', 'across', 'after', ...
'afterwards', 'again', 'against', 'all', 'almost', 'alone', 'along', ...
'already', 'also','although','always','am','among', 'amongst', 'amoungst', ...
'amount', 'an', 'and', 'another', 'any','anyhow','anyone','anything','anyway', ...
'anywhere', 'are', 'around', 'as', 'at', 'back','be','became', 'because','become',...
'becomes', 'becoming', 'been', 'before', 'beforehand', 'behind', 'being', 'below',...
'beside', 'besides', 'between', 'beyond', 'bill', 'both', 'bottom','but', 'by',...
'call', 'can', 'cannot', 'cant', 'co', 'con', 'could', 'couldnt', 'cry', 'de',...
'describe', 'detail', 'do', 'done', 'down', 'due', 'during', 'each', 'eg', 'eight',...
'either', 'eleven','else', 'elsewhere', 'empty', 'enough', 'etc', 'even', 'ever', ...
'every', 'everyone', 'everything', 'everywhere', 'except', 'few', 'fifteen', 'fify',...
'fill', 'find', 'fire', 'first', 'five', 'for', 'former', 'formerly', 'forty', 'found',...
'four', 'from', 'front', 'full', 'further', 'get', 'give', 'go', 'had', 'has', 'hasnt',...
'have', 'he', 'hence', 'her', 'here', 'hereafter', 'hereby', 'herein', 'hereupon', ...
'hers', 'herself', 'him', 'himself', 'his', 'how', 'however', 'hundred', 'ie', 'if',...
'in', 'inc', 'indeed', 'interest', 'into', 'is', 'it', 'its', 'itself', 'keep', 'last',...
'latter', 'latterly', 'least', 'less', 'ltd', 'made', 'many', 'may', 'me', 'meanwhile',...
'might', 'mill', 'mine', 'more', 'moreover', 'most', 'mostly', 'move', 'much', 'must',...
'my', 'myself', 'name', 'namely', 'neither', 'never', 'nevertheless', 'next', 'nine',...
'no', 'nobody', 'none', 'noone', 'nor', 'not', 'nothing', 'now', 'nowhere', 'of', 'off',...
'often', 'on', 'once', 'one', 'only', 'onto', 'or', 'other', 'others', 'otherwise',...
'our', 'ours', 'ourselves', 'out', 'over', 'own','part', 'per', 'perhaps', 'please',...
'put', 'rather', 're', 'same', 'see', 'seem', 'seemed', 'seeming', 'seems', 'serious',...
'several', 'she', 'should', 'show', 'side', 'since', 'sincere', 'six', 'sixty', 'so',...
'some', 'somehow', 'someone', 'something', 'sometime', 'sometimes', 'somewhere', ...
'still', 'such', 'system', 'take', 'ten', 'than', 'that', 'the', 'their', 'them',...
'themselves', 'then', 'thence', 'there', 'thereafter', 'thereby', 'therefore', ...
'therein', 'thereupon', 'these', 'they', 'thickv', 'thin', 'third', 'this', 'those',...
'though', 'three', 'through', 'throughout', 'thru', 'thus', 'to', 'together', 'too',...
'top', 'toward', 'towards', 'twelve', 'twenty', 'two', 'un', 'under', 'until', 'up',...
'upon', 'us', 'very', 'via', 'was', 'we', 'well', 'were', 'what', 'whatever', 'when',...
'whence', 'whenever', 'where', 'whereafter', 'whereas', 'whereby', 'wherein',...
'whereupon', 'wherever', 'whether', 'which', 'while', 'whither', 'who', 'whoever',...
'whole', 'whom', 'whose', 'why', 'will', 'with', 'within', 'without', 'would', 'yet',...
'you', 'your', 'yours', 'yourself', 'yourselves', 'the'};
str1 = 'Alligator in water of the pool'
split1 = regexp(str1,'\s','Split');
out_str1 = strjoin(split1(~ismember(split1,stopwords_cellstring)),' ')
Output
str1 =
Alligator in water of the pool
out_str1 =
Alligator water pool
NOTE: This code uses strjoin from Mathworks File-exchange.
Use regexp:
string = 'Alligator in water'; %// data string
result = regexp(string, 'in\s*', 'split'); %// split according to stop word
result = [result{:}]; %// join remaining pieces

How to position ncurses widgets in Perl

Code:
#!/usr/bin/perl -w
use strict;
use Curses::UI;
my $cui = new Curses::UI( -color_support => 1 );
my $win = $cui->add(
'win', 'Window',
-border => 1,
-y => 1,
-bfg => 'red',
);
my $listbox = $win->add(
'mylistbox', 'Listbox',
-values => [1, 2, 3],
-labels => { 1 => 'One',
2 => 'Two',
3 => 'Three' },
-radio => 1,
-height => 15,
);
my $buttons = $win->add(
'mybuttons', 'Buttonbox',
-buttons => [
{
-label => '< Ok >',
-value => 1,
-onpress => sub { die "Do not press this button!\n"; },
}
],
);
$listbox->focus();
$cui->mainloop();
Output after I run the program and click <tab>:
As you see the button was put behind the listbox. How can I put the button below the listbox, centering it horizontally, like this:
And what are the methods to position the ncurses widgets horizontally and vertically in Perl, related to the other widgets?
use strict;
use Curses::UI;
my $cui = new Curses::UI( -color_support => 1 );
my $win = $cui->add(
'win', 'Window',
-border => 0,
-y => 1,
-bfg => 'red',
);
my $listbox = $win->add(
'mylistbox', 'Listbox',
-values => [1, 2, 3],
-labels => { 1 => 'One',
2 => 'Two',
3 => 'Three' },
-radio => 1,
-border =>1,
-height => 5,
);
my $buttons = $win->add(
'mybuttons', 'Buttonbox',
-buttons => [
{
-label => '< Ok >',
-value => 1,
-onpress => sub { die "Do not press this button!\n"; },
}
],
-y => ($win->height-$listbox->height)/2+$listbox->height,
-width =>8,
-border=>1,
-x=>$win->width/2-4
);
$listbox->focus();
$cui->set_binding( sub {exit 0;}, "q");
$cui->mainloop();

Has anyone used the Wx::GridBagSizer layout manager in Wx Perl?

The very sparse wxPerl documentation that I have been able to find says it is supported and sure enough, I can create an instance of it.
my $layout = new Wx::GridBagSizer(5,5);
But I cannot make it work. Specifically, I cannot add a widget to $layout. Anyone done this?
And while I am on the subject, has anyone found any GOOD documentation for wxPerl?
First, checkout Wx::Demo for examples of just about every class.
You should add widgets using its Add method.
$sizer->Add($widget, Wx::GBPosition->new($row, $col));
and maybe
$sizer->Add($widget, [ $row, $col ]);
ikegami got me going in the right direction. Wx::Demo was VERY helpful (like widget for PerlTk if anyone is familiar with that tool). But Wx::GridBagSizer is not explicitly discussed so it took some trial and error to finally get there. Here is what I was trying to do:
sub new
{
my( $class, $parent ) = #_;
my $self = $class->SUPER::new
(
undef,
-1,
"Wx::GridBagSizer",
wxDefaultPosition, wxDefaultSize,
wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER|wxMAXIMIZE_BOX
);
my $Grid = Wx::GridBagSizer->new(1,1);
$Grid->Add(Wx::Button->new($self, -1, 'Button 1'), Wx::GBPosition->new(0, 0), Wx::GBSpan->new(1, 1), wxGROW|wxALL, 1);
$Grid->Add(Wx::Button->new($self, -1, 'Button 2'), Wx::GBPosition->new(0, 1), Wx::GBSpan->new(1, 1), wxGROW|wxALL, 1);
$Grid->Add(Wx::Button->new($self, -1, 'Button 3'), Wx::GBPosition->new(1, 0), Wx::GBSpan->new(1, 2), wxGROW|wxALL, 1);
$Grid->Add(Wx::Button->new($self, -1, 'Button 4'), Wx::GBPosition->new(2, 0), Wx::GBSpan->new(2, 1), wxGROW|wxALL, 1);
$Grid->Add(Wx::Button->new($self, -1, 'Button 5'), Wx::GBPosition->new(2, 1), Wx::GBSpan->new(1, 1), wxGROW|wxALL, 1);
$Grid->Add(Wx::Button->new($self, -1, 'Button 6'), Wx::GBPosition->new(3, 1), Wx::GBSpan->new(1, 1), wxGROW|wxALL, 1);
$Grid->AddGrowableRow(1);
$Grid->AddGrowableCol(1);
$self->SetAutoLayout( 1 );
$self->SetSizer( $Grid );
$self->CenterOnScreen(wxBOTH);
return $self;
}