javascript 什么是构造接口`google.maps.Icon`

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14407079/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 21:33:28  来源:igfitidea点击:

What is the construct interface `google.maps.Icon`

javascriptgoogle-maps

提问by ddinchev

The docs of Google Maps V3 JS APIdoes not seem to give the interface of the construct of google.maps.Icon. I found an example with MarkerImage, which seems to be deprecated now.

Google Maps V3 JS API的文档似乎没有给出google.maps.Icon. 我找到了一个带有 的示例MarkerImage,现在似乎已弃用。

So, what are the possible google.maps.Iconconstruct parameters and what is their order? How to define icon size, icon offset in sprite, icon anchor, etc?

那么,可能的google.maps.Icon构造参数是什么以及它们的顺序是什么?如何定义图标大小、精灵中的图标偏移量、图标锚点等?

Edit:

编辑:

How would I create an icon and assign it to a marker? Eg (not tested/does not work):

我将如何创建一个图标并将其分配给一个标记?例如(未测试/不起作用):

var icon = new google.maps.Icon(path, 
    new google.maps.Size(32, 32), // size
    new google.maps.Point(0, 32), // offset in sprite
    null, // anchor
);

I do see the docs but I do not see example usage if that class!

我确实看到了文档,但我没有看到该课程的示例用法!

回答by geocodezip

There is no constructor for the google.maps.Icon, it is an anonymous javascript object like MapOptions, MarkerOptions, PolygonOptions, etc.

google.maps.Icon 没有构造函数,它是一个匿名的 javascript 对象,如MapOptionsMarkerOptionsPolygonOptions等。

You use it like this:

你像这样使用它:

var icon = {
    anchor: new Point(...),
    url: "myurl"
    // etc..
    };

From Oliverin a comment: The point is: there is no such class (or function, for that matter) as google.maps.Icon. The API docs refer to it as google.maps.Icon object specification(here), as opposed to e.g. the InfoWindow class.

来自Oliver的评论:重点是:没有像 google.maps.Icon 这样的类(或函数,就此而言)。API 文档将其称为google.maps.Icon 对象规范此处),而不是例如InfoWindow 类

回答by Nikolaj

Hmm... Now, this answer is just wrong.

嗯......现在,这个答案是错误的。

You can't

你不能

var icon = new google.maps.Icon({
    anchor: new Point(...),
    url: "myurl"
    // etc..
});

It's an object literal, which means that you can just use it like this:

它是一个对象字面量,这意味着您可以像这样使用它:

var icon = {
    anchor: new Point(...),
    url: "myurl"
    // etc..
};