angular-google-maps icon indicating copy to clipboard operation
angular-google-maps copied to clipboard

Zoom control icons disappear after configuring zoomControlOptions position

Open lolaswift opened this issue 8 years ago • 21 comments

Issue description zoomControlOptions position is not working

Steps to reproduce and a minimal demo of the problem <agm-map [latitude]="lat" [longitude]="lng" [zoom]="zoom" [zoomControl]="true" [zoomControlOptions]="{position: 'TOP_LEFT'}" (mapClick)="mapClicked($event)" (mapReady)="onMapReady($event)">

_Use https://plnkr.co or similar -- try this template as a starting point: http://plnkr.co/edit/YX7W20?p=preview

https://stackblitz.com/edit/angular-google-maps-demo-7cmc4g?file=app/app.component.html

What steps should we try in your demo to see the problem?

Current behavior Zoom controls disappear

Expected/desired behavior Should show on the position specified

angular2 & angular-google-maps version angular 5.0, latest angular-google-maps version

Other information

lolaswift avatar Feb 06 '18 16:02 lolaswift

I've never used this option myself and I don't currently have a handy Angular project with me where I can quickly try this, but upon inspecting the source code, I see that ZoomControlOptions (the type you're supposed to give it) is using ControlPosition, which is an enumeration, not a string; you're giving it a string.

lazarljubenovic avatar Feb 07 '18 17:02 lazarljubenovic

thx, lazarljubenovic. I am new to typescript. Can you please give me some code example how to pass the right param? I want to place the controls RIGHT_TOP

lolaswift avatar Feb 07 '18 18:02 lolaswift

Need to install googlemap types npm install @types/googlemaps

Then in the component import the types. import { } from 'googlemaps';

Then need to define the position for use through a variable in the component

zoomPosition: google.maps.ControlPosition = google.maps.ControlPosition.TOP_RIGHT;

Then pass that through interpolation to the element [zoomControlOptions] = "{position: zoomPosition}"

Works when I try it in your stackblitz example above.

timcblank avatar Feb 08 '18 19:02 timcblank

@timcblank Many thx for your help. You solution works in the stackblits example. However, I use ionic 3 and I got 'ReferenceError: google is not defined' error. Any idea?

lolaswift avatar Feb 08 '18 22:02 lolaswift

"google" is defined as a type from the types install with the project. You get access to those types from import. Make sure you've also included the AgmModule with your app module and any lazy loaded modules using AGM correctly as well. That info should be part of the getting started bit on the website for this library.

timcblank avatar Feb 08 '18 22:02 timcblank

@timcblank thx for the tips. Adding AgmModule to the app module wasn't necessary.

After some struggling, I found the way.

I assigned the value in onMapReady(map) { google.maps.ControlPosition = google.maps.ControlPosition.TOP_RIGHT; this.zoomPosition = google.maps.ControlPosition; }

You solution SOLVED my issue. Millions of thanks tim!

lolaswift avatar Feb 08 '18 22:02 lolaswift

I use Agm with ionic 3.x. To help other people. Here is what I did: 1. npm install @types/googlemaps 2. ts.

import { } from 'googlemaps'; declare const google: any;

zoomPosition: any //Defined the variable above the constructor

map.setOptions({ zoomControl: 'true', zoomControlOptions: { position: google.maps.ControlPosition.RIGHT_CENTER } });

3.html:

<agm-map [latitude]="lat" [longitude]="lng" [zoom]="zoom" (mapClick)="mapClicked($event)" (mapReady)="onMapReady($event)">

@timcblank thanks again. People like you deserve lots of respect.

lolaswift avatar Feb 08 '18 23:02 lolaswift

@lolaswift not sure how you got it working it is not working for me

this is what i did import { } from 'googlemaps'; declare const google: any;

zoomPosition = google.maps.ControlPosition.TOP_LEFT

i still get 'ReferenceError: google is not defined'

any help will be appreciated!

thanks

sumitdaga avatar Feb 13 '18 11:02 sumitdaga

@sumitdaga You need to run it in your mapReady function.

onMapReady(map) { map.setOptions({ zoomControl: 'true', zoomControlOptions: { position: google.maps.ControlPosition.RIGHT_CENTER } });
}

Don't forget to have mapReady on your template like this: <agm-map [latitude]="lat" [longitude]="lng" [zoom]="zoom" (mapClick)="mapClicked($event)" (mapReady)="onMapReady($event)">

lolaswift avatar Feb 13 '18 12:02 lolaswift

@lolaswift

Thanks a lot ! ...it worked ! still curious though, how the stackblits example of timcblank worked !

thanks anyway

sumitdaga avatar Feb 13 '18 12:02 sumitdaga

@sumitdaga I am not sure. I guess it has something to do with lazyloading. You can only set those options when the map is ready.

lolaswift avatar Feb 13 '18 13:02 lolaswift

All googlemap types are imported through the command

import { } from 'googlemaps';

You don't need to declare the variable google at all. It becomes available inside the MapsAPILoader load function or onMapReady function or inside a function called from the map element on callback. You can't use the google types outside that.

timcblank avatar Feb 13 '18 15:02 timcblank

All you need is to: import { ControlPosition } from '@agm/core/services/google-maps-types'; and then:

zoomControlOptions: {
      position: ControlPosition.TOP_LEFT
 }

shoudaos avatar Feb 15 '18 14:02 shoudaos

thanks! @shoudaos

this makes more sense!

sumitdaga avatar Feb 15 '18 14:02 sumitdaga

@shoudaos. Many thanks!

lolaswift avatar Feb 22 '18 20:02 lolaswift

➡️ Im closing this because I don't see any bug. Feel free to reopen if you still think there's a bug or comment below.

sebholstein avatar Mar 03 '18 15:03 sebholstein

@SebastianM I am alson stuck with this issue <agm-map #gm [latitude]="center?.lat" [longitude]="center?.lng" [zoom]="zoom" [usePanning]='true' [zoomControlOptions]="{position: 'TOP_LEFT'}"> can you please give a right example

mahfuzur avatar Mar 08 '18 12:03 mahfuzur

@mahfuzur . I do it like this

ts:

import { ControlPosition } from '@agm/core/services/google-maps-types';

onMapReady(map) { map.setOptions({ zoomControl: 'true', zoomControlOptions: { position: ControlPosition.TOP_LEFT } }); }

html:

<agm-map [latitude]="lat" [longitude]="lng" [zoom]="zoom" (mapClick)="mapClicked($event)" (mapReady)="onMapReady($event)">

lolaswift avatar Mar 08 '18 13:03 lolaswift

I feel like this is an issue, or the documentation should be updated. The documentation tells me I can do

[zoomControlOptions]="{position: LEFT_TOP}"

Instead I have to do

public mapReadyHandler(map): void {
        this.map = map;
        this.map.setOptions({
            zoomControlOptions: {
                position: google.maps.ControlPosition.LEFT_TOP
            }
        });
    }

Defmetalhead avatar Jul 18 '18 20:07 Defmetalhead

@mahfuzur . I do it like this

ts:

import { ControlPosition } from '@agm/core/services/google-maps-types';

onMapReady(map) { map.setOptions({ zoomControl: 'true', zoomControlOptions: { position: ControlPosition.TOP_LEFT } }); }

html:

<agm-map [latitude]="lat" [longitude]="lng" [zoom]="zoom" (mapClick)="mapClicked($event)" (mapReady)="onMapReady($event)">

thanks you! this solution helped me

ignatov-dmitry avatar Nov 22 '18 08:11 ignatov-dmitry