Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add a way to offset center of map #716

Closed
smatthews1999 opened this issue Oct 21, 2016 · 4 comments
Closed

Feature Request: Add a way to offset center of map #716

smatthews1999 opened this issue Oct 21, 2016 · 4 comments
Labels

Comments

@smatthews1999
Copy link

Could there be a way to add an offset to the center of the map. I know there are ways to do this with direct access to the API. For example...

function offsetCenter(latlng, offsetx, offsety) {

    // latlng is the apparent centre-point
    // offsetx is the distance you want that point to move to the right, in pixels
    // offsety is the distance you want that point to move upwards, in pixels
    // offset can be negative
    // offsetx and offsety are both optional

    var scale = Math.pow(2, map.getZoom());

    var worldCoordinateCenter = map.getProjection().fromLatLngToPoint(latlng);
    var pixelOffset = new google.maps.Point((offsetx/scale) || 0,(offsety/scale) ||0);

    var worldCoordinateNewCenter = new google.maps.Point(
        worldCoordinateCenter.x - pixelOffset.x,
        worldCoordinateCenter.y + pixelOffset.y
    );

    var newCenter = map.getProjection().fromPointToLatLng(worldCoordinateNewCenter);

    map.setCenter(newCenter);

}

Is there a way to accomplish this with the current components?
Thanks
Sam

@arsonik
Copy link

arsonik commented Feb 15, 2017

Hi, just get hold of the google map object and then

        map.setCenter(latlng);
        map.panBy(offsetX, offsetY);

https://developers.google.com/maps/documentation/javascript/reference

Changes the center of the map by the given distance in pixels. If the distance is less than both the width and height of the map, the transition will be smoothly animated. Note that the map coordinate system increases from west to east (for x values) and north to south (for y values).

@Jonatthu
Copy link

@arsonik but that map variable does not have panBy only has panTo using this package, or how can I access to this property without get a compilation error?

@TdoubleG
Copy link

TdoubleG commented Aug 3, 2018

works like @arsonik mentioned.
In HTML:
<agm-map (mapReady)="mapReady($event)" [latitude]="lat" [longitude]="lng">

In .ts:

mapReady(map: any) {
    map.panBy(0, -100);
  }

@stale
Copy link

stale bot commented Nov 13, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 13, 2018
@stale stale bot closed this as completed Nov 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants