My project has to use imagelayer to show map , it can create box on map, box will be a area to put device marker on top , but when the box is too small , there will be a bug in project..., so is there some one who can tell me how to prevent this from happening?
The code is below:
// map init
$map = new OpenLayers.Map("gmap");
$map.addControl(new OpenLayers.Control.MousePosition());
//add basic layer
$map.addLayers([new OpenLayers.Layer.Image(
'Main Layer',
'images/ec/area/area1.jpg',
new OpenLayers.Bounds(0, 0, 2565, 1293),
new OpenLayers.Size(1282.5, 646.5),
{layers: 'basic'}
)]);
//add vector Layer to map
vectorLayer = new OpenLayers.Layer.Vector("Overlay");//Area layer
vectorLayer1 = new OpenLayers.Layer.Vector("Overlay1");//device layer
$map.addLayers([vectorLayer,vectorLayer1]);
selectControl = {
selector: new OpenLayers.Control.SelectFeature([vectorLayer,vectorLayer1], {
onSelect: createPopup,
onUnselect: destroyPopup
}),
box : new OpenLayers.Control.DrawFeature(vectorLayer,
OpenLayers.Handler.RegularPolygon, {
handlerOptions: {
sides: 4,
irregular: true
},
callbacks: {
up: function(geometry){
if( geometry.getArea() < 2500 ){
alert("Box too small can not be create!");
return false; //still can not return false!!!!
}
}
}
}
)
};
//this can log Area Size But can not return false!!
selectControl["box"].handler.callbacks.create = function(data) {
if(data.getArea() < 2500){
console.log("Area Size:"+data.getArea());
return false;
}
}
Should I check when the box too small then remove it?
Or how to prevent the create box when the box is too small?
Bug
actually is ..