How do I show one kml layer when the page is loaded? - google-maps-api-3

I have a page with a google maps that shows several kml files that can be seen when you click on the checkboxes in the legend.
How can I configure the map so that when the page is loaded I see only layer2 as though it had already been clicked?
The source code is:
<script type="text/javascript">
var map;
var layers = [];
function initialize() {
var myLatLng = new google.maps.LatLng(37.18186,-3.58843);
var myOptions = {
zoom: 15,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: false
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var legend = document.getElementById('legend');
map.controls[google.maps.ControlPosition.TOP_RIGHT].push
(document.getElementById('legend'));
var noPoi = [
{
featureType: "poi",
stylers: [
{ visibility: "off" }
]
}
];
map.setOptions({styles: noPoi});
layers [0] = new google.maps.KmlLayer('https://granadainfo.com/googlemaps/kml/L33-2018.kml',
{preserveViewport: true, suppressInfoWindows: false});
layers [1] = new google.maps.KmlLayer('https://granadainfo.com/googlemaps/kml/C31-2018.kml',
{preserveViewport: true, suppressInfoWindows: false});
layers [2] = new google.maps.KmlLayer('https://granadainfo.com/googlemaps/kml/C34-2018.kml',
{preserveViewport: true, suppressInfoWindows: false});
layers [3] = new google.maps.KmlLayer('https://granadainfo.com/googlemaps/kml/C30-2018.kml',
{preserveViewport: true, suppressInfoWindows: false});
for (var i = 0; i < layers.length; i++) {
layers[i].setMap(null);
}
}
function toggleLayer(i) {
if (layers[i].getMap() === null) {
layers[i].setMap(map);
}
else {
layers[i].setMap(null);
}
}
</script>
and the html code is:
<div id="map_canvas"></div>
<div id="legend">
<p>
<input type="checkbox" id="layer0" onClick="toggleLayer(0)"/> Bus 33<br />
<input type="checkbox" id="layer1" onClick="toggleLayer(1)"/> Bus C31<br />
<input type="checkbox" id="layer2" onClick="toggleLayer(2)"/> Bus C34<br />
<input type="checkbox" id="layer3" onClick="toggleLayer(3)"/> Bus C30<br />
</div>

You need to do two things:
set the default checkbox to "checked".
<input type="checkbox" id="layer2" onClick="toggleLayer(2)" checked="checked"/> Bus C34<br />
call the toggleLayer function for the layer you want displayed.
Bus C34
toggleLayer(2);
proof of concept fiddle
code snippet:
var map;
var layers = [];
function initialize() {
var myLatLng = new google.maps.LatLng(37.18186, -3.58843);
var myOptions = {
zoom: 15,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: false
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var legend = document.getElementById('legend');
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(document.getElementById('legend'));
var noPoi = [{
featureType: "poi",
stylers: [{
visibility: "off"
}]
}];
map.setOptions({
styles: noPoi
});
layers[0] = new google.maps.KmlLayer('https://granadainfo.com/googlemaps/kml/L33-2018.kml', {
preserveViewport: true,
suppressInfoWindows: false
});
layers[1] = new google.maps.KmlLayer('https://granadainfo.com/googlemaps/kml/C31-2018.kml', {
preserveViewport: true,
suppressInfoWindows: false
});
layers[2] = new google.maps.KmlLayer('https://granadainfo.com/googlemaps/kml/C34-2018.kml', {
preserveViewport: true,
suppressInfoWindows: false
});
layers[3] = new google.maps.KmlLayer('https://granadainfo.com/googlemaps/kml/C30-2018.kml', {
preserveViewport: true,
suppressInfoWindows: false
});
for (var i = 0; i < layers.length; i++) {
layers[i].setMap(null);
}
toggleLayer(2);
google.maps.event.addListener(layers[2], 'defaultviewport_changed', function() {
map.fitBounds(layers[2].getDefaultViewport())
});
}
function toggleLayer(i) {
if (layers[i].getMap() === null) {
layers[i].setMap(map);
} else {
layers[i].setMap(null);
}
}
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map_canvas {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
<div id="map_canvas"></div>
<div id="legend">
<p>
<input type="checkbox" id="layer0" onClick="toggleLayer(0)" /> Bus 33<br />
<input type="checkbox" id="layer1" onClick="toggleLayer(1)" /> Bus C31<br />
<input type="checkbox" id="layer2" onClick="toggleLayer(2)" checked="checked" /> Bus C34<br />
<input type="checkbox" id="layer3" onClick="toggleLayer(3)" /> Bus C30<br />
</p>
</div>
<!-- Replace the value of the key parameter with your own API key. -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initialize">
</script>

Related

getPath function in google.maps.Circle class

There is no any getPath() function in the google.maps.Circle class. How can I get an approximated path using the getRadius() and getCenter() funcions?
You can use the google.maps.geometry.spherical.computeOffset method to calculate a path for a circular polygon with the same radius and center (requires the geometry library).
function circlePath(circle) {
var numPts = 512;
var path = [];
for (var i = 0; i < numPts; i++) {
path.push(google.maps.geometry.spherical.computeOffset(circle.getCenter(), circle.getRadius(), i * 360 / numPts));
}
return path;
}
code snippet:
var geocoder;
var map;
function circlePath(circle) {
var numPts = 512;
var path = [];
for (var i = 0; i < numPts; i++) {
path.push(google.maps.geometry.spherical.computeOffset(circle.getCenter(), circle.getRadius(), i * 360 / numPts));
}
return path;
}
function initialize() {
var map = new google.maps.Map(
document.getElementById("map_canvas"), {
center: new google.maps.LatLng(37.4419, -122.1419),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var circle = new google.maps.Circle({
map: map,
radius: 1000,
center: map.getCenter(),
fillOpacity: 0.2
});
var polygon = new google.maps.Polygon({
map: map,
paths: [circlePath(circle)],
fillColor: 'red',
fillOpacity: 0.5,
strokeColor: 'red'
});
google.maps.event.addDomListener(document.getElementById('circle'), 'click', function() {
circle.setMap(circle.getMap() == null ? map : null);
});
google.maps.event.addDomListener(document.getElementById('polygon'), 'click', function() {
polygon.setMap(polygon.getMap() == null ? map : null);
});
}
google.maps.event.addDomListener(window, "load", initialize);
html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry&key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
<input type="button" id="circle" value="toggle circle" />
<input type="button" id="polygon" value="toggle polygon" />
<div id="map_canvas"></div>

make markers bounce from a list on google maps

I have a list of places in a text box in Google maps. When a person clicks on one of the places in the text box, I want the corresponding marker of that location in Google Maps to bounce. Any ideas on how I can make this work? Right now I am only able to make the marker bounce when I click on the marker itself.
Here is my code:
var Points = [ {
name: 'Duomo-Cathedral',
lat: 43.7732,
long: 11.2560,
url: 'http://www.google.com'
}, {
name: 'Orsanmichele-Church',
lat: 43.770947,
long: 11.254981,
url: 'http://www.google.com'
}, {
name: 'Ponte Vecchio-Old Bridge',
lat: 43.768350,
long: 11.253323,
url: 'http://www.google.com'
}, {
name: 'Galleria delgi Uffizzi-Art Gallery',
lat: 43.768657,
long: 11.255737,
url: 'http://www.google.com'
}, {
name: 'Santa Croce-Church',
lat: 43.768816,
long: 11.262394,
add1: 'Piazza Santa Croce, 16',
add2: ' Florence, Italy 50122',
phone: '+39 055 246 6105',
url: 'https://www.santacroceopera.it/'
}, {
name: 'Palazzo Vecchio-TownHall',
lat: 43.769670,
long: 11.256075,
url: 'https://www.google.com'
}, {
name: 'Piazza della Signoria-OpenSquare',
lat: 43.769725,
long: 11.255474,
url: 'http://www.google.com/'
}, {
name: 'Santa Maria Novella-Church',
lat: 43.774502,
long: 11.249466,
url: 'https://www.google.com'
}, {
name: 'Santa Maria Novella-TrainStation',
lat: 43.776261,
long: 11.248737,
url: 'https://www.google.com'
}, {
name: 'San Lorenzo- ChurchMarket',
lat: 43.774858,
long: 11.254584,
url: 'http://www.google.com'
}
];
var markersArray = ko.observableArray([]);
Points.forEach(populateMarkersArray);
function populateMarkersArray(element) { //, index, array
markersArray.push(element);
}
// Set up a google map
var mapOptions = {
center: { lat: 43.771341,lng: 11.256875},
zoom: 16
};
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
function initialize() {
Points.forEach(loadMarkers);
var infowindow0 = new google.maps.InfoWindow();
var marker0 = new google.maps.Marker({
map: map,
anchorPoint: new google.maps.Point(0, -29)
});
google.maps.event.addListener(function() {
infowindow0.close();
marker0.setVisible(false);
var place = autocomplete.getPlace();
if (!place.geometry) {
return;
}
// If the place has a geometry, then present it on a map.
marker0.setIcon(/** #type {google.maps.Icon} */({
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(35, 35)
}));
marker0.setPosition(place.geometry.location);
marker0.setVisible(true);
infowindow0.setContent('<div><strong>' + place.name + '</strong><br>' + address);
infowindow0.open(map, marker0);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
function loadMarkers(element) { //, index, array
var myLatlng = new google.maps.LatLng(element.lat,element.long);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: element.name
});
loadInfoWindow(element, marker);
}
function loadInfoWindow(element, marker) {
var contentString = '<div class="strong">' + element.name + '</div><div>' + element.add1 + '</div><div>' + element.add2 + '</div><div>'+ element.phone + '</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
toggleBounce(marker);
});
}
function toggleBounce(marker) {
if (marker.getAnimation() != null) {
marker.setAnimation(null);
} else {
marker.setAnimation(google.maps.Animation.BOUNCE);
}
}
function viewModel() {
}
ko.applyBindings(new viewModel());
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Marker Animations</title>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0; }
#map-canvas { height: 100% }
.place-list {
display: inline-block;
width: 250px;
max-height: 70%;
float: right;
position: absolute;
top: 40px;
right: 6px;
z-index: 5;
overflow-y: auto;
background-color: white;
border: 2px solid grey;
opacity: 0.8;
list-style-type: none;
padding: 20px;
margin: auto;
font-weight: bolder;
border-radius: 25px;
}
</style>
</head>
<body>
<ul class="place-list" data-bind="foreach: Points" >
<li data-bind="text: name, click: $parent.marker" ></li>
</ul>
<div id="map-canvas"></div>
<script type="text/javascript" src="https://maps.googleapis.Com/maps/api/js?key=AIzaSyCPgww-LhtxoQqq2zLI1_gOU1L2XayS-rE"> </script>
<script src="js/lib/knockout-3.2.0.js"></script>
<script src="js/app.js"></script>
</body>
</html>
Thanks for your help,
Max
One of the ways to do it is to use Knockout.js data-binding. In particular, you can use foreach binding to display all your items as a list and apply functions to each of them. Then use click binding to execute functions attached to list items when a user clicks on it. An example of how to use it for list view of places in Google Maps with search function:
HTML:
<h4>Places</h4>
<input type="text" id="my-Input" data-bind="textInput: filter" placeholder="Search for places..">
<div class="scroll" id="my-UL">
<ul data-bind="foreach: visiblePlaces">
<li>
<input data-bind="value: title, click: $parent.zoomToPlace, text: address" type="button" class="btn btn-small btn-link" id="zoomTo">
</li>
</ul>
</div>
JS:
/ ViewModel - provides list view of places, on click zooms map, shows the marker, infowindow, etc.
function viewModel() {
var self = this;
self.places = ko.observableArray(locations);
self.address = ko.observable();
self.title = ko.observable();
self.id = ko.observable();
this.filter = ko.observable();
this.visiblePlaces = ko.computed(function() {
return this.places().filter(function(place) {
if (!self.filter() || place.title.toLowerCase().indexOf(self.filter().toLowerCase()) !== -1)
return place;
});
}, this);
//Zooms to a selected marker and open infowindow
self.zoomToPlace = function() {
// Initialize the geocoder.
var geocoder = new google.maps.Geocoder();
// Get the place.
var address = this.address;
var id = this.id;
// Geocode the address/area entered to get the center. Then, center the map on it and zoom in
geocoder.geocode({
address: address,
}, function(results, status) {
map.setCenter(results[0].geometry.location);
map.setZoom(15);
google.maps.event.trigger(markers[id], 'click');
});
};
}
var vm = new viewModel();
ko.applyBindings(vm);
This will produce a list of places from an array (styles and array aren't shown in the code) and the corresponding marker will open an infowindow and bounce.
For full code, you can look it in my repo: https://github.com/DmitryGrechko/Neighborhood_Map

Fusion Table Icon

I have two columns in my fusion table, both store the names of icons. One of the tables is the default icons.
I'm wondering if there is a way to toggle between the two columns to change icons in JavaScript?
Cheers
set up two maps in the FusionTables UI with the appropriate columns defining the icons (Fusion Tables Help article describing how to do that)
"publish" the map, get HTML and Javascript, that will contain the values to use for styleId and template for each configuration.
call .setOptions on the FusionTablesLayer to change between them
<!DOCTYPE html>
<html>
<head>
<meta name="viewport"></meta>
<title>Astraptes fulgerator- demo data - Google Fusion Tables</title>
<style type="text/css">
html, body, #googft-mapCanvas {
height: 300px;
margin: 0;
padding: 0;
width: 500px;
}
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
google.maps.visualRefresh = true;
var isMobile = (navigator.userAgent.toLowerCase().indexOf('android') > -1) ||
(navigator.userAgent.match(/(iPod|iPhone|iPad|BlackBerry|Windows Phone|iemobile)/));
if (isMobile) {
var viewport = document.querySelector("meta[name=viewport]");
viewport.setAttribute('content', 'initial-scale=1.0, user-scalable=no');
}
var mapDiv = document.getElementById('googft-mapCanvas');
mapDiv.style.width = isMobile ? '100%' : '500px';
mapDiv.style.height = isMobile ? '100%' : '300px';
var map = new google.maps.Map(mapDiv, {
center: new google.maps.LatLng(10.902224578468406, -85.43183000000005),
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(document.getElementById('googft-legend-open'));
map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(document.getElementById('googft-legend'));
layer = new google.maps.FusionTablesLayer({
map: map,
heatmap: { enabled: false },
query: {
select: "col12",
from: "1_DWHpdjPNGQwVZU5OLbMMS-6yrbIY4wTGJoRMLg",
where: ""
},
options: {
styleId: 3,
templateId: 3
}
});
if (isMobile) {
var legend = document.getElementById('googft-legend');
var legendOpenButton = document.getElementById('googft-legend-open');
var legendCloseButton = document.getElementById('googft-legend-close');
legend.style.display = 'none';
legendOpenButton.style.display = 'block';
legendCloseButton.style.display = 'block';
legendOpenButton.onclick = function() {
legend.style.display = 'block';
legendOpenButton.style.display = 'none';
}
legendCloseButton.onclick = function() {
legend.style.display = 'none';
legendOpenButton.style.display = 'block';
}
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<input type="button" value="change A" onclick="layer.setOptions({styleId:2, template:2});"></input>
<input type="button" value="change B" onclick="layer.setOptions({styleId:3, template:3});"></input>
<div id="googft-mapCanvas"></div>
</body>
</html>

Ground Overlay with Transparency

I have an online map that contains a ground-overlay image, and would like to make the image semi-transparent so that the base map will show through. Is it possible to add a transparency value to this overlay?
http://www.tpwd.state.tx.us/fishboat/fish/recreational/lakes/ingulf1c.phtml
Here's the code for the ground overlay:
var imageBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(25.71438633861514, -98.33555959121725),
new google.maps.LatLng(30.40813339247205, -93.57953893270167));
function initialize() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(28.0041,-96.3618),
zoom: 7,
mapTypeId: 'roadmap'
});
overlay = new google.maps.GroundOverlay(
'/fishboat/fish/recreational/lakes/images/statemaps/gulfregion.gif',
imageBounds);
overlay.setMap(map);
There is a setOpacity method of the GroundOverlay (works for me with values between 0 and 1.0):
var overlay = null;
function initialize() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(28.0041,-96.3618),
zoom: 7,
mapTypeId: 'roadmap'
});
overlay = new google.maps.GroundOverlay('http://www.tpwd.state.tx.us/fishboat/fish/recreational/lakes/images/statemaps/gulfregion.gif',
imageBounds);
overlay.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
function setOpacity() {
var opacityStr = document.getElementById('opacity').value;
var opacity = parseFloat(opacityStr);
overlay.setOpacity(opacity);
}
<input type="text" id="opacity" value="0.2"></input>
<input type="button" value="setOpacity" onclick="setOpacity();"></input>
working example - proof of concept fiddle
code snippet:
var overlay = null;
function initMap() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(28.0041, -96.3618),
zoom: 7,
mapTypeId: 'roadmap'
});
var imageBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(25.71438633861514, -98.33555959121725),
new google.maps.LatLng(30.40813339247205, -93.57953893270167));
overlay = new google.maps.GroundOverlay(
'http://www.tpwd.state.tx.us/fishboat/fish/recreational/lakes/images/statemaps/gulfregion.gif',
imageBounds);
overlay.setMap(map);
map.fitBounds(imageBounds);
}
function setOpacity() {
var opacityStr = document.getElementById('opacity').value;
var opacity = parseFloat(opacityStr);
overlay.setOpacity(opacity);
}
html,
body {
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
}
#map {
width: 100%;
height: 90%;
}
<div id="map"></div>
<input type="text" id="opacity" value="0.2" />
<input type="button" value="setOpacity" onclick="setOpacity();" />
<!-- Replace the value of the key parameter with your own API key. -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap"></script>

Sidebar help for Google Maps API V3

I need help to create a sidebar. I have it partially working, but there are 2 problems to solve. First, the sidebar only shows the last marker information. I may not have placed some of the sidebar coding in its proper place. Second, (which may be part of the first problem), all the icons appear when using Firefox, but when using IE8 all the icons except the last icon appears. To view the map and code, first go to http://www.askdata.net/propmap/mapdata.php and do the demo (paste addresses into text area), then the map page will be displayed. Thanks again. The code also follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<h1>'Comparables Map'</h1><!DOCTYPE html >
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Comparables Map</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
//<![CDATA[
var customIcons = {
Subject: {
icon: 'http://askdata.net/compmap/mapicons/sub.png',
//shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
Comp1: {
icon: 'http://askdata.net/compmap/mapicons/c1.png',
//shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
Comp2: {
icon: 'http://askdata.net/compmap/mapicons/c2.png',
//shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
Comp3: {
icon: 'http://askdata.net/compmap/mapicons/c3.png',
//shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
Comp4: {
icon: 'http://askdata.net/compmap/mapicons/c4.png',
//shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
Comp5: {
icon: 'http://askdata.net/compmap/mapicons/c5.png',
//shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
Comp6: {
icon: 'http://askdata.net/compmap/mapicons/c6.png',
//shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
}
};
function load() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(41.95, -87.65),
zoom: 13,
mapTypeId: 'roadmap'
});
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP file
downloadUrl("genxml2.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var address = markers[i].getAttribute("address");
var type = markers[i].getAttribute("type");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = "<b>" + type + "</b> <br/>" + address;
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
draggable: true,
icon: icon.icon
//shadow: icon.shadow
});
bindInfoWindow(marker, map, infoWindow, html);
var sidebar = document.getElementById('sidebar');
sidebar.innerHTML = '';
if (markers.length == 0) {
sidebar.innerHTML = 'No results found.';
map.setCenter(new GLatLng(41, -87), 4);
return;
}
var sidebarEntry = createSidebarEntry(marker, type, address);
sidebar.appendChild(sidebarEntry);
}
});
function createSidebarEntry(marker, type, address) {
var div = document.createElement('div');
var html = '<b>' + type + '</b>' + address;
div.innerHTML = html;
div.style.cursor = 'pointer';
div.style.marginBottom = '5px';
google.maps.event.addDomListener(div, 'click', function() {
google.maps.event.trigger(marker, 'click');
});
google.maps.event.addDomListener(div, 'mouseover', function() {
div.style.backgroundColor = '#eee';
});
google.maps.event.addDomListener(div, 'mouseout', function() {
div.style.backgroundColor = '#fff';
});
return div;
}
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
//]]>
</script>
</head>
<body onload="load()">
<br/>
<br/>
<div style="width:1200px; font-family:Arial,
sans-serif; font-size:11px; border:1px solid black">
<table>
<tbody>
<tr id="cm_mapTR">
<td width="200" valign="top"> <div id="sidebar" style="overflow: auto; height: 700px; font-size: 11px; color: #000"></div>
</td>
<td> <div id="map" style="overflow: hidden; width: 1000px; height: 700px"></div> </td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
IE doesn't like trailing commas at the end of a structure, e.g. the comma after the icon here:
Comp5: {
icon: 'http://askdata.net/compmap/mapicons/c5.png',
}
You're mixing Google Maps API 2 and 3 code. e.g. you declare latlng objects using API 3:
center: new google.maps.LatLng(41.95, -87.65)
but then you use API 2 here:
map.setCenter(new GLatLng(41, -87), 4);
Here is your problem: sidebar.innerHTML = '';
Since it is within the loop, every time it loops, it deletes the prior side bar entry.
Place it fight after function load() { -Outside the loop AND within Load().
Use document.getElementById('sidebar').innerHTML = '';
Also, you have to do something about your customIcons
You can change them to something like this
Subject: { icon: 'http://askdata.net/compmap/mapicons/sub.png' }
And you are done!
EXAMPLE
function load() {
document.getElementById('sidebar').innerHTML = '';
var map = new google.maps.Map(document.getElementById("map"), {
//rest of the code goes here
Also, it might be a good idea to replace this code with CSS:
div.style.cursor = 'pointer';
div.style.marginBottom = '5px';
google.maps.event.addDomListener(div, 'mouseover', function() {
div.style.backgroundColor = '#eee';
});
google.maps.event.addDomListener(div, 'mouseout', function() {
div.style.backgroundColor = '#fff';
});
CSS option:
#sidebar {
background-color: white;
}
#sidebar div {
cursor: pointer;
margin-bottom: 5px;
}
#sidebar div:hover {
background-color: #eee;
}

Resources