Android basemap partial loading and movement

Source: Internet
Author: User
 

Public class mapmgr {public static mapmgr = NULL; private int map_num = 28; private int B _x = 0; private int B _y = 0; private int width = 0; private int Height = 0; private bitmap BMP view = NULL; // create by danielinbiti, if your image is indeed larger than the screen, modify the comment below. Public static void Init (INT width, int height) {If (mapmgr = NULL) {mapmgr = new mapmgr (width, height) ;}} public static mapmgr getinstance () {return mapmgr;} public mapmgr (INT width, int height) {This. width = width; this. height = height; bitmap BMP = picmgr. getinstance (). getbackgroundbitmap (); B _x = (BMP. getwidth ()-width)/2; // ensure that the image is larger than the screen's B _y = (BMP. getheight ()-height)/2; BMP view = bitmap. createbitmap (B MP, B _x, B _y, width, height);} public void logic () {} public void mapdown () {bitmap BMP = picmgr. getinstance (). getbackgroundbitmap (); If (B _y + height <BMP. getheight () {B _y = B _y + BMP. getheight ()/map_num; If (B _y + height> BMP. getheight () {B _y = BMP. getheight ()-height ;}} BMP view = bitmap. createbitmap (BMP, B _x, B _y, width, height);} public void mapup () {bitmap BMP = picmgr. getinstance (). getbackgro Undbitmap (); If (B _y> 0) {B _y = B _y-BMP. getheight ()/map_num; If (B _y <0) {B _y = 0 ;}} BMP view = bitmap. createbitmap (BMP, B _x, B _y, width, height);} public void mapleft () {bitmap BMP = picmgr. getinstance (). getbackgroundbitmap (); If (B _x> 0) {B _x = B _x-BMP. getwidth ()/map_num; If (B _x <0) {B _x = 0 ;}} BMP view = bitmap. createbitmap (BMP, B _x, B _y, width, height);} public void mapright () {bitmap BMP = P Icmgr. getinstance (). getbackgroundbitmap (); If (B _x + width <BMP. getwidth () {B _x = B _x + BMP. getwidth ()/map_num; If (B _x + width> BMP. getwidth () {B _x = BMP. getheight ()-width ;}} BMP view = bitmap. createbitmap (BMP, B _x, B _y, width, height);} public void draw (canvas) {paint = new paint (); If (BMP view! = NULL) {canvas. drawbitmap (BMP view, 0, 0, paint );}}}

Call

 
Public void onkeydowndeal (INT keycode) {If (keycode = keyevent. keycode_dpad_up) {mapmgr. getinstance (). mapup ();} else if (keycode = keyevent. keycode_dpad_down) {mapmgr. getinstance (). mapdown ();} else if (keycode = keyevent. keycode_dpad_left) {mapmgr. getinstance (). mapleft ();} else if (keycode = keyevent. keycode_dpad_right) {mapmgr. getinstance (). mapright ();}}

Then, use the thread to call draw for Refresh.

For touch movement, the coordinate calculation method is different, and others are similar. In addition, it can be expanded to GIS, and content can be locally loaded based on small image pasting.

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.