var Shape =
{
CIRCLE_SHAPE: 4,
LINE_SHAPE: 5,
POLYGON_SHAPE: 6,
RECTANGLE_SHAPE: 7,
// properties
_map: null,
_id: null,
_layer: null,
_shape: null,
_type: null,
// methods
create: function(map, type, latlngs)
{
if(this._shape == null)
{
this._map = map;
this._type = (type == 'circle')?this.CIRCLE_SHAPE:(type == 'polyline')?
this.LINE_SHAPE:(type == 'polygon')?this.POLYGON_SHAPE:
(type == 'rectangle')?this.RECTANGLE_SHAPE:null;
switch(this._type)
{
case this.CIRCLE_SHAPE:
console.log('shape: circle');
console.log('latlngs: ' + latlngs);
this._shape = L.circle(latlngs, latlngs.distanceTo(latlngs));
break;
case this.LINE_SHAPE:
console.log('shape: polyline');
break;
case this.POLYGON_SHAPE:
console.log('shape: polygon');
break;
case this.RECTANGLE_SHAPE:
console.log('shape: rectangle');
break;
}
if(this._shape != null)
{
console.log('shape is created');
this._id = BEGIN_NUMBER_SHAPE++;
this._layer = L.featureGroup();
this._map.addLayer(this._layer);
this._layer.addLayer(this._shape);
}
this._map.on('click', this._onMouseClick);
this._map.on('mousemove', this._onMouseMove);
this._map.on('contextmenu', this._onMouseContextMenu);
}
},
_onMouseClick: function(e)
{
console.log('_onMouseClick');
console.log('current number shape: ' + this._id);
console.log('type shape: ' + this._type);
},
_onMouseMove: function(e)
{
console.log('_onMouseMove');
},
_onMouseContextMenu: function(e)
{
console.log('_onMouseContextMenu');
}
} |