[OpenLayers-Users] Controls

Tondo gpktondo at gmail.com
Thu Nov 3 07:06:00 EDT 2011


Hi 

I was told to create a web map app as my seminar work. I'm supposed to use
HTML/PHP/JavaScript so I was happy when found OL - yeah just one more noob.
But I've got some problems I can't solve... Could you help me plz?

#1:

the code's simple...

/var scaleBar = new OpenLayers.Control.ScaleLine({bottomOutUnits: '',
bottomInUnits: ''});
var scaleAbc = new OpenLayers.Control.Scale();
var mousePos = new OpenLayers.Control.MousePosition({prefix: 'X: ',
separator: ', Y: '});
var navigation = [scaleAbc, mousePos, scaleBar,
 new OpenLayers.Control.PanPanel(),
 new OpenLayers.Control.ZoomPanel()
 ];/

I add navigation array via /map.addLayers()/ method, but every single time I
open page scale or mouse position or scaleline are missing. Not sure what's
wrong sometimes I miss scale sometimes both scaleLine and scale now for
example I'm missing mouse position. I put /Alert(<variables>)/ after every
single var line to make sure every object was created and I got 3 alerts
with response ''object'', so I suppose all of 'em were created... Note, that
if I add controls to the array via /new <constructor>/, they are added to
the map correctly... any idea why?

#2

I'm supposed to create a few toggle buttons and display map controls only
when toggled. The code's here:

---CSS---
/.getScaleToggleItemActive {
background: url("ICO/MyIcos/ScaleOn.png") no-repeat;
cursor: pointer;
height: 32px;
width: 32px;
}
.getScaleToggleItemInactive {
background: url("ICO/MyIcos/ScaleOff.png") no-repeat;
cursor: pointer;
height: 32px;
width: 32px;
}/

---JS---
/function getScale() {
map.addControl(scaleBar);
map.addControl(scaleAbc);
}
function removeScale() {
map.removeControl(scaleBar);
map.removeControl(scaleAbc); 
} 
var scaleButton = new OpenLayers.Control.Button({
displayClass: 'getScaleToggle',
eventListeners: { 
'activate': getScale,
'deactivate': removeScale
},
type: OpenLayers.Control.TYPE_TOGGLE
});/

Button added to the Control Panel and Panel added to the map via
/map.addControl()/ method - looks simple. When page's reloaded, control's
invisible. On first click, it turns on, both controls are visible. On 2nd
click, it turns off, both controls are removed from the map. On third click,
it turns on again, but nothing's changed. I can simply add those controls
only once. Again I tried to put simple /Alert('on');/ to function /getScale/
and /Alert('off);/ to function /removeScale/. Those functions are called
correctly. I dont know, why it's not working. I tried also other way...
here's the code:

/function addControl(Input){
map.addControl(Input);
}
function remControl(Input){
map.removeControl(Input);
}

var scale = new OpenLayers.Control.Button({
displayClass: 'getScaleToggle',
eventListeners: { 
'activate': addControl(scaleBar),
'deactivate': remControl(scaleBar)
},
type: OpenLayers.Control.TYPE_TOGGLE
});/

This time nothing happens... If I pass /activate': addControl(new
OpenLayers.Control.ScaleLine ({bottomOutUnits: '', bottomInUnits: ''}))/
instead, the control's visible instantly without clicking the button.

#3

This one's gonna be little complicated. Our server got 50 layers, published
by GeoServer 2.0.2, WFS.  I'm supposed to test WFS-T, attribute and spatial
filters and speed loss when added multiple layers (up to 50) to the map
window. I got idea how to do it but I'm C++/VB.NET, not HTML/JS. I need to
add the control panel to the map with ComboBox(you will have to choose layer
you would like to edit). I tried some ways via  <div> but one way the div
moves the entire controls and map, or (if used position:absolute) it's not
visible when map's loaded. Any ideas how to solve this pls?

OS: Win7 32bit Ultimate (virtual drive - pls don't ask me why ;)
OL: 2.10
Browsers: FireFox, Chrome

Thanks a lot for any help.

Tom.

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Controls-tp6958626p6958626.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list