Google Map API 3为来自API 2代码的标记创建不同的颜色 [英] Google Map API 3 creating different colors for markers from code of API 2

查看:125
本文介绍了Google Map API 3为来自API 2代码的标记创建不同的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在API 2中使用了此代码,但找不到API 3的等效代码。我想根据严重性为标记创建不同的颜色,因此它们不是静态值。我遇到了如何创建 GICON,G_DEFAULT_ICON,GSize和addOverlay 的问题。如果有人告诉我如何转换这个确切的代码,我会很感激。我不想使用micons / color-dot.png,因为我使用了特定的颜色。

  var severity = parseFloat (标记[I] .getAttribute( 严重性)); 
var severityIcon =新的GIcon(G_DEFAULT_ICON);
var color;
if(severity == 0)color =66FF33;
else if(severity == 1)color =990099;
else if(severity == 2)color =00CCFF;

severityIcon.image =http://www.googlemapsmarkers.com/v1/+ color;
severityIcon.iconSize =新的GSize(15,30);

markerOptions = {icon:severityIcon};


var marker = createMarker(point,label,alarm,markerOptions);
map.addOverlay(marker);


解决方案

GIcon不再是GMap API V3的一部分。但Gabriel Schneider创建了一个Marker扩展,它可以解决您的问题。



StyledMarker 的文档和示例。 信中补充说。 示例



我想你会想要这样的东西:

  var styleMaker1 = new StyledMarker {styleIcon:new StyledIcon(StyledIconTypes.MARKER,{color:66FF33}),position:myLatLng,map:map}); 
... //等等


I used this code in API 2 but I can not find equivalent code for API 3. I want to create different colors for markers depending on severity so they are not static values. I have problem how to create GICON, G_DEFAULT_ICON, GSize and addOverlay. If someone tell me how to convert this exact code I will be thankful. I do not want to use micons/color-dot.png because of the specific colors I am using.

var severity = parseFloat(markers[i].getAttribute("severity"));
var severityIcon = new GIcon(G_DEFAULT_ICON);
var color;
if (severity == 0) color = "66FF33";
else if (severity == 1) color = "990099";
else if (severity == 2) color = "00CCFF";

severityIcon.image = "http://www.googlemapsmarkers.com/v1/" + color;
severityIcon.iconSize = new GSize(15, 30);

markerOptions = { icon:severityIcon };


  var marker = createMarker(point,label,alarm,markerOptions);
  map.addOverlay(marker);

解决方案

GIcon is no longer part of GMap API V3. But Gabriel Schneider created a Marker extension which solves your problem.

StyledMarker with documentation and examples.

This example demonstrates color changes for the default GMap icons with a letter added. Example

I think you'd want something like:

var styleMaker1 = new StyledMarker({styleIcon:new StyledIcon(StyledIconTypes.MARKER,{color:"66FF33"}),position:myLatLng,map:map});
... // etc.

这篇关于Google Map API 3为来自API 2代码的标记创建不同的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆