diegoazh / gmap-vue

A wrapper component for consuming Google Maps API built on top of Vue. Fork of the popular vue-google-maps plugin.
https://diegoazh.github.io/gmap-vue/
173 stars 51 forks source link

Need help on: Restricting Map Bounds #261

Closed joe94113 closed 2 years ago

joe94113 commented 2 years ago

Please complete all sections that you can but please don't remove any section, otherwise the bot will close your issue because it doesn't meet our issue template (you can remove this comment)

What you try to do

Restricting Map Bounds

What is the problem

How to limit map boundaries?

What kind of things have you already treated

Boundary values have been obtained

Steps to reproduce

Os

Mobile

Versions

Package manager

Plugin version

joe94113 commented 2 years ago

I use bounds changed to get the desired boundaries

boundsChanged() {
    console.log(
        "south:" +
            this.$refs.mapRef.$mapObject
                .getBounds()
                .getSouthWest()
                .lat()
    );
    console.log(
        "east:" +
            this.$refs.mapRef.$mapObject
                .getBounds()
                .getNorthEast()
                .lng()
    );
    console.log(
        "north:" +
            this.$refs.mapRef.$mapObject
                .getBounds()
                .getNorthEast()
                .lat()
    );
    console.log(
        "west:" +
            this.$refs.mapRef.$mapObject
                .getBounds()
                .getSouthWest()
                .lng()
    );
}

Restricting Map Bounds

async mounted() {
    await this.$gmapApiPromiseLazy();
    this.$refs.mapRef.$mapPromise.then((map) => {
        const TAIWAN = {
            south: 21.682932848786514,
            east: 123.51322416331587,
            north: 26.007404797220943,
            west: 118.28922513987837,
        };
        map.setRestriction({
            latLngBounds: TAIWAN,
            strictBounds: false,
        });
    });
}