Resize info window of google map V3 - php

I am facing huge problem to solve info window size. I want to show a image block and some text information in info window but after place the content info window size increased i have read some threads but no luck with my code. Can any one help me to sort it out.
// Creating an object literal containing the properties
// we want to pass to the map
var options = {
zoom: 5,
center: new google.maps.LatLng(44.913990, 15.205078),
mapTypeId: google.maps.MapTypeId.ROADMAP ,
};
// Creating the map
var map = new google.maps.Map(document.getElementById("map"), options);
// Creating a LatLngBounds object
var bounds = new google.maps.LatLngBounds();
// Creating an array that will contain the coordinates
// for New York, San Francisco, and Seattle
var content = [];
var places = [];content.push('Some html');
places.push(new google.maps.LatLng(44.913990, 15.205078));
// Creating a variable that will hold
// the InfoWindow object
var infowindow;
// Looping through the places array
for (var i = 0; i < places.length; i++)
{
// Adding the markers
var marker = new google.maps.Marker({
position: places[i],
map: map,
icon: "/themes/garland/images/beach_icon_gmap.png"
// title: "Place number " + i
});
// Wrapping the event listener inside an anonymous function
// that we immediately invoke and passes the variable i to.
(function(i, marker) {
// Creating the event listener. It now has access to the values of
// i and marker as they were during its creation
google.maps.event.addListener(marker, "click", function() {
// Check to see if we already have an InfoWindow
if (!infowindow) {
infowindow = new google.maps.InfoWindow({
maxWidth: 20,
maxheight: 20
});
}
// Setting the content of the InfoWindow
infowindow.setContent(content[i]);
// Tying the InfoWindow to the marker
infowindow.open(map, marker);
});
})(i, marker);
// Extending the bounds object with each LatLng
bounds.extend(places[i]);
}
// Adjusting the map to new bounding box
// map.fitBounds(bounds)
Any help would be greatly appreciated. Thanks in advance.

The first thing I notice in your code: maxWidth is a valid property of the InfoWindowOptionsapi-doc object that is passed to the InfoWindow constructor, but maxheight is not. You won't be able to treat the InfoWindow as a strict or rigid container, although maxWidth will constrain the width. An InfoWindow is always sized to contain whatever content it has been provided. From the API Doc:
The InfoWindow will be sized according to the content. To set an
explicit size for the content, set content to be a HTML element with
that size.
That said, you are able to control the size, display, color, etc. of an InfoWindow by defining a CSS class and applying the styling rules to the content of the window. Taking the CSS approach to the content will pretty much give you complete control over the size of the content, because the InfoWindow just functions as a container for the content. If a CSS rule results in content of the correct size, your InfoWindow will be the correct size.

Related

how to reset the graph/chart after zoomin, pan using chartjs

I recently added zoom-in and pan functionality to my line chart. Now i want to add a reset button or something like that when pressed graph come back to normal position/shape. Currently i am drawing it for dynamic data which get updated every10 seconds.
ThankYou in advance.
Try chartjs-plugin-zoom
First, get the Chart.js instance, and then you can just call the resetZoom function of the instance to reset the zooming and panning.
window.myLine = new Chart(ctx, config);
...
function resetZoom() {
window.myLine.resetZoom();
}
...
<button onclick="resetZoom()">Reset Zoom</button>
The chart.js version I'm using is 2.9.3 and chartjs-plugin-zoom version 0.7.7
See examples:
chartjs-plugin-zoom samples
chartjs zoom and pan on codepen
There are multiple ways to do this:
Try any of these:
1. .clear()
2. .destroy()
myLineChart.destroy();
Then re-initialize the chart:
var ctx = document.getElementById("myChartLine").getContext("2d");
myLineChart = new Chart(ctx).Line(data, options);
delete the element and then reappending a new to the parent container
var resetCanvas = function () {
$('#results-graph').remove(); // this is my <canvas> element
$('#graph-container').append('<canvas id="results-graph"><canvas>');
canvas = document.querySelector('#results-graph');
ctx = canvas.getContext('2d');
ctx.canvas.width = $('#graph').width(); // resize to parent width
ctx.canvas.height = $('#graph').height(); // resize to parent height
var x = canvas.width/2;
var y = canvas.height/2;
ctx.font = '10pt Verdana';
ctx.textAlign = 'center';
ctx.fillText('This text is centered on the canvas', x, y);
};`
.update( )
Calling update() on your Chart instance will re-render the chart with any updated values, allowing you to edit the value of multiple existing points, then render those in one animated render loop.
Also refer:
How to clear a chart from a canvas so that hover events cannot be triggered?
chart.js load totally new data

BING MAP LAYER AND PINS : HOW TO DRAW PINS UP ON POLYGON LAYER?

i having two var as,
map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), {
showMapTypeSelector:false,
showScalebar:false,
enableSearchLogo:false,
showDashboard:true,
credentials:"Aku0L3I-4aBqUL0zUWpJYNIp-vppMK2h",
mapTypeId:Microsoft.Maps.MapTypeId.road,
zoom:4,
center:new Microsoft.Maps.Location(38.3466110000000029,-77.0653559999999942)
});
this Map var used to draw polygon on my bing map.
greenLayer = new ClusteredEntityCollection(map, {
singlePinCallback: createPin,
clusteredPinCallback: createClusteredPin,
clusterPlacementType: 2,
clusteringEnabled: true,
visible: true,
gridSize: 50
});
this greenlayer is used to draw pins on bing map.
while running,
the polygon is up and the pins is down.
i need to draw polygon down and pins up.
how to do greenlayer which comes up in the bing map.
You can change the z-index of ClusteredEntityCollection (as it's supposedly an extension on EntityCollection) with a simple:
greenLayer.setOptions({zIndex: 1000});

Wordpress - use of meta data to get postcode and output a google map

I'm trying to use meta data to get a postcode, so something like:
$property->add_meta_box(
'Property Info',
array(
array(
'name' => 'postcode',
'label' => 'Postcode',
'type' => 'text',
);
)
);
to create a meta box on every post type - property. How do I use this postcode to get a google map to generate on a page dynamically, IF the property has a postcode?
I'll show how I did it but this was a year ago and there is perhaps a more updated, modern answer based on updates to Google Maps / Geocoding. Geocoding being the term for the process of converting a postcode to a Latitude/Longitude. This code was all in my single.php as I was using it to display the map on individual posts, you could do things differently depending on how you've set it up.
I had originally used Yahoo Maps API to geocode a postcode and then use Google Maps for the map as Google Map's geocoding was woefully inaccurate. Yahoo turned their service off, so I changed it to the Google Local Search version of geocoding which was more accurate at the time than Google Maps (this was last year, 2011).
Firs of all make sure you include the scripts to the map API in your <head>
https://developers.google.com/maps/documentation/javascript/tutorial#api_key
and
<body onload="initialize()" onunload="GUnload()">
In your template you access your custom option (assuming it has an id of postcode) like;
<?php $postcode = get_post_meta($post->ID, 'postcode', true); ?>
And then use the following Javscript to geocode the address and generate your map (in #map_canvas).
Here's the JS;
<script type="text/javascript">
var localSearch;
var map;
var icon;
var addressMarkerOptions;
google.load("search", "1");
google.load("maps", "2");
google.setOnLoadCallback(initialize);
function initialize()
{
localSearch = new GlocalSearch();
icon = new GIcon(G_DEFAULT_ICON);
addressMarkerOptions = { icon:icon , draggable: false};
map = new GMap2(document.getElementById("map_canvas"));
map.addControl(new GSmallZoomControl3D ());
var mapControl = new GMapTypeControl();
plotAddress("<?php echo $postcode ?>");
}
/**
* This takes either a postcode or an address string
*
*/
function plotAddress(address)
{
localSearch.setSearchCompleteCallback(null,
function() {
if (localSearch.results[0])
{
var resultLat = localSearch.results[0].lat;
var resultLng = localSearch.results[0].lng;
var point = new GLatLng(resultLat,resultLng);
var marker = new GMarker(point, addressMarkerOptions);
map.setCenter(point, 15, G_HYBRID_MAP);
}
});
localSearch.execute(address + ", UK");
}
</script>
The HTML is as follows;
<div id="streetview">
<div id="map_canvas" style="width: 250px; height: 250px"></div>
</div>

Fire click event on a highchart column drilldown chart on clicking x axis for drill down reports

I want to drill down through column chart in highcharts. I have a 3 level drill down with each having at least 20 x-axis labels.Right now drill down is working for column click. I want to do the same thing on x axis click.
Based on my research i found this probable solution. What I want to achieve can be seen here on clicking x-axis labels.
The function i used to achieve this functionality
function(chart) {
//console.log(chart.xAxis[0].ticks[0]);
$.each(chart.xAxis[0].ticks, function(i, tick) {
tick.label.on('click', function() {
var drilldown = chart.series[0].data[i].drilldown;
if (drilldown) { // drill down
chart.setTitle({
text: drilldown.name
});
setChart(drilldown.name, drilldown.categories, drilldown.data, drilldown.color, drilldown.level , drilldown.ytitle);
} else { // restore
setChart(name, categories, data, null, level , 'Total Agent score');
chart.setTitle({text: "Agent Performance Drill Down Report"});
chart.setTitle(undefined, { text: 'Click the Columns to view Drill Down Reports.' });
}
});
});
}
The problem: It works with most of the x-labels but not all. This can be seen # this fiddle the label drill down does not work at all 3 levels on all labels.
Also, here is the post I made on highchart forum for reference
You are adding the handlers at chart load, some of the axis labels won't be present at that time, hence those labels won't respond to the click event
As a quick (read dirty) fix you can add the same handler that you have for the load to the redraw, so the new labels that are created will bind to it.
You can bind the same function to the redraw (this happens when the x-axis labels are changed too, you can replace with a less frequent event that suits the need too) event, so every time the chart is redrawn you unbind (since I am unsure of the lifetime of the labels in highchart, if an exisiting label is reused for the new drilled down chart, it would be safer to remove) any existing click handler as follows for each tick
$(tick.label.element).unbind('click');
and then add the click handler
var bindAxisClick = function() {
$.each(this.xAxis[0].ticks, function(i, tick) {
$(tick.label.element).unbind('click');
$(tick.label.element).click(function() {
var drilldown = chart.series[0].data[i].drilldown;
if (drilldown) { // drill down
chart.setTitle({
text: drilldown.name
});
setChart(drilldown.name, drilldown.categories, drilldown.data, drilldown.color, drilldown.level, drilldown.ytitle);
} else { // restore
setChart(name, categories, data, null, level, 'Total score');
chart.setTitle({
text: "Drill Down Report"
});
chart.setTitle(undefined, {
text: 'Click the Columns to view Drill Down Reports.'
});
}
});
});
};
Modify the chart options to add the redraw and load handlers
chart :{
...
events: {
redraw: bindAxisClick ,
load:bindAxisClick
},
...
}
Dril down from x-axis labels # jsFiddle

Why a layer was incorrectly reloaded?

I've got a problem that was discribed over there:
how to correctly reload fusion tables layer?
Briefly:
i have a fusion table that changes very often.
And i have a javascript code that allows to visualize location information from database:
Thanks everyone, i've managed to solve this thing. This is the code that works as it should:
var map;
var layer;
function initialize() {
map = new google.maps.Map(document.getElementById('map_canvas'), {
center: new google.maps.LatLng(60,30),
zoom: 9,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
layer = new google.maps.FusionTablesLayer({
query: {
select: 'location',
from: '3415835'
}
});
layer.setMap(map);
refreshMap();
}
function refreshMap(){
layer.setOptions({
query: {
select: 'location',
from: '3415835',
where: "location not equal to" + (-1 * Math.floor(Math.random() * 10000000)).toString()
}
});
setTimeout('refreshMap()',5000);
}
At first t thought that my code is wrong. But after testing i discovered that layer is
being reloaded incorrectly: when new point is added i can see it on one zoom level but on
another level it dissapears. i dnon't know what's causing this: browser is cashing map or
script is wrong or smth else. Can someone help me?

Categories