English 中文(简体)
页: 1
原标题:Google Maps v3 - Muliple Markers - Different Colors

我用冷聚力来绘制一个 go角地图,我想用不同的彩色标识做事。

Using Google Maps API v3

这部法典是行之有效的,但所有1个标识——绿色总是显示的——我无法看到不同的颜色。

Thoughts? Thanx for any input

 <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> 

 <script type="text/javascript"> 

 var locations = 
[ 
<cfloop query=due>
<cfoutput>
<cfquery name="info" datasource="data">
SELECT * FROM data
WHERE id = #due.id#
</cfquery>
<cfif info.gpslat is not "">["#info.id#", #info.gpslat#, #info.gpslong#,      #info.id#],</cfif>
</cfoutput>
</cfloop> 
]; 

 var map = new google.maps.Map(document.getElementById( map ), { 
  zoom: 14, 
  center: new google.maps.LatLng(51.19, -114.48),
  mapTypeId: google.maps.MapTypeId.HYBRID
 }); 

var infowindow = new google.maps.InfoWindow(); 

 <cfloop query=due>
<cfquery name="info" datasource="data">
SELECT * FROM data
WHERE id = #due.id#
</cfquery>

       var marker, i;

<cfif info.gpslat is not "">    
   <cfif due.data is  yes >
   var image =  red.png ; 
   </cfif>
   <cfif due.data is  no >
   var image =  green.png ; 
   </cfif>
</cfif>
</cfloop> 


 for (i = 0; i < locations.length; i++) {   
  marker = new google.maps.Marker({ 
    position: new google.maps.LatLng(locations[i][1], locations[i][2]), 
    map: map,
    icon: image
  }); 

  google.maps.event.addListener(marker,  click , (function(marker, i) { 
    return function() { 
      infowindow.setContent(locations[i][0]); 
      infowindow.open(map, marker); 
    } 
  })(marker, i)); 
 } 


 </script> 
最佳回答

你们重新组合了 j和冷藏法,因此,所拍摄的标志形象是你 lo中的最后一张。 可能起作用的一些因素

<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> 

<script type="text/javascript"> 

    var locations = 
    [ 
    <cfloop query=due>
    <cfoutput>
    <cfquery name="info" datasource="data">
    SELECT * FROM data
    WHERE id = #due.id#
    </cfquery>
    <cfif info.gpslat is not "">[ #info.id# , #info.gpslat#, #info.gpslong#,#info.id#,<cfif due.data is "yes> red.png <cfelse> green.png </cfif>],</cfif>
    </cfoutput>
    </cfloop> 
    ]; 

    var map = new google.maps.Map(document.getElementById( map ), { 
        zoom: 14, 
        center: new google.maps.LatLng(51.19, -114.48),
        mapTypeId: google.maps.MapTypeId.HYBRID
    }); 

    var infowindow = new google.maps.InfoWindow(); 

    for (i = 0; i < locations.length; i++) {   
        marker = new google.maps.Marker({ 
        position: new google.maps.LatLng(locations[i][1], locations[i][2]), 
        map: map,
        icon: locations[i][4]
    }); 

    google.maps.event.addListener(marker,  click , (function(marker, i) { 
            return function() { 
                infowindow.setContent(locations[i][0]); 
                infowindow.open(map, marker); 
            } 
        })(marker, i)); 
    } 
</script> 

法典也没有优化......但又是:-

问题回答

我这样说,你需要一个阵容或一些东西。 ::

<cfloop query=due>
<cfquery name="info" datasource="data">
SELECT * FROM data
WHERE id = #due.id#
</cfquery>

       var marker, i;

<cfif info.gpslat is not "">    
   <cfif due.data is  yes >
   var image =  red.png ; 
   </cfif>
   <cfif due.data is  no >
   var image =  green.png ; 
   </cfif>
</cfif>
</cfloop> 

我的假设是,做的是/或做,在地图上形成一个以上标记——实际上为“age”生产一个变量。

var image =  red.png ;
var image =  red.png ;
var image =  green.png ;

But each set statement is going to overwrite the next on in the script.

相反,创立了一种由你称之为“红色或绿色”的联合文件功能。 和在您的座位上:

icon: image;

you would now do:

icon: getimage(var1, var2);

var1和var2等。 gsplat and due.data. 无论这还是整个事情都需要在休息室内进行,因此,你都按顺序写出每个标识。

您可使用CSS Sprite Technologies,使用各种标识:

var mImage = new google.maps.MarkerImage("/i/Images/IconsLarge.png", 
    new google.maps.Size(34, 35), 
    new google.maps.Point(0, vPos), <--- set the vertical position to match your sprite offset.
    new google.maps.Point(10, 34)
); 
//insert marker
marker = new google.maps.Marker({
    icon: mImage,
    position: new google.maps.LatLng(latitude, longitude),
    map: map
});




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签