Make Baidu map offline JavaScript API load local tile map

Source: Internet
Author: User

1. First get Baidu JavaScript API

First open the http://api.map.baidu.com/api?v=1.3 as shown in the browser

Where http://api.map.baidu.com/getscript?v=1.3&key=&services=&t=20121108061854 this link is the API file we're looking for,

Also open it in the browser and save it as "Apiv1.3.min.js"

and Baidu map must be some of the controls, cursors, logos and other pictures are also downloaded down

2. Modify the "apiv1.3.min.js" to replace the map control inside the picture, cursor, logo and other links replaced by local.

3. Download Baidu map Tile, there are many ways to get it. Like this tool: Maptiledownloader

4. Start loading local map tiles using the offline Map API

Now, can completely out of the network to use Baidu map. Sample source code is as follows:

<!DOCTYPE HTML><HTML>        <Head>        <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />        <title>Baidu Offline Map Demo</title>        <Scripttype= "Text/javascript"src= "Js/apiv1.3.min.js"></Script>        <Scripttype= "Text/javascript"src= "Js/map,oppc,navictrl,tile,copyrightctrl"></Script>        <!--script type= "Text/javascript" src= "http://api.map.baidu.com/api?v=1.3" ></script -        <Linkrel= "stylesheet"type= "Text/css"href= "Bmap.css" />    </Head>        <Body>        <Divstyle= "left:0;top:0;width:100%;height:100%;p osition:absolute;"ID= "Container"></Div>    </Body></HTML><Scripttype= "Text/javascript">    varTilelayer= NewBmap.tilelayer ({istransparentpng:true    }); Tilelayer.gettilesurl= function(Tilecoord, zoom) {varx=tilecoord.x; vary=Tilecoord.y; return 'maptile/' +Zoom+ '/' +x+ '/' +y+ '. PNG'; }        varMap= NewBmap.map ('Container');    Map.addtilelayer (Tilelayer); Map.addcontrol (NewBmap.navigationcontrol ()); Map.centerandzoom (NewBmap.point (100.675, 39.007978), 5);  Map.enablescrollwheelzoom (); //Enable wheel zoom in and zoom outMap.enablekeyboard (); //enables keyboard actions, which are disabled by default. The top, bottom, left, and right keys of the keyboard can move the map continuously. map.enablecontinuouszoom ();//Enable continuous zoom effect    varCopyctrl= NewBmap.copyrightcontrol ({anchor:bmap_anchor_bottom_right}); Copyctrl.addcopyright ({ID:1, Content:"http://maptiledownloader.googlecode.com Baidu offline map demo"    }); Map.addcontrol (Copyctrl);</Script>

Make Baidu map offline JavaScript API load local tile map

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.