Opened 6 years ago

Last modified 2 years ago

#16916 assigned defect

OpenLayers widget creation broken in Dojo 1.8

Reported by: Rubbinio Owned by: Patrick Ruzand
Priority: undecided Milestone: 1.15
Component: Dojox Version: 1.8.3
Keywords: Cc: cjolif
Blocked By: Blocking:

Description

In Dojo 1.8 creating an openLayers map in a programmatic way as a child of another widget (i.e. a border container) is not working any more.

The code below work in Dojo 1.7 but breaks as soon as you upgrade to 1.8.

this.tracking.map = new Map({ 	 
    baseLayerType : dojox.geo.openlayers.BaseLayerType.OSM, 	 
    style : "width : 100%, height: 100%", 	 
    region : "center" 	 
});

The only way we managed to make it work is to create an empty div tag in the page and place the map inside that div which defeats the purpose of creating widgets programmatic.

What we are doing now is add a div to the border container and then create the map like this:

  • in the jsp we added:
<div data-dojo-id="mapContentPane"
     data-dojo-type="dijit.layout.ContentPane"
     data-dojo-props="splitter:true, region: 'center'">
     <div id="map" style="width: 100%; height: 100%;"></div>
</div>	
  • and then in javascript:
this.tracking.map = new Map({}, "map");
this.tracking.map.startup();

This appears to have been broken when ticket #15525 was fixed. If we reverse the change in that ticket everything starts working in 1.8 as well.

Change History (6)

comment:1 Changed 6 years ago by Rubbinio

This happens in openLayers - APIMethod: getZoomForExtent

  • extent has a width and height
  • viewSize is null
     /**
      * APIMethod: getZoomForExtent
      *
      * Parameters:
      * extent - {<OpenLayers.Bounds>}
      * closest - {Boolean} Find the zoom level that most closely fits the
      *     specified bounds. Note that this may result in a zoom that does
      *     not exactly contain the entire extent.
      *     Default is false.
      *
      * Returns:
      * {Integer} The index of the zoomLevel (entry in the resolutions 
array)
      *     for the passed-in extent. We do this by calculating the ideal
      *     resolution for the given extent (based on the map size) and 
then
      *     calling getZoomForResolution(), passing along the 'closest'
      *     parameter.
      */
     getZoomForExtent: function(extent, closest) {
         var viewSize = this.map.getSize();
         var idealResolution = Math.max( extent.getWidth()  / viewSize.w,
                                         extent.getHeight() / viewSize.h );

         return this.getZoomForResolution(idealResolution, closest);
     },

comment:2 Changed 6 years ago by bill

Cc: cjolif added
Component: GeneralDojox
Owner: set to Patrick Ruzand
Status: newassigned

If no one owns the dojox/geo code anymore, shall we close this and #16399 as patchwelcome?

comment:3 Changed 6 years ago by cjolif

Indeed nobody "owns" this anymore... That said if Patrick could give it a look it would be good. And then we will decide based on his analysis.

comment:4 Changed 5 years ago by owainb

I came up against this problem and I have put a workaround into my code which seems to fix the issue. The problem is that the widget creates a new div with zero size, which when passed to OpenLayers? causes the null size as described. I have made the following change to dojox/geo/openlayers/widget/Map.js

buildRendering: function(){
	// summary:
	//		Construct the UI for this widget, creates the real dojox.geo.openlayers.Map object.		
	// tags:
	//		protected
	this.inherited(arguments);
	var div = this.domNode;
+	div.style.height = "1px";
+	div.style.width = "1px";
	var map = new Map(div, {
		baseLayerType: this.baseLayerType,
		touchHandler: this.touchHandler
	});
	this.map = map;

	this._makeLayers();
}

I based this on what OpenLayers? does in the Map initialize function when the div is null

if(!this.div) {
	this.div = document.createElement("div");
	this.div.style.height = "1px";
	this.div.style.width = "1px";
}

Having not worked with dojo or OpenLayers? for long I'm not entirely sure if this will have any side-effects but it seems OK to me. If this a suitable fix, could someone add it in please.

comment:5 Changed 3 years ago by dylan

Milestone: tbd1.12

comment:6 Changed 2 years ago by dylan

Milestone: 1.131.15

Ticket planning... move current 1.13 tickets out to 1.15 to make it easier to move tickets into the 1.13 milestone.

Note: See TracTickets for help on using tickets.