Git Product home page Git Product logo

mapboxgl-print-tool's Introduction

mapboxgl-print-tool

地图全图打印,框选打印导出图片

使用

  • CDN
    // 依赖file-save下载图片
      <script src="https://cdn.bootcss.com/FileSaver.js/2014-11-29/FileSaver.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.js"></script>
       <script>
           mapboxgl.accessToken = '';
           var map = new mapboxgl.Map({
               container: 'map',
               style: 'mapbox://styles/mapbox/streets-v9',
               preserveDrawingBuffer:true //canvas toDataURL
           });
           const mapPrint  = new MapPrintTool({
               enableImg:true, //是否出图
               fileName:'mapDemo.png' // 文件名
           })
           map.addControl(mapPrint, 'top-right')
           // 监听打印 获取数据 
           mapPrint.on('success',function (res) {
               console.log(res)
           })
       </script>
  • 模块化
      npm install mapboxgl-print-tool
      import MapPrintTool from 'mapboxgl-print-tool'
        // 打印
      const mapPrintTool = new MapPrintTool({
          enableImg:true,
          fileName:'test.jpg'
      })
      this.map.addControl(mapPrintTool,'top-left')
      //监听获取图片数据
      mapPrintTool.on('success',(res) => {
          console.log(res)
      })
     

配置项 -- 两个绑定出现

` 名称 类型 描述 默认值
1 enableImg Boolean 是否导出图片 true
2 fileName String 导出的图片文件名 'map.jpg'

事件

  • 监听 success,获取 canvas 转成的图片数据 base64
      const mapPrint = new MapPrintTool()
      mapPrint.on('success',(res) => {
          console.log(res)
      })

效果

  • 界面

  • 全图打印

  • 框选打印

mapboxgl-print-tool's People

Contributors

jerckyly avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.