I have a pretty basic setup of a map with openlayers, and just 3 controls, built in an MVC project. For soem reason though, the navigation control and the panzoombar do not show (although the mouseposition one does). I see them for an instant while the map loads, but then they disappear. Below is my code that i use to make this happen. Can anyone tell me what i’m doing wrong?
function initNormMap() {
var map;
OpenLayers.DOTS_PER_INCH = 72;
map = new OpenLayers.Map('divmap', {
controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.MousePosition()
], units: 'm',
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326")
});
//http://trac.osgeo.org/openlayers/wiki/AvailableWMSServices
var ol_wms = new OpenLayers.Layer.WMS("OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0",
{ layers: 'basic' });
var osm_wms = new OpenLayers.Layer.OSM();
map.addLayers([osm_wms]);
var fromProjection = new OpenLayers.Projection("EPSG:4326"); // Transform from WGS 1984
var toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
var position = new OpenLayers.LonLat(-98, 39).transform(fromProjection, toProjection);
var zoom = 4;
map.setCenter(position, zoom);
}
Problem turned out to be with MVC4 bundling, which doesn’t seem to work well with openlayers at all. I had in my BundleConfig.cs file:
and in my actual .cshtml page:
I even tried it without the CDNPath, and still got the same issue each time. changed to just straight
and it works fine.