OpenLayers OpenLayers

Ticket #460 (closed feature: fixed)

Opened 2 years ago

Last modified 2 years ago

full CSS support

Reported by: tschaub Assigned to:
Priority: minor Milestone: 2.4 Release
Component: general Version:
Keywords: Cc:
State:

Description

With the current "on demand" stylesheet loading, a single map property (theme) determines the location of the stylesheet. This single stylesheet is loaded when the map is initialized. When the styles are actually applied can't really be determined. To customize the style of a single element, you would edit the style.css or make your own copy.

Pretend I'm building an application that uses OL and I only want to change the background color of the overview map container.

Currently, I would do one of two things:

1) Dig into theme/default/style.css and edit the declarations. This doesn't work well if I'm using the same library for more than one application. Also, if I upgrade OL, I lose my customizations.

2) Copy the entire style.css into mystyle.css, edit the section I'm interested in, and set the theme property of the main map and the overview map

  var map = new OpenLayers.Map('map', {theme: 'mystyle.css'});
  var ov = new OpenLayers.Control.OverviewMap({mapOptions: {theme: 'mystyle.css'}});

This doesn't work well if I upgrade OL and there is a new class name that I don't know about, or the class name of some other element I don't care about changes. I'm stuck with my single (outdated) stylesheet.

If the default theme had been added in a regular <style> tag, my application could simply do (after the default style tag)

<style type="text/css">
  .olControlOverviewMapElement {
    background-color: purple;
  }
</style>

By cascading styles, if I upgrade OL and some other class name changes or a new one is introduced, my application will still work well. Also, I can use the same library with the same default style for any number of applications - each with their own style.

Attachments

css.patch (3.1 kB) - added by tschaub on 03/21/07 18:52:39.
allows for css

Change History

03/08/07 13:25:24 changed by sderle

  • milestone changed from 2.4 Release to 2.5 Release.

03/21/07 18:52:05 changed by tschaub

This can make it in to 2.4 with a pretty simple patch. With the following patch, if you want better css support, you do three things:

1) include the default stylesheet above your script tag

   <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />

2) include any non-default style declarations below the default stylesheet

    <style type="text/css">
        div.olControlMousePosition {
            color: red;
        }
    </style>

3) construct your map with options that include {theme: null}

    var options = {theme: null};
    var map = new OpenLayers.Map('map', options);

If a map's theme property is null (or false), the default stylesheet will not be appended to the dom via the old method. This allows application designers to modify the default style without editing default/style.css.

This doesn't get around the issues created by appending link elements to the head programmatically. Namely, an application designer can no longer roll through document.styleSheets without the browser giving them trouble. However, unless this is a problem for anybody else at this point, I think this should go in 2.4.

03/21/07 18:52:39 changed by tschaub

  • attachment css.patch added.

allows for css

03/21/07 18:53:20 changed by tschaub

  • keywords set to review.
  • milestone changed from 2.5 Release to 2.4 Release.

please review

03/22/07 07:22:04 changed by sderle

  • status changed from new to closed.
  • resolution set to fixed.

Applied as r2844. On second thought, a unit test or two would be really nice.

03/22/07 14:55:12 changed by tschaub

  • keywords deleted.

tests added to test_Map.js with r2855