css-scaled google maps click incorrect coordinates

前端 未结 3 1973
一生所求
一生所求 2021-01-28 11:11

I have a Google Maps map inserted in a css-scaled container. Due to project specifics this cannot be avoided. I need to track clicks coords on this map, but being scaled map set

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-28 11:20

    This answer works, but being scaled map works very bad, many coordinate-related functions don't wok correctly. But there is a workaround: place the map in a virtual iframe:

        const iframe = this.$el.querySelector('iframe');
        iframe.contentWindow.document.open();
        iframe.contentWindow.document.write('
    '); iframe.contentWindow.document.close(); const mapContainer = iframe.contentWindow.document.querySelector('#map'); const map = new gmaps.Map(mapContainer, { center: {lat: 48.7, lng: 31}, zoom: 6 });

    There are no x-origin restrictions and you can manipulate with iframe content how you want. And with it, even if parent container is scaled, everything works fine

提交回复
热议问题