ol2 icon indicating copy to clipboard operation
ol2 copied to clipboard

OpenLayers attempts to load default CSS file even with theme: null

Open mizzao opened this issue 12 years ago • 11 comments

I'm using OpenLayers with Meteor, a highly dynamic interactive web framework (http://www.meteor.com/). With the way Meteor works, we can't just stick a bunch of JS and CSS on the page, so I'm trying to control the way OpenLayers loads its images and themes.

I am trying to specify the ImgPath manually as well as adding a manual CSS link. I am also explicitly telling OpenLayers to not attempt to load the CSS with Javascript:

<link rel="stylesheet" href="http://dev.openlayers.org/releases/OpenLayers-2.13.1/theme/default/style.css" type="text/css">
  OpenLayers.ImgPath = "http://dev.openlayers.org/releases/OpenLayers-2.13/img/";

  map = new OpenLayers.Map 'map',
    layers: [mapLayer, vectorLayer, cursorLayer]
    maxExtent: extent
    restrictedExtent: extent
    resolutions: resolutions
    serverResolutions: serverResolutions
    theme: null # don't attempt to load theme from default path

However, when my app runs, OL attempts to load the default CSS link relatively anyway. This results in a Meteor application bundle being served, because of how Meteor works:

Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://192.168.56.101:3000/client/compatibility/theme/default/style.css". 

Is there any way to turn off the auto theme loading more forcefully or is this a bug?

mizzao avatar Aug 05 '13 16:08 mizzao

Try :

theme: false

or simply omit it.

seuros avatar Sep 12 '13 15:09 seuros

Both theme: null and theme: false are giving the same behavior, although I discovered that this may be due to the overview map loading the theme a second time. Will look into it.

mizzao avatar Sep 12 '13 19:09 mizzao

I can confirm, OverviewMap control is loading default theme. You have to specify theme: null for OverviewMap options, I can send you sample tomorrow. I had the same problem and just manged to solve it.

gawelczyk avatar Sep 12 '13 19:09 gawelczyk

I'm doing this for both Map and OverviewMap but the style css load is still showing up. theme: false doesn't work either. What else could be doing it?

  map = new OpenLayers.Map 'map',
    layers: # ...
    # ... other properties
    theme: null # don't attempt to load theme from default path
    controls: # ...

  map.addControl(new OpenLayers.Control.OverviewMap
    theme: null # again, don't load theme
  )

This is using 2.13.1.

image

mizzao avatar Sep 18 '13 23:09 mizzao

You should send that to the mapOptions property

 map.addControl(new OpenLayers.Control.OverviewMap
   mapOptions:
       theme: null 
 )

seuros avatar Sep 19 '13 09:09 seuros

That's convoluted. OverviewMap should inherit options like this from the normal map. Oh well...

mizzao avatar Sep 19 '13 15:09 mizzao

Since you are setting this property for an instance of OpenLayers.Map, there is no way an unrelated instance of OpenLayers.Control.OverviewMap can inherit this, right?

marcjansen avatar Sep 24 '13 06:09 marcjansen

an overviewmap always has a relation to a map, since it is added as a control to the map

mprins avatar Sep 24 '13 09:09 mprins

Good point, @mprins .

So when the mapOptions of the Control.OverviewMap do not specify theme, we should not default to something, but to the value of theme of the OpenLayers.Map it is bound to, right?

I'd be in favor of a change like the one above.

marcjansen avatar Sep 26 '13 07:09 marcjansen

I'm not unhappy with the way it is now (since I learned from the code), but to me it seems logical to inherit things like from theme, projection, units etc. from the O.Map containing the control ( I know some of these may actually be Layer props)

mprins avatar Sep 26 '13 15:09 mprins

In my javascript code within meteor client, how can i acess the OSM using openlayers? I have added the package for openlayers but my javascript function is not recognising the openlayer object

var osm = new OpenLayers.Layer.OSM("OpenLayers OSM"); says unresolved variable if i hover on openlayers

tracethepath avatar Apr 29 '15 09:04 tracethepath