setMap(map) seems not work

2,178 views
Skip to first unread message

Adriano Ellero

unread,
Apr 10, 2011, 3:29:41 PM4/10/11
to google-map...@googlegroups.com

http://win.cvao-soaring.org/public/Global/GlobalTask.asp
i have created an array of marker (more than 2000).
after created with method setMap(null)... markers disappear correctly
i kept the markers in an array.

once i try to restore the markers with setMap(map) the markers never appear anymore

<%@ LANGUAGE="VBSCRIPT" %>

<!DOCTYPE html "-//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">
<head>
<title>TEMA DI VOLO / Flight Task</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />

<link rel="stylesheet" href="/public/StyleSheet.css" type="text/css" media="screen" />


<script src="http://maps.google.com/maps/api/js?libraries=geometry&key=ABQIAAAADc9fglFKLYk-JGWzZ96EBxSmk_TfWjN_0u8ss96bjpTbgLtE0RQNqW6cAy5W82DslVimuaG4uzvNQA&sensor=false" type="text/javascript" >
</script>

<script type="text/javascript" language="javascript">

var map;
var task;
var taskOption;
var markersArray = [];
var segment;
var notePath = '';
var show = 1;
var markersLanding = [];

//----------------------- INITIALIZE MAP -------------------------------------

function Initialize(iniLAT, iniLNG, iniMapType, iniZoom) {
var newCenter;
newCenter = new google.maps.LatLng(iniLAT, iniLNG);
var mapOption={
zoom: iniZoom,
center: newCenter,
mapTypeId: iniMapType,
mapTypeControlOptions:{

style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
}
};


map = new google.maps.Map(document.getElementById("map_canvas"),mapOption); //create map





//---------------------------------------------- DIV MENU ---------------------------

var diMenu = document.createElement('DIV');

var tbMenu = document.createElement('TABLE');
tbMenu.setAttribute('style','filter:alpha(opacity=50); -moz-opacity:0.5; opacity:0.5; -khtml-opacity:0.5');
tbMenu.setAttribute('id','tbMenu');

var trHome = document.createElement('TR');
var tdHome = document.createElement('TD');
tdHome.setAttribute('class','list');
tdHome.innerHTML = '<a class=menu href=http://win.cvao-soaring.org target=_parent>Home</a>';

var trLanding = document.createElement('TR');
var tdLanding = document.createElement('TD');
tdLanding.setAttribute('class','list');
tdLanding.innerHTML = "<a class='menu' onclick='landing()'>Landings</a>";


var trNew = document.createElement('TR');
var tdNew = document.createElement('TD');
tdNew.setAttribute('class','list');
tdNew.innerHTML = "<a class='menu' onclick='newTask()'>New Task</a>";

var trTask = document.createElement('TR');
var tdTask = document.createElement('TD');
tdTask.setAttribute('class','list');
tdTask.setAttribute('id','tdTask');

var trTPs = document.createElement('TR');
var tdTPs = document.createElement('TD');
tdTPs.setAttribute('class','list');
tdTPs.setAttribute('id','tdTPs');

var gMap = document.getElementById("map_canvas");

gMap.appendChild(diMenu);
diMenu.appendChild(tbMenu);
tbMenu.appendChild(trHome);
tbMenu.appendChild(trNew);
tbMenu.appendChild(trLanding);
tbMenu.appendChild(trTask);
tbMenu.appendChild(trTPs);
trHome.appendChild(tdHome);
trTask.appendChild(tdTask);
trNew.appendChild(tdNew);
trLanding.appendChild(tdLanding);
trTPs.appendChild(tdTPs);

google.maps.event.addDomListener (tbMenu,'mouseover', function(){

document.getElementById('tbMenu').setAttribute('style','filter:alpha(opacity=100); -moz-opacity:1; opacity:1; -khtml-opacity:1') ;

});

google.maps.event.addDomListener (tbMenu,'mouseout', function(){

document.getElementById('tbMenu').setAttribute('style','filter:alpha(opacity=50); -moz-opacity:0.5; opacity:0.5; -khtml-opacity:0.5') ;

});


map.controls[google.maps.ControlPosition.RIGHT_TOP].push(diMenu); //add command menu



//------------------------- create box for showing mouse coordinates ------------------------------------------

var diLL = document.createElement('DIV');

var tbLL = document.createElement('TABLE');

var trLL = document.createElement('TR');
var tdLL = document.createElement('TD');
tdLL.setAttribute('id','tdLL');
tdLL.setAttribute('class','google');
tdLL.setAttribute('style','filter:alpha(opacity=50); -moz-opacity:0.5; opacity:0.5; -khtml-opacity:0.5');

var gMap = document.getElementById("map_canvas");

gMap.appendChild(diLL);
diLL.appendChild(tbLL);
tbLL.appendChild(trLL);
trLL.appendChild(tdLL);



google.maps.event.addDomListener (tdLL,'mouseover', function(){
document.getElementById('tdLL').setAttribute('style','filter:alpha(opacity=100); -moz-opacity:1; opacity:1; -khtml-opacity:1') ;
});

google.maps.event.addDomListener (tdLL,'mouseout', function(){

document.getElementById('tdLL').setAttribute('style','filter:alpha(opacity=50); -moz-opacity:0.5; opacity:0.5; -khtml-opacity:0.5') ;

});



map.controls[google.maps.ControlPosition.BOTTOM_LEFT].push(diLL); //add box for coordinate indicaition




google.maps.event.addListener (map, "mousemove", function(mEvent) {

var LatCoord= new String (mEvent.latLng.lat());
i=LatCoord.indexOf('.');
LatDeg=LatCoord.substr(0,i);
LatMinSec=LatCoord-LatDeg;
LatMinSec=LatMinSec*60;
var LatMinSec=new String(LatMinSec);
i=LatMinSec.indexOf('.');
LatMin=LatMinSec.substr(0,i);
LatSec=LatMinSec-LatMin;
LatSec=LatSec*60;
var LatSec=new String(LatSec);
i=LatSec.indexOf('.');
LatSec=LatSec.substr(0,i);

var LngCoord= new String (mEvent.latLng.lng());
i=LngCoord.indexOf('.');
LngDeg=LngCoord.substr(0,i);
LngMinSec=LngCoord-LngDeg;
LngMinSec=LngMinSec*60;
var LngMinSec=new String(LngMinSec);
i=LngMinSec.indexOf('.');
LngMin=LngMinSec.substr(0,i);
LngSec=LngMinSec-LngMin;
LngSec=LngSec*60;
var LngSec=new String(LngSec);
i=LngSec.indexOf('.');
LngSec=LngSec.substr(0,i);

document.getElementById("tdLL").innerHTML = 'N ' + LatDeg + "°" + LatMin + "'" + LatSec + "'' / E " + LngDeg + "°" + LngMin + "'" + LngSec + "''";


});



//--------------------------------- add listener for click for adding turn point------------------------



taskOption = {
strokeColor: '#0000ff',
strokeOpacity: 0.5,
strokeWeight: 3


}



task = new google.maps.Polyline(taskOption);
task.setMap(map);



//-------------------------------- add tunr point function -------------------------------------


google.maps.event.addListener(map,'rightclick',function(){
for (i in markersArray){
alert(markersArray[i].title);

}
});

google.maps.event.addListener(map, 'click', function(mEvent){

segment = task.getPath();
segment.push(mEvent.latLng);

var totalLength = google.maps.geometry.spherical.computeLength(segment);

var TL = totalLength / 1000;
TL = TL.toFixed(2);
document.getElementById('tdTask').innerHTML = TL + 'km';


var TP = new google.maps.Marker({
position: mEvent.latLng,
title: segment.length + ': ' + TL + 'km',
draggable: true,
map: map
}

);
notePath = notePath + segment.length + ': ' + TL + 'km<br>'
document.getElementById('tdTPs').innerHTML = notePath;

google.maps.event.addListener(TP,'drag',function(mEvent){

segment.clear();
notePath = '';
for (i in markersArray){
var a ='';
segment.push(markersArray[i].getPosition());
var totalLength = google.maps.geometry.spherical.computeLength(segment);

var TL = totalLength / 1000;
TL = TL.toFixed(2);
a = parseInt(i) + 1 + ': ' + TL + 'km';
notePath = notePath + a + '<br>';

markersArray[i].title = a;

}

document.getElementById('tdTPs').innerHTML = notePath;
task.setPath(segment);
var totalLength = google.maps.geometry.spherical.computeLength(segment);

var TL = totalLength / 1000;
TL = TL.toFixed(2);
document.getElementById('tdTask').innerHTML = TL + 'km';


});

google.maps.event.addListener(TP,'dragend',function(){
for(i in markersArray){
//markersArray[i].setMap(null);
markersArray[i].setMap(map);
}
});

markersArray.push(TP);



});
// end add turn point

}
// end initialize


//--------------------------------------------------- create marker ------------------------------------




function AddMarker(LAT, LNG, NameM, MapNav, MrkType) {
var MrkIcon;
switch (MrkType){
case "Outlanding":
MrkIcon = new google.maps.MarkerImage ('/images/Outlanding.png',
new google.maps.Size (20,20), /* size 519,519 */
new google.maps.Point (0,0), /* origin */
new google.maps.Point (10,10), /* anchor */
new google.maps.Size (20,20)); /* scale size */
break;
case 'Unusable':
MrkIcon = new google.maps.MarkerImage ('/images/Unusable.png',
new google.maps.Size (20,20), /* size 515,515 */
new google.maps.Point (0,0),
new google.maps.Point (10,10),
new google.maps.Size (20,20));
break;
case 'Airfield':
MrkIcon = new google.maps.MarkerImage ('/images/Airfield.png',
new google.maps.Size (25,20), /* size 633,515 */
new google.maps.Point (0,0),
new google.maps.Point (12,10),
new google.maps.Size (25,20));
break;
case 'Airport':
MrkIcon = new google.maps.MarkerImage ('/images/Airport.png',
new google.maps.Size (20,20), /* size 573,573 */
new google.maps.Point (0,0),
new google.maps.Point (10,10),
new google.maps.Size (20,20));
break;
case 'Maybe':
MrkIcon = new google.maps.MarkerImage ('/images/Maybe.png',
new google.maps.Size (20,20), /* size 515,515 */
new google.maps.Point (0,0),
new google.maps.Point (10,10),
new google.maps.Size (20,20));
break;
}

var LL = new google.maps.LatLng (LAT,LNG);


var marker = new google.maps.Marker ({
clickable: false,
map:map,
position: LL,
title:NameM,
icon: MrkIcon});

markersLanding.push(marker);
} // end add marker




//--------------------------------- create new task--------------------------------------------------

function newTask(){
task.setMap(null);
task=null;
notePath='';
document.getElementById('tdTPs').innerHTML = notePath;

taskOption = {
strokeColor: '#0000ff',
strokeOpacity: 0.5,
strokeWeight: 3
}

task = new google.maps.Polyline(taskOption);
task.setMap(map);

document.getElementById('tdTask').innerHTML = '';


if (markersArray){
for (i in markersArray) {
markersArray[i].setMap(null);
}

markersArray.length = 0;
segment.clear();
}
}


//-------------------------------------------- hide/show landings --------------------------------------
function landing () {
if (show == 0) {

for (i in markersLanding){
markersLanding[i].setMap(map);

}
show = 1;

}

if (show == 1) {
for (i in markersLanding){
markersLanding[i].setMap(null);
}
show = 0;
}
}
</script>

</head>



<%


iniLAT = Request.QueryString("LAT")

iniLNG = Request.QueryString("LNG")

iniMapType = Request.QueryString("MapType")

iniZoom = Request.QueryString("Zoom")



if iniLAT = "" then

iniLAT = "46.798333333333"

end if


if iniLNG = "" then

iniLNG = "12.8833333333333"

end if


if iniMapType = "" then

iniMapType = "google.maps.MapTypeId.TERRAIN"

end if


if iniZoom = "" then

iniZoom = "07"

end if


%>



<body style="text-align:center" >

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-9933789-1");
pageTracker._trackPageview();
} catch (err) { }
</script>
<script type="text/javascript" language="javascript">
if (navigator.appName == "Netscape") {

document.write("<div id='map_canvas' align='center' valign='center' style='width:100%; height:100%'></div>");

}

if (navigator.appName == "Microsoft Internet Explorer") {

document.write("<div id='map_canvas' align='center' valign='center' style='width:100%; height:100%'></div>");

}


</script>



<script type="text/javascript" language="javascript">

Initialize(<%=iniLAT%>,<%=iniLNG%>,<%=iniMapType%>,<%=iniZoom%>);

</script>
<%

set FSO = Server.CreateObject("Scripting.FileSystemObject")

set dbFolder = FSO.GetFolder(server.MapPath("/mdb-database"))

set FF = dbFolder.files
for each F in FF
if F.name <> "Global.mdb" then
if right(F.name,4) = ".mdb" then
CreateMap(F.name)
end if
end if
next


Function CreateMap (DatabaseName)

dbPath = Server.MapPath("/mdb-database/" & DatabaseName)

set FieldDB= Server.CreateObject("ADODB.Connection")
FieldDB.Open "driver={Microsoft Access Driver (*.mdb)}; DBQ=" & dbPath

set Field = server.createobject("ADODB.RECORDSET")
FieldRes = "SELECT FuoriCampo.* FROM FuoriCampo"
Field.Open FieldRes, FieldDB

if not Field.BOF or not Field.EOF then
Field.movefirst

do while not Field.EOF
LAT = Field.Fields("LATITUDINE GRADI") + Field.Fields("LATITUDINE PRIMI") / 60 + Field.Fields("LATITUDINE SECONDI") / 3600
LNG = Field.Fields("LONGITUDINE GRADI") + Field.Fields("LONGITUDINE PRIMI") / 60 + Field.Fields("LONGITUDINE SECONDI") / 3600
NameM = Field.Fields("SCHEDA") & " " & Field.Fields("NOME")
MapNav = "MapNav.asp?SCHEDA=" & Field.Fields("SCHEDA") & "&LAT=" & LAT & "&LNG=" & LNG
LAT = Replace (LAT, ",", ".")
LNG = Replace (LNG, ",", ".")

select case Field.Fields("CATEGORIA")
case "AEROPORTO. Airport."
MrkType = "Airport"
case "AVIOSUPERFICIE. Airfield."
MrkType = "Airfield"
case "FUORICAMPO. Outlanding."
MrkType = "Outlanding"
case "INUTILIZZABILE. Unusable."
MrkType = "Unusable"
case "IN VALUTAZIONE. Under evaluation."
MrkType = "Maybe"
end select

%>
<script type="text/javascript" language="javascript">

AddMarker(<%=LAT%>,<%=LNG%>,'<%=NameM%>','<%=MapNav%>', '<%=MrkType%>');

</script>
<%

Field.movenext
loop


end if

Field.Close

end function
%>

</body>
</html>


thanks a lot

Adriano Ellero
adriano...@gmail.com

email sent by Mac Pro

geoco...@gmail.com

unread,
Apr 10, 2011, 6:08:09 PM4/10/11
to Google Maps JavaScript API v3
On Apr 10, 12:29 pm, Adriano Ellero <adriano.ell...@gmail.com> wrote:
> http://win.cvao-soaring.org/public/Global/GlobalTask.asp
> i have created an array of marker (more than 2000).
> after created with method setMap(null)... markers disappear correctly

How do we make the markers disappear?

How do we make them exhibit the problem?

-- Larry

> i kept the markers in an array.
>
> once i try to restore the markers with setMap(map) the markers never appear anymore

>
> thanks a lot
>
> Adriano Ellero
> adriano.ell...@gmail.com

Adriano Ellero

unread,
Apr 11, 2011, 3:51:04 AM4/11/11
to google-map...@googlegroups.com, geoco...@gmail.com
http://win.cvao-soaring.org/public/Global/GlobalTask.asp
on the web page, click on "landings" first time to hide markers, second time to show markers.

"landings" has switch function (0/I) all the time it passes to 0 or I as long as u push


Adriano Ellero
adriano...@gmail.com


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


Rossko

unread,
Apr 11, 2011, 4:11:00 AM4/11/11
to Google Maps JavaScript API v3
> http://win.cvao-soaring.org/public/Global/GlobalTask.asp

It takes several minutes to render the map, with a few "unresponsive
script" warnings. This is what I'd expect with 2,000 markers.

> "landings" has switch function (0/I) all the time it passes to 0 or I as
> long as u push

But landings() doesn't have an if/else structure.
On entry with switch as 0, it sets switch to 1.
Then it it goes on to test if switch is 1 and if so set switch to 0.
Not a maps issue.

Adriano Ellero

unread,
Apr 11, 2011, 4:23:03 AM4/11/11
to google-map...@googlegroups.com, Rossko
thanks a lot all works perfectly (quite fast with safari, firefox, google C.)

black screens all maps with IE 7 and 8


Adriano Ellero
adriano...@gmail.com



--
Reply all
Reply to author
Forward
0 new messages