Google Maps API V3 Printing Maps

前端 未结 5 1633
北海茫月
北海茫月 2020-12-09 14:13

I am looking for a method to efficiently print Google maps that have been implemented on a site using the google maps api v3.

I have seen some people using just the

5条回答
  •  盖世英雄少女心
    2020-12-09 14:38

    I guess by simple yet subtle DOM manipulation, you can get the "snapshot" of your Google Maps (well, theoretically - any maps :)) viewer and perfectly print it in any browsers. Assuming $mapContainer is the main container of your maps, related code is:

    // printAnyMaps ::
    function printAnyMaps() {
      const $body = $('body');
      const $mapContainer = $('.map-container');
      const $mapContainerParent = $mapContainer.parent();
      const $printContainer = $('
    '); $printContainer .height($mapContainer.height()) .append($mapContainer) .prependTo($body); const $content = $body .children() .not($printContainer) .not('script') .detach(); /** * Needed for those who use Bootstrap 3.x, because some of * its `@media print` styles ain't play nicely when printing. */ const $patchedStyle = $('