Show:

File: ia\maps\layers\MarkerLayer.js

  1. /**
  2. * A layer that you can add markers to.
  3. *
  4. * @author J Clare
  5. * @class ia.MarkerLayer
  6. * @extends ia.LayerBase
  7. * @constructor
  8. */
  9. ia.MarkerLayer = function()
  10. {
  11. ia.MarkerLayer.baseConstructor.call(this);
  12. this._markers = new Array();
  13. };
  14. ia.extend(ia.LayerBase, ia.MarkerLayer);
  15. /**
  16. * Adds a new marker
  17. *
  18. * @method addMarker
  19. * @param {Image} icon The icon.
  20. * @param {Number} x The x-coord.
  21. * @param {Number} y The y-coord.
  22. */
  23. ia.MarkerLayer.prototype.addMarker = function(icon, x, y)
  24. {
  25. var marker = {};
  26. marker.icon = icon;
  27. marker.x = x;
  28. marker.y = y;
  29. this._markers[this._markers.length] = marker;
  30. };
  31.  
  32. /**
  33. * Clears all the markers.
  34. *
  35. * @method clearMarkers
  36. */
  37. ia.MarkerLayer.prototype.clearMarkers = function()
  38. {
  39. this._markers = new Array();
  40. this.clear();
  41. };
  42.  
  43. /**
  44. * Renders the layer.
  45. *
  46. * @method render
  47. */
  48. ia.MarkerLayer.prototype.render = function()
  49. {
  50. this.clear();
  51. for (var i = 0; i < this._markers.length; i++)
  52. {
  53. var marker = this._markers[i];
  54. var px = this.map.getPixelX(marker.x) - (marker.icon.width / 2);
  55. var py = this.map.getPixelY(marker.y) - (marker.icon.height);
  56. this.context.drawImage(marker.icon, px, py);
  57. }
  58. };