Google Maps V3: Infowindows not resizing to fit information - google-maps-api-3

Problem
I have a API V3 map, with a content window for each marker. The content of the infowindow stretches across multiple lines, but the infowindow does not resize to fit it all, causing an iframe-like scroll to appear.
I have looked at the setContent() method in the API which according to some posts on the API V3 mailing list should correct the issue. However, it looks like I've been putting into the wrong place thus causing the map not to load.
Infowindow content is populated from a field in the locations_array.
Map code
Here's the code I'm using, minus the setContent() method.
<script src="/_global/assets/scripts/jquery-1.2.6.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script language="javascript">
$(document).ready(function() {
//Google Maps
var myOptions = {
zoom: 5,
center: new google.maps.LatLng(-26.66, 122.25),
mapTypeControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU },
navigationControl: true,
navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL }
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
// Create an array to hold a series of generic objects
// Each one will represent an individual marker, and contain all the
// information we need for that marker. This way, we can reuse the data
// on the client-side in other scripts as well.
var locations_array = [
{latitude: -35.015672, longitude: 117.879639, title: "Albany", infoWindowContent: "<strong>Albany</strong><br /><br />Get office details"},
{latitude: -33.351479, longitude: 115.666658, title: "Bunbury", infoWindowContent: "<strong>Bunbury</strong><br /><br />Get office details"},
{latitude: -24.850919, longitude: 113.731984, title: "Carnarvon", infoWindowContent: "<strong>Carnarvon</strong><br /><br />Get office details"},
{latitude: -33.361363, longitude: 116.161534, title: "Collie", infoWindowContent: "<strong>Collie</strong><br /><br />Get office details"},
{latitude: -33.847418, longitude: 121.884107, title: "Esperance", infoWindowContent: "<strong>Esperance</strong><br /><br />Get office details"},
{latitude: -31.795396, longitude: 115.88941, title: "Gnangara", infoWindowContent: "<strong>Gnangara</strong><br /><br />Get office details"},
{latitude: -33.082093, longitude: 115.913902, title: "Harvey", infoWindowContent: "<strong>Harvey</strong><br /><br />Get office details"},
{latitude: -33.082093, longitude: 115.913902, title: "Harvey Mill", infoWindowContent: "<strong>Harvey Mill</strong><br /><br />Get office details"},
{latitude: -30.749071, longitude: 121.472324, title: "Kalgoorlie", infoWindowContent: "<strong>Kalgoorlie</strong><br /><br />Get office details"},
{latitude: -33.691176, longitude: 117.557189, title: "Katanning", infoWindowContent: "<strong>Katanning</strong><br /><br />Get office details"},
{latitude: -32.531789, longitude: 115.721341, title: "Mandurah", infoWindowContent: "<strong>Mandurah</strong><br /><br />Get office details"},
{latitude: -34.250365, longitude: 116.147165, title: "Manjimup", infoWindowContent: "<strong>Manjimup</strong><br /><br />Get office details"},
{latitude: -33.982459, longitude: 115.765361, title: "Nannup", infoWindowContent: "<strong>Nannup</strong><br /><br />Get office details"},
{latitude: -31.953472, longitude: 115.914248, title: "Rivervale", infoWindowContent: "<strong>Rivervale</strong><br /><br />Get office details"},
{latitude: -31.948893, longitude: 115.795029, title: "Shenton Park", infoWindowContent: "<strong>Shenton Park</strong><br /><br />Get office details"},
{latitude: -34.214112, longitude: 116.074472, title: "West Manjimup", infoWindowContent: "<strong>West Manjimup</strong><br /><br />Get office details"},
];
// Now let's create some markers
for (var x = 0; x < locations_array.length; x++) {
// Grab an individual park object out of our array
var _park = locations_array[x];
var myLatlng = new google.maps.LatLng(locations_array[x].latitude,locations_array[x].longitude);
var marker = new google.maps.Marker({
map: map,
position: myLatlng,
title: locations_array[x].title,
icon: 'http://google-maps-icons.googlecode.com/files/park.png',
clickable: true,
infocontent: locations_array[x].infoWindowContent
});
google.maps.event.addListener(marker, 'click', function() {
var infowindow = new google.maps.InfoWindow({
content: this.infocontent
});
infowindow.open(map,this);
});
google.maps.event.addListener(marker, 'dblclick', function() {
map.setZoom(16);
});
}
});
</script>

Try putting the html strings of infoWindowContent in a div with a class that has a width set then change:
content: this.infocontent
to be
content: $(this.infocontent)[0]

Related

How to add label to search input in material-table

I'm using material-table version 1.69.2 which is latest now. I want to add a label to the search textfield displayed above the table.
Any help is much appreciated.
<MaterialTable
title=""
columns={[
{ title: "id", field: "CurrencyKey", hidden: true },
{ title: "Currency", field: "CurrencyName" },
{ title: "Currency code", field: "CurrencyCode" },
{ title: "Status", field: "IsDeleted" },
{ title: "Last modified", field: "DateModified" }
]}
data={data.list}
icons={tableIcons}
options={{
pageSize: 50,
pageSizeOptions: [50, 100, 150],
paginationPosition: "both",
searchFieldAlignment: "left",
search: true,
}}
localization={{
toolbar: {
searchPlaceholder: 'Search',
searchAriaLabel: 'Search here'
},
pagination: {
labelRowsSelect: 'Rows per page'
}
}}
/>

Display multiple MapPolygons via ListView and ListModel

I would like to display multiple MapPolygons. To structre it nicely, I would like to define the polygons in a separated file.
After some googling around, I think an approach with ListView and ListModel could work.
So far I tried to define the complete MapPolygon inside the ListElement{}. This produced an error, that a ListElement{} can not contain any nested elements.
So I defiend a viarable path and color in the ListElement{} and tried to delegate those to a MapPolygon.
This produces the error: "ListElement: cannot use script for property value"
The ListView:
ListView {
model: PolygonCoords {}
delegate: MapPolygon {
color: color
path: path
}
}
The ListModel, PolygonCoords.qml:
ListModel{
ListElement{
color: "blue"
path: [ //very big
{latitude: 47.30985701233802, longitude: 8.957498557565305},
{latitude: 48.31223969058969, longitude: 12.959643094792634},
{latitude: 50.31281785500094, longitude: 12.960823612887165},
{latitude: 47.31281654102718, longitude: 8.962966471196324},
{latitude: 47.30862993050194, longitude: 8.963243902017013},
{latitude: 47.30863115391583, longitude: 8.963151349827395},
{latitude: 47.30697209667029, longitude: 8.962058898768426},
{latitude: 47.30985701233802, longitude: 8.957498557565305}
]
}
ListElement {
color: "red"
path: [ //very big
{latitude: 45.30985701233802, longitude: 7.957498557565305},
{latitude: 41.31223969058969, longitude: 11.959643094792634},
{latitude: 54.31281785500094, longitude: 11.960823612887165},
{latitude: 45.31281654102718, longitude: 7.962966471196324},
{latitude: 45.30862993050194, longitude: 7.963243902017013},
{latitude: 45.30863115391583, longitude: 7.963151349827395},
{latitude: 45.30697209667029, longitude: 7.962058898768426},
{latitude: 45.30985701233802, longitude: 7.957498557565305}
]
}
}
How do I have to change my path-Variable that it is not read as a script and
is the ListView even the right approach or is there a better option?
#Update Thanks to #folibis, I got it working with a Repeater as long the path and the repeater are in the same file as the map. Since the file with the map is already huge, I would like to move as much as possible in its own file.
I cannot begin a file with property var points, so I thought of using Item as a wrapper in PolygonCoords.qml:
Item {
property var points: [
{
color: Qt.rgba(0, 80, 128, 0.5),
path: [ //very big
{latitude: 47.30985701233802, longitude: 8.957498557565305},
{latitude: 48.31223969058969, longitude: 12.959643094792634},
{latitude: 50.31281785500094, longitude: 12.960823612887165},
{latitude: 47.31281654102718, longitude: 8.962966471196324},
{latitude: 47.30862993050194, longitude: 8.963243902017013},
{latitude: 47.30863115391583, longitude: 8.963151349827395},
{latitude: 47.30697209667029, longitude: 8.962058898768426},
{latitude: 47.30985701233802, longitude: 8.957498557565305}
]
},
{
color: Qt.rgba(128, 80, 0, 0.5),
path: [ //very big
{latitude: 45.30985701233802, longitude: 7.957498557565305},
{latitude: 41.31223969058969, longitude: 11.959643094792634},
{latitude: 54.31281785500094, longitude: 11.960823612887165},
{latitude: 45.31281654102718, longitude: 7.962966471196324},
{latitude: 45.30862993050194, longitude: 7.963243902017013},
{latitude: 45.30863115391583, longitude: 7.963151349827395},
{latitude: 45.30697209667029, longitude: 7.962058898768426},
{latitude: 45.30985701233802, longitude: 7.957498557565305}
]
}
]
}
And then calling it like this:
Repeater {
model: PolygonCoords.points
MapPolygon {
color: Polygoncoords.points[index].color
border {width: 2; color: "grey"}
path: PolygonCoords.points[index].path
}
}
Here I get no error, but the neither a MapPolygon on the map.
I also tried it with naming the Item with an id and calling it like this:
model: PolygonCoords.ItemID.points
But with this, I got the error: TypeError: Cannot read property points of undefined.
I further tried moving the repeater with the points together in another file and then just calling PolygonCoords. Again, no error and no MapPolygon:
Item {
Repeater {
model: PolygonCoords.points
MapPolygon {
color: Polygoncoords.points[index].color
border {width: 2; color: "grey"}
path: PolygonCoords.points[index].path
}
}
property var points: [
{
color: Qt.rgba(0, 80, 128, 0.5),
path: [ //very big
{latitude: 47.30985701233802, longitude: 8.957498557565305},
{latitude: 48.31223969058969, longitude: 12.959643094792634},
{latitude: 50.31281785500094, longitude: 12.960823612887165},
{latitude: 47.31281654102718, longitude: 8.962966471196324},
{latitude: 47.30862993050194, longitude: 8.963243902017013},
{latitude: 47.30863115391583, longitude: 8.963151349827395},
{latitude: 47.30697209667029, longitude: 8.962058898768426},
{latitude: 47.30985701233802, longitude: 8.957498557565305}
]
},
{
color: Qt.rgba(128, 80, 0, 0.5),
path: [ //very big
{latitude: 45.30985701233802, longitude: 7.957498557565305},
{latitude: 41.31223969058969, longitude: 11.959643094792634},
{latitude: 54.31281785500094, longitude: 11.960823612887165},
{latitude: 45.31281654102718, longitude: 7.962966471196324},
{latitude: 45.30862993050194, longitude: 7.963243902017013},
{latitude: 45.30863115391583, longitude: 7.963151349827395},
{latitude: 45.30697209667029, longitude: 7.962058898768426},
{latitude: 45.30985701233802, longitude: 7.957498557565305}
]
}
]
}
And in the file with the map:
PolygonCoords {}
To make sure, I referenced PolygonCords right, I defined just a MapPolygon in it. This one was properly displayed on the map.
Any idea what I am missing?
Here is example to illustrate idea I was talking about. I've used Repeater instead of ListView since it is more suitable for your purpose I guess. The data array could be stored in a different javascript file.
import QtQuick 2.11
import QtQuick.Controls 2.4
import QtLocation 5.6
import QtPositioning 5.6
ApplicationWindow {
id: mainWindow
width: 800
height: 600
visible: true
property var points: [
{
color: Qt.rgba(0, 80, 128, 0.5),
path: [
{latitude:59.91288302222718, longitude:10.728799819940349},
{latitude:59.91821810440818, longitude:10.737211227411649},
{latitude:59.912323649434825, longitude:10.754119873037723},
{latitude:59.90961270928307, longitude:10.764762878423767},
{latitude:59.90165073245826, longitude:10.759441375730745},
{latitude:59.908364741793115, longitude:10.748540878294307},
{latitude:59.9010050830971, longitude:10.741846084608},
{latitude:59.910387286199025, longitude:10.731632232668204},
]
},
{
color: Qt.rgba(128, 80, 0, 0.5),
path: [
{latitude:59.92101437751683, longitude:10.77077102661346},
{latitude:59.920842305970744, longitude:10.772916793815767},
{latitude:59.9168413910999, longitude:10.772830963132293},
{latitude:59.915206469874626, longitude:10.769741058354015},
{latitude:59.91787393143297, longitude:10.765792846683212},
]
}
]
Map {
id: map
anchors.fill: parent
plugin: Plugin { id: mapPlugin; name: "esri" }
center: QtPositioning.coordinate(59.91, 10.75)
zoomLevel: 14
MouseArea {
anchors.fill: parent
onPressed: {
var coord = map.toCoordinate(Qt.point(mouse.x,mouse.y));
console.log(coord.latitude, coord.longitude);
}
}
Repeater {
model: points
MapPolygon {
color: points[index].color
border{ width: 1; color: "grey" }
path: points[index].path
}
}
}
}

customizing each button in kendo grid

I have a kendo grid with custom buttons at the end of the row. This is done in the following way:
<div class="demo-section k-content" style="float: right">
<button id="textButton" style="margin: 5px;">Open WFR</button>
<button id="textButton_remind" style="margin-left: 5px;">Remind Me</button>
</div>
columns: [
{
field: "WFR", title: "WFR", filterable: {
cell: {
operator: "contains",
suggestionOperator: "contains"
}
}
},
{ field: "Activity", title: "Activity" },
{ field: "Date", title: "Date" },
{ field: "Group", title: "Group" },
{ field: "MoreInfo", title: "More Information", hidden: true },
{ field: "Read", title: "Read", hidden: true },
{ template: '<button id="textButton" style="margin: 5px;">Open WFR</button>', title: 'View Event'}
$("#textButton").kendoButton();
The problem I am having is that, it is only changing the first button in the grid. so if I have 3 rows, only the first button is changing. When I create different IDs and implement them as a kendo button then it works. How can I dynamically assign an id to the <button id="textButton" to create individual buttons ($("#textButton").kendoButton();)
use a class instead of id
{ template: '<button class="textButton" style="margin: 5px;">Open WFR</button>', title: 'View Event'}
and do this instead
$(".textButton").kendoButton();
I suggest you use the dataBound event of your grid to convert them to buttons
$(..).kendoGrid({
dataBound: function(e) {
$('.textButton').kendoButton();
}
});
I do suggest this approach instead cleaner less taking effect on the whole DOM.
here is the dojo and the code https://dojo.telerik.com/EhUNUwOr
<div id="my-grid"></div>
<script>
$('#my-grid').kendoGrid({
columns: [
{
field: 'firstName',
title: 'First Name'
},
{
template: '<button class="grid-text-button">A</button><button class="grid-text-button">B</button>',
title: 'Actions'
}
],
dataSource: [
{
id: 1,
firstName: 'David'
},
{
id: 2,
firstName: 'Chuck'
}
],
dataBound: function(e) {
var $rows = e.sender.items();
$rows.find('.grid-text-button').kendoButton();
}
});
</script>

Fullcalendar jquery not working in wordpress

I am working on Fullcalendar selectable jquery. I need to use it in wordpress. I have created a template file and call the calendar div in template file and include css files "fullcalendar.css" and "fullcalendar.print.css" in header and "moment.min.js" and "fullcalendar.min.js" in footer. It is only showing calendar without any css effect and not working selectable event. Files are included correctly and not showing any javascript error. I am using this fullcalendar script. I have tried to deactivate all plugins.
jQuery(document).ready(function($) {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: '2016-08-05',
theme: true,
selectable: true,
selectHelper: true,
select: function(start, end) {
var title = prompt('Event Title:'); alert(title);
var eventData;
if (title) {
eventData = {
title: title,
start: start,
end: end
};
$('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true
}
$('#calendar').fullCalendar('unselect');
},
editable: true,
eventLimit: true, // allow "more" link when too many events
events: [
{
title: 'All Day Event',
start: '2016-08-09'
},
{
title: 'Long Event',
start: '2016-08-07',
end: '2016-08-15'
},
{
id: 999,
title: 'Repeating Event',
start: '2016-06-09T16:00:00'
},
{
id: 999,
title: 'Repeating Event',
start: '2016-06-16T16:00:00'
},
{
title: 'Conference',
start: '2016-06-11',
end: '2016-06-13'
},
{
title: 'Meeting',
start: '2016-06-12T10:30:00',
end: '2016-06-12T12:30:00'
},
{
title: 'Lunch',
start: '2016-06-12T12:00:00'
},
{
title: 'Meeting',
start: '2016-06-12T14:30:00'
},
{
title: 'Happy Hour',
start: '2016-06-12T17:30:00'
},
{
title: 'Dinner',
start: '2016-06-12T20:00:00'
},
{
title: 'Birthday Party',
start: '2016-06-13T07:00:00'
},
{
title: 'Click for Google',
url: 'http://google.com/',
start: '2016-06-28'
}
]
});
});
My issue has been resolved.I was adding "fullcalendar.print.css" after "fullcalendar.min.css". When i commented "print.css" file then it started working fine.

Google Maps API 3 Directions - Adding trip duration and distance to infoWindow

I'm so close on this one right now, but can't quite get the result I'm looking for. This is an attempt to pull a series of geolocations - along with a title and text. These are then assigned to markers which are populated on a google map. My ultimate goal is to get the distance and duration of travel between each of the markers and the 'map-center' marker (hub if you will) and populate it in the infoWindow when an individual marker is clicked.
So far I've got every aspect of this working EXCEPT getting the distance/duration to populate correctly in the infoWindow. I can successfully populate a div outside of the 'map-canvas' with innerHTML.
If I either try to print an assigned var or change the content of a div within the infoWindow, the function only works on the first click event. After that the infoWindow shows up blank. Here is the working script:
<head>
<meta charset="utf-8" />
<title>Towns Hub</title>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<style>
.wrapper {position:relative;width:500px;height:300px;margin:30px auto;}
#map {width:500px;height:300px;}
.container{position:absolute;bottom:0;left:0;width:100%;z-index:999;}
.trav-det{border:1px solid #000;float:left;padding:7px;font-size:1.5em;background: rgba(255,255,255, .85);}
</style>
</head>
<body>
<div class="wrapper">
<div class="container">
<div class='trav-det' id='distance_road'></div>
<div class='trav-det' id='duration'></div>
</div>
<div id="map"></div>
</div>
<script>
var map;
var arrMarkers = [];
var infowindow = new google.maps.InfoWindow();
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
function mapInit(){
directionsDisplay = new google.maps.DirectionsRenderer({
suppressMarkers: true,
preserveViewport:true
});
var latlng = new google.maps.LatLng(45.18929617,-109.24727440);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"),myOptions);
directionsDisplay.setMap(map);
var marker1 = new google.maps.Marker({
position: new google.maps.LatLng(45.18929617,-109.24727440),
map: map,
title: 'Red Lodge, MT',
icon: 'http://mywebsite.com/images/orange-marker.png'
});
$.getJSON("hub.txt", {}, function(data){
$.each(data.places, function(i, item){
var marker = new google.maps.Marker({
position: new google.maps.LatLng(item.lat, item.lng),
map: map,
title: item.title
});
arrMarkers[i] = marker;
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent("<p><strong>" + item.title + "</strong><br>"+ item.description +"</p>");
calcRoute(this.getPosition());
infowindow.open(map, this);
});
function calcRoute(drive_end) {
var start = new google.maps.LatLng(45.18929617,-109.24727440);
var end = drive_end;
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING,
unitSystem: google.maps.DirectionsUnitSystem.IMPERIAL
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
distance = response.routes[0].legs[0].distance.text;
duration = response.routes[0].legs[0].duration.text;
document.getElementById("distance_road").innerHTML = distance;
document.getElementById("duration").innerHTML = duration;
}
});
}
});
});
}
google.maps.event.addDomListener(window, 'load', mapInit);
</script>
text file:
{"places": [{
"title": "Cooke City, MT",
"description": "TEXT",
"lat": 45.02009497,
"lng": -109.93234595
},
{
"title": "Silver Gate, MT",
"description": "TEXY",
"lat": 45.00687965,
"lng": -109.98979568
},
{
"title": "Absarokee, MT",
"description": "TEXT",
"lat": 45.52004697,
"lng": -109.44136186
},
{
"title": "Billings, MT",
"description": "TEXT",
"lat": 45.78333000,
"lng": -108.50000000
},
{
"title": "Bridger, MT",
"description": "TEXT",
"lat": 45.28568200,
"lng": -108.90821700
},
{
"title": "Cody, WY",
"description": "TEXT",
"lat": 44.52313500,
"lng": -109.07561100
},
{
"title": "Columbus, MT",
"description": "TEXT",
"lat": 45.62617100,
"lng": -109.25712600
},
{
"title": "Gardiner, MT",
"description": "TEXT",
"lat": 45.03049875,
"lng": -110.70471900
},
{
"title": "Nye, MT",
"description": "TEXT",
"lat": 45.43584263,
"lng": -109.80859757
},
{
"title": "Joliet, MT",
"description": "TEXT",
"lat": 45.48287830,
"lng": -108.97241592
}]}
Any ideas about populating the duration/distance in the infoWindow?
Help appreciated!
Thanks,
Sam
ps I apologize for any ugly scripting. I'm learning as I go and appreciate any thoughts on making this script more efficient!
i might be wrong but from looking at your code:
<div class="wrapper">
<div class="container">
<div class='trav-det' id='distance_road'></div>
<div class='trav-det' id='duration'></div>
</div>
</div>
you are poulating divs in the dom with the distance/duration.
assuming the info is appearing in the divs ok...
to get it into the info window you would need to use:
infowindow.setContent(" distance: "+distance+"<br> duration: "+duration+" ")

Resources