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',
    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

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;

screen shot is hre

Should I check when the box too small then remove it?

Or how to prevent the create box when the box is too small?

  • Exactly WHAT is teh bug?? It will help to know .. Oct 11, 2014 at 11:07
  • 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... Oct 11, 2014 at 11:13
  • Ok, WHAT is the bug, please post a screen shot ro something to describe what the Bug actually is .. Oct 11, 2014 at 11:14
  • sorry for i do not use this post... thanks all expert..... Oct 11, 2014 at 12:48
  • Probably you have a conflict in the SRS between the data layer and the Vector Layer you are drawing the Box on .. What is the EPSG of the base layer .. try making them the same .. Oct 11, 2014 at 14:41

1 Answer 1


My friend Chris help me to resolve the problem and the answer will be like this: http://jsfiddle.net/v18kuxgf/

polygonLayer.events.register('featureadded', null, function(event) {
                        var feature = event.feature,
                            geometry = feature.geometry;
                        if (geometry.getArea() < 2500) {
                            alert('Box too small to create!');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.