[OpenLayers-Users] Add a button onto openlayers

Andreas Hocevar ahocevar at opengeo.org
Tue Jun 16 08:36:10 EDT 2009


Hi,

have a look at the source of [1]. The button panel is made visible
with proper css, as shown in the example source. To add a custom
button, do something like the following (based on [1]):

<style type="text/css>
[...]
.olControlPanel .customControlItemInactive {
    width: 16px;
    height: 16px;
    background-image: url('custom_inactive.png');
}
.olControlPanel customControlItemActive {
    width: 16px;
    height: 16px;
    background-image: url('custom_active.png');
}
</style>
<script type="text/javascript">
[...]
panel.addControls(new OpenLayers.Control.Button({
    trigger: function() {
        // your action here
    },
    displayClass: "customControl"
})
</script>

The CSS selector for the inactive button is displayClass of your
button plus "ItemInactive", and for the active button it is
displayClass plus "ItemActive".

That's it.

Regards,
Andreas.

[1] http://www.openlayers.org/dev/examples/panel.html

On Tue, Jun 16, 2009 at 2:18 PM, Kwong Hu Kiu<kwonghu at hotmail.com> wrote:
> Hi,
>
> Anyone knows how I can add a button on the map ?
>
> Similar stuff like that Mapfish has done but I encountered conflicts
> integrating Mapfish with openlayers.
>
> Similar to this.
> http://websamples.thinkgeo.com/webeditionsamples/
>
> Notice the instructions panel ? I want to put a button on the panel so users
> can generate and download maps.
>
> Kind regards,
> Kwong
>
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
>



-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.



More information about the Users mailing list