Help us understand the problem. What is going on with this article?

Google Maps APIでzoom levelに応じてmarkerの画像やサイズなどを変える

More than 1 year has passed since last update.

やりたいこと

zoom levelに応じてmarkerの画像やサイズを変えたい

コード

gmapsample.js
google.maps.event.addListener(map, 'zoom_changed', function(e){
    const currentzoom = map.getZoom();
    if(currentzoom < 12){
        for(let i in marker) {
            let image = {
                url: '/img/smallerIcon.png',
                    anchorPoint: new google.maps.Point(0,0),
                    scaledSize: new google.maps.Size(50,50),
            };
                marker[i].setIcon(image);
            }
    }
});

zoom_changedのイベントリスナにzoom levelに応じた処理を書いて、最後にmarkerそれぞれにsetIcon()メソッドを呼べばmarkerの設定が変わります。
上記の例ですと、image =でmarkerの設定を書いて、marker[i].setIcon(image)でセットしています。

以下はsetIconに関する参考です。
setIcon
google.maps.Icon interface

bubbles
仕事ではweb開発をしており、現在はphp(framework:laravel5.4.36)、sqlserver、mysql、javascriptを扱っています。
ayudante
いつもユーザー中心で技術者とコンサルタントがとことん考え抜く それがアユダンテです
https://ayudante.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした