| 1 | define([ |
| 2 | "dojo/_base/lang", |
| 3 | "dojo/_base/declare", |
| 4 | "dojo/_base/array", |
| 5 | "dojo/dom-geometry", |
| 6 | "dojo/query", |
| 7 | "dijit/_Widget", |
| 8 | "../_base", |
| 9 | "../Map", |
| 10 | "../Layer", |
| 11 | "../GfxLayer" |
| 12 | ], function(lang, declare, array, domgeo, query, Widget, openlayers, Map, Layer, GfxLayer){ |
| 13 | |
| 14 | return declare("dojox.geo.openlayers.widget.Map", Widget, { |
| 15 | // summary: |
| 16 | // A widget version of the `dojox.geo.openlayers.Map` component. |
| 17 | // description: |
| 18 | // The `dojox.geo.openlayers.widget.Map` widget is the widget |
| 19 | // version of the `dojox.geo.openlayers.Map` component. |
| 20 | // With this widget, user can specify some attributes in the markup such as |
| 21 | // |
| 22 | // - `baseLayerType`: The type of the base layer. Permitted values are |
| 23 | // - `initialLocation`: The initial location as for the dojox.geo.openlayers.Map.fitTo method |
| 24 | // - `touchHandler`: Tells if we attach touch handler or not. |
| 25 | // |
| 26 | // example: |
| 27 | // | <div id="map" dojoType="dojox.geo.openlayers.widget.Map" baseLayerType="Google" initialLocation="{ |
| 28 | // | position: [7.154126, 43.651748], |
| 29 | // | extent: 0.2 }" |
| 30 | // | style="background-color: #b5d0d0; width: 100%; height: 100%;"> |
| 31 | // |
| 32 | |
| 33 | // baseLayerType: String |
| 34 | // Base layer type as defined in `dojox.geo.openlayer.BaseLayerType`. Can be one of: |
| 35 | // |
| 36 | // - `OSM` |
| 37 | // - `WMS` |
| 38 | // - `Google` |
| 39 | // - `VirtualEarth` |
| 40 | // - `Yahoo` |
| 41 | // - `ArcGIS` |
| 42 | baseLayerType: openlayers.BaseLayerType.OSM, |
| 43 | |
| 44 | // initialLocation: String |
| 45 | // The part of the map shown at startup time. It is the string description of the location shown at |
| 46 | // startup time. Format is the same as for the `dojox.geo.openlayers.widget.Map.fitTo` |
| 47 | // method. |
| 48 | // | { |
| 49 | // | bounds: [ulx, uly, lrx, lry] |
| 50 | // | } |
| 51 | // The map is fit on the specified bounds expressed as decimal degrees latitude and longitude. |
| 52 | // The bounds are defined with their upper left and lower right corners coordinates. |
| 53 | // |
| 54 | // | { |
| 55 | // | position: [longitude, latitude], |
| 56 | // | extent: degrees |
| 57 | // | } |
| 58 | // The map is fit on the specified position showing the extent `<extent>` around |
| 59 | // the specified center position. |
| 60 | initialLocation: null, |
| 61 | |
| 62 | // touchHandler: Boolean |
| 63 | // Tells if the touch handler should be attached to the map or not. |
| 64 | // Touch handler handles touch events so that the widget can be used |
| 65 | // on mobile applications. |
| 66 | touchHandler: false, |
| 67 | |
| 68 | // map: [readonly] Map |
| 69 | // The underlying `dojox/geo/openlayers/Map` object. |
| 70 | map : null, |
| 71 | |
| 72 | startup: function(){ |
| 73 | // summary: |
| 74 | // Processing after the DOM fragment is added to the document |
| 75 | this.inherited(arguments); |
| 76 | this.map.initialFit({ |
| 77 | initialLocation: this.initialLocation |
| 78 | }); |
| 79 | }, |
| 80 | |
| 81 | buildRendering: function(){ |
| 82 | // summary: |
| 83 | // Construct the UI for this widget, creates the real dojox.geo.openlayers.Map object. |
| 84 | // tags: |
| 85 | // protected |
| 86 | this.inherited(arguments); |
| 87 | var div = this.domNode; |
| 88 | var map = new Map(div, { |
| 89 | baseLayerType: this.baseLayerType, |
| 90 | touchHandler: this.touchHandler |
| 91 | }); |
| 92 | this.map = map; |
| 93 | |
| 94 | this._makeLayers(); |
| 95 | }, |
| 96 | |
| 97 | _makeLayers: function(){ |
| 98 | // summary: |
| 99 | // Creates layers defined as markup. |
| 100 | // tags: |
| 101 | // private |
| 102 | var n = this.domNode; |
| 103 | var layers = /* ?? query. */query("> .layer", n); |
| 104 | array.forEach(layers, function(l){ |
| 105 | var type = l.getAttribute("type"); |
| 106 | var name = l.getAttribute("name"); |
| 107 | var cls = "dojox.geo.openlayers." + type; |
| 108 | var p = lang.getObject(cls); |
| 109 | if(p){ |
| 110 | var layer = new p(name, {}); |
| 111 | if(layer){ |
| 112 | this.map.addLayer(layer); |
| 113 | } |
| 114 | } |
| 115 | }, this); |
| 116 | }, |
| 117 | |
| 118 | resize : function(b,h){ |
| 119 | // summary: |
| 120 | // Resize the widget. |
| 121 | // description: |
| 122 | // Resize the domNode and the widget to the dimensions of a box of the following form: |
| 123 | // `{ l: 50, t: 200, w: 300: h: 150 }` |
| 124 | // b: Object|Number? |
| 125 | // If passed, denotes the new size of the widget. |
| 126 | // Can be either nothing (widget adapts to the div), |
| 127 | // an Object describing a box, or a Number representing the width. |
| 128 | // h: Number? |
| 129 | // The new height. Requires that a width has been specified in the first parameter. |
| 130 | |
| 131 | var olm = this.map.getOLMap(); |
| 132 | |
| 133 | var box; |
| 134 | switch(arguments.length){ |
| 135 | case 0: |
| 136 | // case 0, do not resize the div, just the surface |
| 137 | break; |
| 138 | case 1: |
| 139 | // argument, override node box |
| 140 | box = lang.mixin({}, b); |
| 141 | domgeo.setMarginBox(olm.div, box); |
| 142 | break; |
| 143 | case 2: |
| 144 | // two argument, width, height |
| 145 | box = { |
| 146 | w: arguments[0], |
| 147 | h: arguments[1] |
| 148 | }; |
| 149 | domgeo.setMarginBox(olm.div, box); |
| 150 | break; |
| 151 | } |
| 152 | olm.updateSize(); |
| 153 | } |
| 154 | }); |
| 155 | }); |