Search code examples
jqueryhtmlsencha-touchhtml5-canvas

Javascript - Which framework to build scrollable map with item selection?


I need to scroll a large map area on a mobile device website, and be able to select PNG or vector images on the map, like this:

enter image description here

What would be the simplest method? HTML5, jQuery, Sencha Touch, or ?


Solution

  • Using HTML5 canvas you can scroll like this:

    JS:

    var img = new Image();  
    img.src = 'image.jpg'; 
    
    var w = $(window).outerWidth();
    var h = $(window).height();
    
    var addit = -1;
    var scrollSpeed = 10; 
    var current = 0;
    
    ctx = document.getElementById('canvas1').getContext('2d');
    
    var init = setInterval(function() {
                   current += addit;
                   ctx.drawImage(img,current,0, w, h);
               }, scrollSpeed);
    

    CSS:

    body {
      overflow: hidden;
    }
    #canvas1 {
      position: absolute;
      height: 100%;
      width: auto;
      left: 0;
      top: 0;
    }
    

    HTML:

    <canvas id="canvas1" width="1784px" height="534px"></canvas>