[OpenLayers-Users] re stricting path creation
ibarkley
ian.barkley at CATLINUSA.COM
Fri Nov 2 17:27:32 EDT 2007
Christopher, thanks for the reply. I've tried featureAdded, along with
onFeatureInsert, and I receive the follow error: this.point has no
properties: this.point.destroy(); this errors gracefully in FF2, but not in
IE (pick a version). I've modified an example from the examples page to
describe my problem (and error):
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
#map {
width: 512px;
height: 350px;
border: 1px solid gray;
}
#controlToggle li {
list-style: none;
}
p {
width: 512px;
}
</style>
<script src="../JS/OpenLayers-2.5/OpenLayers.js"></script>
<script type="text/javascript">
var f;
var map, drawControls;
OpenLayers.Util.onImageLoadErrorColor = "transparent";
function init(){
map = new OpenLayers.Map('map');
var wmsLayer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'});
var pointLayer = new OpenLayers.Layer.Vector("Point Layer");
var lineLayer = new OpenLayers.Layer.Vector("Line Layer");
var polygonLayer = new OpenLayers.Layer.Vector("Polygon Layer");
map.addLayers([wmsLayer, pointLayer, lineLayer, polygonLayer]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.MousePosition());
var options = {handlerOptions: {freehand: false}};
drawControls = {
point: new
OpenLayers.Control.DrawFeature(pointLayer,OpenLayers.Handler.Point),
line: new
OpenLayers.Control.DrawFeature(lineLayer,OpenLayers.Handler.Path),
select: new OpenLayers.Control.SelectFeature(lineLayer),
polygon: new OpenLayers.Control.DrawFeature(polygonLayer,
OpenLayers.Handler.Polygon, options)
};
drawControls.line.featureAdded =
function(){toggleControl({value:"select"});}
for(var key in drawControls) {
map.addControl(drawControls[key]);
}
map.setCenter(new OpenLayers.LonLat(0, 0), 3);
document.getElementById('noneToggle').checked = true;
}
function toggleControl(element) {
for(key in drawControls) {
var control = drawControls[key];
if(element.value == key && element.checked) {
control.activate();
} else {
control.deactivate();
}
}
}
</script>
</head>
<body onload="init()">
<h1>OpenLayers Draw Feature Example</h1>
<div id="map"></div>
<ul id="controlToggle">
<li>
<input type="radio" name="type" value="none" id="noneToggle"
onclick="toggleControl(this);" checked="checked" />
<label for="noneToggle">navigate</label>
</li>
<li>
<input type="radio" name="type" value="point"
id="pointToggle" onclick="toggleControl(this);" />
<label for="pointToggle">draw point</label>
</li>
<li>
<input type="radio" name="type" value="line" id="lineToggle"
onclick="toggleControl(this);" />
<label for="lineToggle">draw line</label>
</li>
<li>
<input type="radio" name="type" value="polygon"
id="polygonToggle" onclick="toggleControl(this);" />
<label for="polygonToggle">draw polygon</label>
</li>
</ul>
</body>
</html>
I hope this helps. And again, any help for this newbie is appreciated..
Ian Barkley
Christopher Schmidt-4 wrote:
>
> On Fri, Nov 02, 2007 at 01:00:52PM -0700, ibarkley wrote:
>>
>> Hello All (newbie question),
>> I've been swimming in OpenLayers for about a month now, and I have a very
>> simple problem, but for some reason, I can't get it to work: Whenever I
>> use
>> a callback for the 'done' property for OpenLayers.Control.DrawFeature and
>> OpenLayers.Handler.Path, the path disappears. What I'm trying to
>> accomplish
>> is when a user draws a path, after the doubleclick, I need the control to
>> change to select, or hover; therefore not allowing the user the ability
>> to
>> create more paths on the map. Is this possible? can someone post some
>> sort
>> of example that shows this? any help is much, much appreciated...
>
> You don't want to hook into the callback on the handler. Instead, you
> want to hook into (probably) featureAdded on the DrawFeature control --
> drawControl.featureAdded = function() { activate_my_control(); }
>
> Regards,
> --
> Christopher Schmidt
> MetaCarta
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
>
--
View this message in context: http://www.nabble.com/restricting-path-creation-tf4739952.html#a13556573
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list