From 058a979a6a795d390856b471db713379263addf0 Mon Sep 17 00:00:00 2001 From: Alex Speller Date: Sun, 7 Dec 2014 16:44:05 +0000 Subject: [PATCH] Update popup in the afterRender queue When the popup is first rendered, it may be a different size than after ember finishes rendering. This change ensures the popup will always be visible if autoPan is enabled (the default) --- dist/ember-leaflet.js | 10 ++++++++-- dist/ember-leaflet.min.js | 6 +++--- packages/ember-leaflet/lib/mixin/popup.js | 6 ++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/dist/ember-leaflet.js b/dist/ember-leaflet.js index 669e264..9bddb01 100644 --- a/dist/ember-leaflet.js +++ b/dist/ember-leaflet.js @@ -1,5 +1,5 @@ -// Version: v0.6.0-1-g78d74a3 -// Last commit: 78d74a3 (2014-06-19 14:10:45 -0700) +// Version: v0.6.0-5-gdd38076 +// Last commit: dd38076 (2014-12-03 02:26:38 +0000) (function() { @@ -677,6 +677,12 @@ EmberLeaflet.PopupMixin = Ember.Mixin.create({ this._popupView._insertElementLater(function() { self._popupView.$().appendTo(self._popup._contentNode); }); + + // After the view has rendered, call update to ensure + // popup is visible with autoPan + Ember.run.schedule('afterRender', this, function() { + self._popup.update(); + }); }, _destroyPopupContent: function() { diff --git a/dist/ember-leaflet.min.js b/dist/ember-leaflet.min.js index 6e5a738..0bf0c9f 100644 --- a/dist/ember-leaflet.min.js +++ b/dist/ember-leaflet.min.js @@ -6,8 +6,8 @@ -// Version: v0.6.0-1-g78d74a3 -// Last commit: 78d74a3 (2014-06-19 14:10:45 -0700) +// Version: v0.6.0-5-gdd38076 +// Last commit: dd38076 (2014-12-03 02:26:38 +0000) -(function(){EmberLeaflet=Ember.Namespace.create()})(),function(){function e(e){return e?[e.lat,e.lng]:null}function t(e){return e?[e.lng,e.lat]:null}function r(e){return e?e.lat?e:L.latLng(e[0],e[1]):null}function i(e){return e?e.lat?e:L.latLng(e[1],e[0]):null}var n=Ember.get,o=Ember.set;EmberLeaflet.convert={latLngArrayFromLatLng:e,lngLatArrayFromLatLng:t,latLngFromLatLngArray:r,latLngFromLngLatArray:i},EmberLeaflet.computed={},EmberLeaflet.computed.latLngFromLngLatArray=function(e){return Ember.computed(e,function(r,a){return 1===arguments.length?i(n(this,e)):(o(this,e,t(a)),a)})},EmberLeaflet.computed.latLngFromLatLngArray=function(t){return Ember.computed(t,function(i,a){return 1===arguments.length?r(n(this,t)):(o(this,t,a=e(a)),a)})},EmberLeaflet.computed.optionProperty=function(e){return Ember.computed("options",function(t,r){if(t=e||t,arguments.length>1){var i="set"+Ember.String.classify(t);return Ember.assert(this.constructor+" must have a "+i+" function.",!!this._layer[i]),this._layer[i].call(this._layer,r),r}return this._layer.options[t]})}}(),function(){var e=(Ember.String.fmt,Ember.EnumerableUtils.forEach),t=Ember.get;EmberLeaflet.LayerMixin=Ember.Mixin.create({_layer:null,_parentLayer:null,isVirtual:!1,_childLayers:[],concatenatedProperties:["events"],parentLayer:Ember.computed.alias("_parentLayer").readOnly(),layer:Ember.computed(function(){return this._layer}).property(),_newLayer:Ember.required(Function),willCreateLayer:Ember.K,didCreateLayer:Ember.K,willDestroyLayer:Ember.K,didDestroyLayer:Ember.K,events:[],_createLayer:function(){Ember.assert("Parent layer must be in leaflet.",!!this._parentLayer._layer),this.willCreateLayer(),this.isVirtual||(this.propertyWillChange("layer"),this._layer=this._newLayer(),this._addEventListeners(),this._addToParent(),this.propertyDidChange("layer")),this.didCreateLayer()},_destroyLayer:function(){this.willDestroyLayer(),this.isVirtual||(this.propertyWillChange("layer"),this._removeEventListeners(),this._removeFromParent(),this._layer=null,this.propertyDidChange("layer")),this.didDestroyLayer()},_addToParent:function(){this._parentLayer._addChild(this._layer)},_removeFromParent:function(){this._parentLayer._removeChild(this._layer)},_addChild:function(e){this._layer.addLayer(e)},_removeChild:function(e){this._layer.removeLayer(e)},_addEventListeners:function(){this._eventHandlers={},e(t(this,"events"),function(e){"function"==typeof this[e]&&(this._eventHandlers[e]=function(t){Ember.run(this,this[e],t)},this._layer.addEventListener(e,this._eventHandlers[e],this))},this)},_removeEventListeners:function(){e(t(this,"events"),function(e){"function"==typeof this[e]&&(this._layer.removeEventListener(e,this._eventHandlers[e],this),delete this._eventHandlers[e])},this)}}),EmberLeaflet.Layer=Ember.Object.extend(EmberLeaflet.LayerMixin,{}),EmberLeaflet.EmptyLayer=EmberLeaflet.Layer.extend({_newLayer:function(){return L.layerGroup([])}})}(),function(){var e=Ember.get,t=(Ember.set,Ember.String.fmt),r=Ember.EnumerableUtils.forEach,i=Ember.EnumerableUtils.map;EmberLeaflet.ContainerLayerMixin=Ember.Mixin.create(EmberLeaflet.LayerMixin,Ember.MutableArray,{_childLayers:null,didCreateLayer:function(){this._super(),this.createAndAddChildLayers()},willDestroyLayer:function(){this.removeAndDestroyChildLayers(),this._super()},createAndAddChildLayers:function(){var t,i=this._childLayers=Ember.A(),n=this;void 0===this._childLayerClasses&&(this._childLayerClasses=e(this,"childLayers")||[]),Ember.defineProperty(this,"childLayers",Ember.computed(function(){return this._childLayers})),r(this._childLayerClasses,function(e,r){t=n.createChildLayer(e),n.addChildLayer(t),i[r]=t},this)},replace:function(t,r,n){var o=n?e(n,"length"):0,a=this;if(this.arrayContentWillChange(t,r,o),this.childLayersWillChange(this._childLayers,t,r),0===o)this._childLayers.splice(t,r);else{n=i(n,function(e){return a.createChildLayer(e)});var s=[t,r].concat(n);n.length&&!this._childLayers.length&&(this._childLayers=this._childLayers.slice()),this._childLayers.splice.apply(this._childLayers,s)}return this.arrayContentDidChange(t,r,o),this.childLayersDidChange(this._childLayers,t,r,o),this},objectAt:function(e){return this._childLayers[e]},length:Ember.computed(function(){return this._childLayers.length}),childLayersWillChange:function(e,t,i){var n=this;if(this.propertyWillChange("childLayers"),i>0){var o=e.slice(t,t+i);r(o,function(e){n.removeChildLayer(e)})}},childLayersDidChange:function(e,t,i,n){var o=this;if(n>0){var a=e.slice(t,t+n);r(a,function(e){o.addChildLayer(e)})}this.propertyDidChange("childLayers")},addChildLayer:function(e){e._createLayer()},removeChildLayer:function(e){e._destroyLayer()},createChildLayer:function(e,r){r=r||{},r.container=this.get("container"),r.controller=this.get("controller"),r._parentLayer=this.isVirtual?this._parentLayer:this;var i,n=Ember.typeOf(e);return Ember.assert(t("layerClass %@ must be an Ember instance or class.",e?e.toString():""),"instance"===n||"class"===n),"instance"===n?(i=e,i.setProperties(r)):"class"===n&&(i=e.create(r)),i},removeAndDestroyChildLayers:function(){var e=this;this._childLayers&&r(this._childLayers,function(t){e.removeChildLayer(t),t.destroy()}),this._childLayers=[]}}),EmberLeaflet.ContainerLayer=Ember.Object.extend(EmberLeaflet.ContainerLayerMixin,{_newLayer:function(){return L.layerGroup()}})}(),function(){var e=L.latLng(40.713282,-74.006978);EmberLeaflet.MapView=Ember.View.extend(EmberLeaflet.ContainerLayerMixin,{options:{},center:e,zoom:16,isMoving:!1,isZooming:!1,events:["click","dblclick","mousedown","mouseup","mouseover","mouseout","mousemove","contextmenu","focus","blur","preclick","load","unload","viewreset","movestart","move","moveend","dragstart","drag","dragend","zoomstart","zoomend","zoomlevelschange","resize","autopanstart","layeradd","layerremove","baselayerchange","overlayadd","overlayremove","locationfound","locationerror","popupopen","popupclose"],init:function(){this._super(),void 0===this.get("childLayers")&&this.set("childLayers",[EmberLeaflet.DefaultTileLayer])},didInsertElement:function(){this._super(),this._createLayer()},willDestroyElement:function(){this._destroyLayer()},_createLayer:function(){this._layer||(Ember.assert("Center must be set before creating map, was "+this.get("center"),!!this.get("center")),Ember.assert("Zoom must be set before creating map, was "+this.get("zoom"),!!this.get("zoom")),this.willCreateLayer(),this.propertyWillChange("layer"),this._layer=L.map(this.get("elementId"),this.get("options")),this._layer.setView(this.get("center"),this.get("zoom")),this._addEventListeners(),this.propertyDidChange("layer"),this.didCreateLayer())},_destroyLayer:function(){this.willDestroyLayer(),this.propertyWillChange("layer"),this._layer&&(this._defaultChildLayer&&(this._layer.removeLayer(this._defaultChildLayer),this._defaultChildLayer=null),this._removeEventListeners(),this._layer.remove(),this._layer=null,this.propertyDidChange("layer"),this.didDestroyLayer())},zoomstart:function(){this.set("isZooming",!0)},zoomend:function(){this.setProperties({isZooming:!1,zoom:this._layer.getZoom()}),this._queuedZoom&&(this._queuedZoom!==this._layer.getZoom()&&this._layer.setZoom(this._queuedZoom),this._queuedZoom=null)},movestart:function(){this.set("isMoving",!0)},moveend:function(){this.set("isMoving",!1)},move:function(){this.set("center",this._layer.getCenter())},zoomDidChange:Ember.observer(function(){this._layer&&!Ember.isNone(this.get("zoom"))&&(this._layer._animatingZoom?this._queuedZoom=this.get("zoom"):this._layer.setZoom(this.get("zoom")))},"zoom"),centerDidChange:Ember.observer(function(){this._layer&&!this.get("isMoving")&&this.get("center")&&(this._layer.getCenter().equals(this.get("center"))||this._layer.panTo(this.get("center")))},"center")})}(),function(){var e=Ember.get;EmberLeaflet.TileLayer=EmberLeaflet.Layer.extend({tileUrl:null,options:{},_newLayer:function(){return L.tileLayer(e(this,"tileUrl"),e(this,"options"))},tileUrlDidChange:Ember.observer(function(){this._layer&&this._layer.setUrl(this.get("tileUrl"))},"tileUrl"),zIndex:EmberLeaflet.computed.optionProperty(),opacity:EmberLeaflet.computed.optionProperty()}),EmberLeaflet.DefaultTileLayer=EmberLeaflet.TileLayer.extend({tileUrl:"http://a.tiles.mapbox.com/v3/examples.map-zr0njcqy/{z}/{x}/{y}.png"})}(),function(){var e=Ember.get;Ember.set,Ember.setProperties,EmberLeaflet.PopupMixin=Ember.Mixin.create({popupContent:"",popupViewClass:null,popupOptions:{offset:L.point(0,-36)},click:function(e){this._super&&this._super(e),this.openPopup(e)},dragstart:function(e){this._super&&this._super(e),this.closePopup()},openPopup:function(e){this.willOpenPopup();var t;t=this._layer.getLatLng?this._layer.getLatLng():L.latLngBounds(this._layer.getLatLngs()).getCenter(),this._popup.setLatLng(e&&e.latlng||t).openOn(this._layer._map),this._createPopupContent(),this.didOpenPopup()},closePopup:function(){this.willClosePopup(),this._layer._map.closePopup(),this.didClosePopup()},willOpenPopup:Ember.K,didOpenPopup:Ember.K,willClosePopup:Ember.K,didClosePopup:Ember.K,willCreatePopup:Ember.K,didCreatePopup:Ember.K,willDestroyPopup:Ember.K,didDestroyPopup:Ember.K,_createPopupContent:function(){if(!e(this,"popupViewClass"))return this._popup.setContent(e(this,"popupContent")),void 0;this._popupView&&this._destroyPopupContent();var t=e(this,"popupViewClass");"string"===Ember.typeOf(t)&&(t=e(this,"container").lookupFactory("view:"+t)),this._popupView=t.create({container:e(this,"container"),controller:e(this,"controller"),context:e(this,"controller"),content:e(this,"content")});var r=this;this._popupView._insertElementLater(function(){r._popupView.$().appendTo(r._popup._contentNode)})},_destroyPopupContent:function(){e(this,"popupViewClass")&&this._popupView&&(this._popupView.destroy(),this._popupView=null)},_createPopup:function(){this.willCreatePopup(),this._popup=L.popup(e(this,"popupOptions"),this._layer);var t=this._popup.onRemove,r=this;this._popup.onRemove=function(e){r._destroyPopupContent(),t.call(r._popup,e)},this.didCreatePopup()},_destroyPopup:function(){this._popup&&(this.willDestroyPopup(),this._popup._map&&this._layer&&this._layer._map&&this._layer._map.closePopup(),this._popup=null,this.didDestroyPopup())},_updatePopup:Ember.observer(function(){this._popup&&this._popup.setContent(e(this,"popupContent"))},"popupContent"),_removePopupObservers:Ember.beforeObserver(function(){this._layer&&this._destroyPopup()},"layer"),_addPopupObservers:Ember.observer(function(){this._layer&&this._createPopup()},"layer")})}(),function(){var e=Ember.get;EmberLeaflet.BoundsMixin=Ember.Mixin.create({bounds:Ember.computed(function(){var t=e(this,"locations");return t instanceof L.LatLngBounds?t:t&&e(t,"length")?L.latLngBounds(t):null}).property("locations").volatile()})}(),function(){var e=Ember.get;Ember.EnumerableUtils.forEach,EmberLeaflet.CollectionLayer=EmberLeaflet.ContainerLayer.extend({content:[],isVirtual:!0,itemLayerClass:Ember.computed(function(){throw new Error("itemLayerClass must be defined.")}).property(),didCreateLayer:function(){this._super(),this._contentDidChange()},willDestroyLayer:function(){this._contentWillChange(),this._super()},_contentWillChange:Ember.beforeObserver(function(){var t=e(this,"content");t&&t.removeArrayObserver(this);var r=t?e(t,"length"):0;this.arrayWillChange(t,0,r)},"content"),_contentDidChange:Ember.observer(function(){var t=e(this,"content");t&&t.addArrayObserver(this);var r=t?e(t,"length"):0;this.arrayDidChange(t,0,null,r)},"content"),arrayWillChange:function(e,t,r){for(var i=t;t+r>i;i++)this.objectWasRemoved(e.objectAt(i))},arrayDidChange:function(e,t,r,i){for(var n=t;t+i>n;n++)this.objectWasAdded(e.objectAt(n),n)},objectWasAdded:function(t,r){void 0===r&&(r=this._childLayers.length);var i=this.createChildLayer(e(this,"itemLayerClass"),{content:t});this.replace(r,0,[i])},objectWasRemoved:function(e){for(var t,r=0,i=this._childLayers.length;i>r;r++)if(t=this._childLayers[r],t.get("content")===e)return this.replace(r,1,[]),t.destroy(),void 0}})}(),function(){EmberLeaflet.CollectionBoundsMixin=Ember.Mixin.create(EmberLeaflet.BoundsMixin,{locations:Ember.computed("@each.location",function(){return this.filterProperty("location").mapProperty("location")})})}(),function(){var e=Ember.get,t=Ember.set,r=Ember.setProperties;EmberLeaflet.DraggableMixin=Ember.Mixin.create({isDragging:!1,isDraggable:!0,dragstart:function(){t(this,"isDragging",!0)},dragend:function(){r(this,{location:this._layer.getLatLng(),isDragging:!1})},_updateDraggability:Ember.observer(function(){this._layer&&this._layer._map&&(e(this,"isDraggable")?this._layer.dragging.enable():this._layer.dragging.disable())},"isDraggable","layer")})}(),function(){var e=Ember.get;EmberLeaflet.MarkerLayer=EmberLeaflet.Layer.extend({content:null,options:null,location:Ember.computed.alias("content.location"),zIndexOffset:EmberLeaflet.computed.optionProperty(),opacity:EmberLeaflet.computed.optionProperty(),events:["click","dblclick","mousedown","mouseover","mouseout","contextmenu","dragstart","drag","dragend","move","remove","popupopen","popupclose"],_detectClustering:function(){for(var e=this;e._parentLayer;)if(e=e._parentLayer,e._isCluster)return!0;return!1},_updateLayerOnLocationChange:Ember.observer(function(){var t=e(this,"location");if(t&&!this._layer)this._createLayer();else if(this._layer&&!t)this._destroyLayer();else{var r=this._layer&&this._layer.getLatLng();r&&t&&!r.equals(t)&&(this._detectClustering()?(this._destroyLayer(),this._createLayer()):this._layer.setLatLng(t))}},"location"),_newLayer:function(){return L.marker(e(this,"location"),e(this,"options"))},_createLayer:function(){if(!this._layer&&e(this,"location")){this._super(),this._layer.content=e(this,"content");var t=this._layer.onAdd,r=this;this._layer.onAdd=function(){r.propertyWillChange("layer"),t.apply(this,arguments),r.propertyDidChange("layer")},this.notifyPropertyChange("layer")}},_destroyLayer:function(){this._layer&&this._super()}})}(),function(){EmberLeaflet.MarkerCollectionLayer=EmberLeaflet.CollectionLayer.extend({itemLayerClass:EmberLeaflet.MarkerLayer})}(),function(){EmberLeaflet.MarkerClusterLayer=EmberLeaflet.ContainerLayer.extend({options:{},_isCluster:!0,_newLayer:function(){return new L.MarkerClusterGroup(this.get("options"))},_removeChild:function(e){this._layer.removeLayer(e),e._map&&e._map.removeLayer(e)}})}(),function(){function e(e){return Ember.computed("options",function(i,n){if(i=e||i,arguments.length>1){if(this._layer){var o={};o[i]=n,this._layer.setStyle(o)}return r(this,"options")||t(this,"options",{}),this.get("options")[i]=n,n}return this._layer.options[i]})}var t=Ember.set,r=Ember.get;EmberLeaflet.PathLayer=EmberLeaflet.Layer.extend({stroke:e(),color:e(),weight:e(),opacity:e(),fill:e(),fillColor:e(),fillOpacity:e(),dashArray:e()})}(),function(){var e=Ember.get,t=EmberLeaflet.convert.latLngFromLatLngArray;EmberLeaflet.PointPathLayer=EmberLeaflet.PathLayer.extend({location:Ember.computed.alias("content.location"),_createLayer:function(){!this._layer&&e(this,"location")&&this._super()},_updateLayerOnLocationChange:Ember.observer(function(){var r=t(e(this,"location"));if(r&&!this._layer)this._createLayer();else if(this._layer&&!r)this._destroyLayer();else if(this._layer){var i=this._layer.getLatLng();i&&r&&!i.equals(r)&&this._layer.setLatLng(r)}},"location")})}(),function(){var e=Ember.get,t=EmberLeaflet.convert.latLngFromLatLngArray;EmberLeaflet.CircleLayer=EmberLeaflet.PointPathLayer.extend({radius:Ember.computed.alias("content.radius"),_updateLayerOnRadiusChange:Ember.observer(function(){var t=e(this,"radius");if(t&&!this._layer)this._createLayer();else if(this._layer&&!t)this._destroyLayer();else{var r=this._layer&&this._layer.getRadius();r&&t&&r!==t&&this._layer.setRadius(t)}},"radius"),_newLayer:function(){return L.circle(t(e(this,"location")),e(this,"radius"),e(this,"options"))},_destroyLayer:function(){this._layer&&this._super()}})}(),function(){var e=Ember.get,t=EmberLeaflet.convert.latLngFromLatLngArray;EmberLeaflet.ArrayPathLayer=EmberLeaflet.PathLayer.extend({init:function(){this._super(),this._setupLocationObservers()},destroy:function(){return this._teardownLocationObservers(),this._super()},locationsProperty:null,locationProperty:null,locations:Ember.computed(function(){var r=e(this,"locationProperty"),i=e(this,"locationsProperty"),n="content"+(i?"."+i:""),o=e(this,n)||Ember.A();return r&&(o=o.mapProperty(r)),o=o.filter(function(e){return!!e}),o=o.map(t)}).property("content","locationProperty","locationsProperty").volatile(),_contentWillChange:Ember.beforeObserver(function(){this._contentLocationsWillChange(),this._teardownLocationObservers()},"content","locationsProperty","locationProperty"),_contentDidChange:Ember.observer(function(){this._setupLocationObservers(),this._contentLocationsDidChange()},"content","locationsProperty","locationProperty"),_setupLocationObservers:function(){var t=e(this,"content"),r=e(this,"locationProperty"),i=e(this,"locationsProperty");if(t){var n=i?"content."+i:"content";i&&(Ember.addBeforeObserver(this,n,this,"_contentLocationsWillChange"),Ember.addObserver(this,n,this,"_contentLocationsDidChange"));var o=i?e(t,i):t;if(Ember.assert("Content object or locations property must be array-like",!o||!!o.addArrayObserver),o&&o.addArrayObserver(this),r){var a=n+".@each."+r;Ember.addBeforeObserver(this,a,this,"_contentLocationsWillChange"),Ember.addObserver(this,a,this,"_contentLocationsDidChange")}}},_teardownLocationObservers:function(){var t=e(this,"content"),r=e(this,"locationProperty"),i=e(this,"locationsProperty");if(t){var n=i?"content."+i:"content";i&&(Ember.addBeforeObserver(this,n,this,"_contentLocationsWillChange"),Ember.addObserver(this,n,this,"_contentLocationsDidChange"));var o=i?e(t,i):t;if(o&&o.removeArrayObserver(this),r){var a=n+".@each."+r;Ember.removeBeforeObserver(this,a,this,"_contentLocationsWillChange"),Ember.removeObserver(this,a,this,"_contentLocationsDidChange")}}},_contentLocationsWillChange:function(){this.propertyWillChange("locations")},_contentLocationsDidChange:function(){this.propertyDidChange("locations")},arrayWillChange:function(){this.propertyWillChange("locations")},arrayDidChange:function(){this.propertyDidChange("locations")}})}(),function(){var e=Ember.get;EmberLeaflet.PolylineLayer=EmberLeaflet.ArrayPathLayer.extend({options:{},events:["click","dblclick","mousedown","mouseover","mouseout","contextmenu","add","remove","popupopen","popupclose"],_newLayer:function(){return L.polyline(e(this,"locations"),e(this,"options"))},locationsDidChange:Ember.observer(function(){this._layer&&this._layer.setLatLngs(e(this,"locations"))},"locations")}),EmberLeaflet.PolygonLayer=EmberLeaflet.PolylineLayer.extend({_newLayer:function(){return L.polygon(e(this,"locations"),e(this,"options"))}})}(),function(){Ember.get,EmberLeaflet.PathBoundsLayer=EmberLeaflet.ArrayPathLayer.extend(EmberLeaflet.BoundsMixin,{})}(),function(){var e=Ember.get;EmberLeaflet.RectangleLayer=EmberLeaflet.PathBoundsLayer.extend({events:["click","dblclick","mousedown","mouseover","mouseout","contextmenu","add","remove","popupopen","popupclose"],_newLayer:function(){return L.rectangle(e(this,"bounds"),e(this,"options"))},_createLayer:function(){e(this,"bounds")&&this._super()},boundsDidChange:Ember.observer(function(){var t=e(this,"bounds");this._layer&&!t?this._destroyLayer():t&&!this._layer?this._createLayer():t&&this._layer&&this._layer.setBounds(t)},"locations")})}(),"undefined"==typeof location||"localhost"!==location.hostname&&"127.0.0.1"!==location.hostname||console.warn("You are running a production build of Ember on localhost and won't receive detailed error messages. If you want full error messages please use the non-minified build provided on the Ember website."); \ No newline at end of file +(function(){EmberLeaflet=Ember.Namespace.create()})(),function(){function e(e){return e?[e.lat,e.lng]:null}function t(e){return e?[e.lng,e.lat]:null}function r(e){return e?e.lat?e:L.latLng(e[0],e[1]):null}function i(e){return e?e.lat?e:L.latLng(e[1],e[0]):null}var n=Ember.get,o=Ember.set;EmberLeaflet.convert={latLngArrayFromLatLng:e,lngLatArrayFromLatLng:t,latLngFromLatLngArray:r,latLngFromLngLatArray:i},EmberLeaflet.computed={},EmberLeaflet.computed.latLngFromLngLatArray=function(e){return Ember.computed(e,function(r,a){return 1===arguments.length?i(n(this,e)):(o(this,e,t(a)),a)})},EmberLeaflet.computed.latLngFromLatLngArray=function(t){return Ember.computed(t,function(i,a){return 1===arguments.length?r(n(this,t)):(o(this,t,a=e(a)),a)})},EmberLeaflet.computed.optionProperty=function(e){return Ember.computed("options",function(t,r){if(t=e||t,arguments.length>1){var i="set"+Ember.String.classify(t);return Ember.assert(this.constructor+" must have a "+i+" function.",!!this._layer[i]),this._layer[i].call(this._layer,r),r}return this._layer.options[t]})}}(),function(){var e=(Ember.String.fmt,Ember.EnumerableUtils.forEach),t=Ember.get;EmberLeaflet.LayerMixin=Ember.Mixin.create({_layer:null,_parentLayer:null,isVirtual:!1,_childLayers:[],concatenatedProperties:["events"],parentLayer:Ember.computed.alias("_parentLayer").readOnly(),layer:Ember.computed(function(){return this._layer}).property(),_newLayer:Ember.required(Function),willCreateLayer:Ember.K,didCreateLayer:Ember.K,willDestroyLayer:Ember.K,didDestroyLayer:Ember.K,events:[],_createLayer:function(){Ember.assert("Parent layer must be in leaflet.",!!this._parentLayer._layer),this.willCreateLayer(),this.isVirtual||(this.propertyWillChange("layer"),this._layer=this._newLayer(),this._addEventListeners(),this._addToParent(),this.propertyDidChange("layer")),this.didCreateLayer()},_destroyLayer:function(){this.willDestroyLayer(),this.isVirtual||(this.propertyWillChange("layer"),this._removeEventListeners(),this._removeFromParent(),this._layer=null,this.propertyDidChange("layer")),this.didDestroyLayer()},_addToParent:function(){this._parentLayer._addChild(this._layer)},_removeFromParent:function(){this._parentLayer._removeChild(this._layer)},_addChild:function(e){this._layer.addLayer(e)},_removeChild:function(e){this._layer.removeLayer(e)},_addEventListeners:function(){this._eventHandlers={},e(t(this,"events"),function(e){"function"==typeof this[e]&&(this._eventHandlers[e]=function(t){Ember.run(this,this[e],t)},this._layer.addEventListener(e,this._eventHandlers[e],this))},this)},_removeEventListeners:function(){e(t(this,"events"),function(e){"function"==typeof this[e]&&(this._layer.removeEventListener(e,this._eventHandlers[e],this),delete this._eventHandlers[e])},this)}}),EmberLeaflet.Layer=Ember.Object.extend(EmberLeaflet.LayerMixin,{}),EmberLeaflet.EmptyLayer=EmberLeaflet.Layer.extend({_newLayer:function(){return L.layerGroup([])}})}(),function(){var e=Ember.get,t=(Ember.set,Ember.String.fmt),r=Ember.EnumerableUtils.forEach,i=Ember.EnumerableUtils.map;EmberLeaflet.ContainerLayerMixin=Ember.Mixin.create(EmberLeaflet.LayerMixin,Ember.MutableArray,{_childLayers:null,didCreateLayer:function(){this._super(),this.createAndAddChildLayers()},willDestroyLayer:function(){this.removeAndDestroyChildLayers(),this._super()},createAndAddChildLayers:function(){var t,i=this._childLayers=Ember.A(),n=this;void 0===this._childLayerClasses&&(this._childLayerClasses=e(this,"childLayers")||[]),Ember.defineProperty(this,"childLayers",Ember.computed(function(){return this._childLayers})),r(this._childLayerClasses,function(e,r){t=n.createChildLayer(e),n.addChildLayer(t),i[r]=t},this)},replace:function(t,r,n){var o=n?e(n,"length"):0,a=this;if(this.arrayContentWillChange(t,r,o),this.childLayersWillChange(this._childLayers,t,r),0===o)this._childLayers.splice(t,r);else{n=i(n,function(e){return a.createChildLayer(e)});var s=[t,r].concat(n);n.length&&!this._childLayers.length&&(this._childLayers=this._childLayers.slice()),this._childLayers.splice.apply(this._childLayers,s)}return this.arrayContentDidChange(t,r,o),this.childLayersDidChange(this._childLayers,t,r,o),this},objectAt:function(e){return this._childLayers[e]},length:Ember.computed(function(){return this._childLayers.length}),childLayersWillChange:function(e,t,i){var n=this;if(this.propertyWillChange("childLayers"),i>0){var o=e.slice(t,t+i);r(o,function(e){n.removeChildLayer(e)})}},childLayersDidChange:function(e,t,i,n){var o=this;if(n>0){var a=e.slice(t,t+n);r(a,function(e){o.addChildLayer(e)})}this.propertyDidChange("childLayers")},addChildLayer:function(e){e._createLayer()},removeChildLayer:function(e){e._destroyLayer()},createChildLayer:function(e,r){r=r||{},r.container=this.get("container"),r.controller=this.get("controller"),r._parentLayer=this.isVirtual?this._parentLayer:this;var i,n=Ember.typeOf(e);return Ember.assert(t("layerClass %@ must be an Ember instance or class.",e?e.toString():""),"instance"===n||"class"===n),"instance"===n?(i=e,i.setProperties(r)):"class"===n&&(i=e.create(r)),i},removeAndDestroyChildLayers:function(){var e=this;this._childLayers&&r(this._childLayers,function(t){e.removeChildLayer(t),t.destroy()}),this._childLayers=[]}}),EmberLeaflet.ContainerLayer=Ember.Object.extend(EmberLeaflet.ContainerLayerMixin,{_newLayer:function(){return L.layerGroup()}})}(),function(){var e=L.latLng(40.713282,-74.006978);EmberLeaflet.MapView=Ember.View.extend(EmberLeaflet.ContainerLayerMixin,{options:{},center:e,zoom:16,isMoving:!1,isZooming:!1,events:["click","dblclick","mousedown","mouseup","mouseover","mouseout","mousemove","contextmenu","focus","blur","preclick","load","unload","viewreset","movestart","move","moveend","dragstart","drag","dragend","zoomstart","zoomend","zoomlevelschange","resize","autopanstart","layeradd","layerremove","baselayerchange","overlayadd","overlayremove","locationfound","locationerror","popupopen","popupclose"],init:function(){this._super(),void 0===this.get("childLayers")&&this.set("childLayers",[EmberLeaflet.DefaultTileLayer])},didInsertElement:function(){this._super(),this._createLayer()},willDestroyElement:function(){this._destroyLayer()},_createLayer:function(){this._layer||(Ember.assert("Center must be set before creating map, was "+this.get("center"),!!this.get("center")),Ember.assert("Zoom must be set before creating map, was "+this.get("zoom"),!!this.get("zoom")),this.willCreateLayer(),this.propertyWillChange("layer"),this._layer=L.map(this.get("elementId"),this.get("options")),this._layer.setView(this.get("center"),this.get("zoom")),this._addEventListeners(),this.propertyDidChange("layer"),this.didCreateLayer())},_destroyLayer:function(){this.willDestroyLayer(),this.propertyWillChange("layer"),this._layer&&(this._defaultChildLayer&&(this._layer.removeLayer(this._defaultChildLayer),this._defaultChildLayer=null),this._removeEventListeners(),this._layer.remove(),this._layer=null,this.propertyDidChange("layer"),this.didDestroyLayer())},zoomstart:function(){this.set("isZooming",!0)},zoomend:function(){this.setProperties({isZooming:!1,zoom:this._layer.getZoom()}),this._queuedZoom&&(this._queuedZoom!==this._layer.getZoom()&&this._layer.setZoom(this._queuedZoom),this._queuedZoom=null)},movestart:function(){this.set("isMoving",!0)},moveend:function(){this.set("isMoving",!1)},move:function(){this.set("center",this._layer.getCenter())},zoomDidChange:Ember.observer(function(){this._layer&&!Ember.isNone(this.get("zoom"))&&(this._layer._animatingZoom?this._queuedZoom=this.get("zoom"):this._layer.setZoom(this.get("zoom")))},"zoom"),centerDidChange:Ember.observer(function(){this._layer&&!this.get("isMoving")&&this.get("center")&&(this._layer.getCenter().equals(this.get("center"))||this._layer.panTo(this.get("center")))},"center")})}(),function(){var e=Ember.get;EmberLeaflet.TileLayer=EmberLeaflet.Layer.extend({tileUrl:null,options:{},_newLayer:function(){return L.tileLayer(e(this,"tileUrl"),e(this,"options"))},tileUrlDidChange:Ember.observer(function(){this._layer&&this._layer.setUrl(this.get("tileUrl"))},"tileUrl"),zIndex:EmberLeaflet.computed.optionProperty(),opacity:EmberLeaflet.computed.optionProperty()}),EmberLeaflet.DefaultTileLayer=EmberLeaflet.TileLayer.extend({tileUrl:"http://a.tiles.mapbox.com/v3/examples.map-zr0njcqy/{z}/{x}/{y}.png"})}(),function(){var e=Ember.get;Ember.set,Ember.setProperties,EmberLeaflet.PopupMixin=Ember.Mixin.create({popupContent:"",popupViewClass:null,popupOptions:{offset:L.point(0,-36)},click:function(e){this._super&&this._super(e),this.openPopup(e)},dragstart:function(e){this._super&&this._super(e),this.closePopup()},openPopup:function(e){this.willOpenPopup();var t;t=this._layer.getLatLng?this._layer.getLatLng():L.latLngBounds(this._layer.getLatLngs()).getCenter(),this._popup.setLatLng(e&&e.latlng||t).openOn(this._layer._map),this._createPopupContent(),this.didOpenPopup()},closePopup:function(){this.willClosePopup(),this._layer._map.closePopup(),this.didClosePopup()},willOpenPopup:Ember.K,didOpenPopup:Ember.K,willClosePopup:Ember.K,didClosePopup:Ember.K,willCreatePopup:Ember.K,didCreatePopup:Ember.K,willDestroyPopup:Ember.K,didDestroyPopup:Ember.K,_createPopupContent:function(){if(!e(this,"popupViewClass"))return this._popup.setContent(e(this,"popupContent")),void 0;this._popupView&&this._destroyPopupContent();var t=e(this,"popupViewClass");"string"===Ember.typeOf(t)&&(t=e(this,"container").lookupFactory("view:"+t)),this._popupView=t.create({container:e(this,"container"),controller:e(this,"controller"),context:e(this,"controller"),content:e(this,"content")});var r=this;this._popupView._insertElementLater(function(){r._popupView.$().appendTo(r._popup._contentNode)}),Ember.run.schedule("afterRender",this,function(){r._popup.update()})},_destroyPopupContent:function(){e(this,"popupViewClass")&&this._popupView&&(this._popupView.destroy(),this._popupView=null)},_createPopup:function(){this.willCreatePopup(),this._popup=L.popup(e(this,"popupOptions"),this._layer);var t=this._popup.onRemove,r=this;this._popup.onRemove=function(e){r._destroyPopupContent(),t.call(r._popup,e)},this.didCreatePopup()},_destroyPopup:function(){this._popup&&(this.willDestroyPopup(),this._popup._map&&this._layer&&this._layer._map&&this._layer._map.closePopup(),this._popup=null,this.didDestroyPopup())},_updatePopup:Ember.observer(function(){this._popup&&this._popup.setContent(e(this,"popupContent"))},"popupContent"),_removePopupObservers:Ember.beforeObserver(function(){this._layer&&this._destroyPopup()},"layer"),_addPopupObservers:Ember.observer(function(){this._layer&&this._createPopup()},"layer")})}(),function(){var e=Ember.get;EmberLeaflet.BoundsMixin=Ember.Mixin.create({bounds:Ember.computed(function(){var t=e(this,"locations");return t instanceof L.LatLngBounds?t:t&&e(t,"length")?L.latLngBounds(t):null}).property("locations").volatile()})}(),function(){var e=Ember.get;Ember.EnumerableUtils.forEach,EmberLeaflet.CollectionLayer=EmberLeaflet.ContainerLayer.extend({content:[],isVirtual:!0,itemLayerClass:Ember.computed(function(){throw new Error("itemLayerClass must be defined.")}).property(),didCreateLayer:function(){this._super(),this._contentDidChange()},willDestroyLayer:function(){this._contentWillChange(),this._super()},_contentWillChange:Ember.beforeObserver(function(){var t=e(this,"content");t&&t.removeArrayObserver(this);var r=t?e(t,"length"):0;this.arrayWillChange(t,0,r)},"content"),_contentDidChange:Ember.observer(function(){var t=e(this,"content");t&&t.addArrayObserver(this);var r=t?e(t,"length"):0;this.arrayDidChange(t,0,null,r)},"content"),arrayWillChange:function(e,t,r){for(var i=t;t+r>i;i++)this.objectWasRemoved(e.objectAt(i))},arrayDidChange:function(e,t,r,i){for(var n=t;t+i>n;n++)this.objectWasAdded(e.objectAt(n),n)},objectWasAdded:function(t,r){void 0===r&&(r=this._childLayers.length);var i=this.createChildLayer(e(this,"itemLayerClass"),{content:t});this.replace(r,0,[i])},objectWasRemoved:function(e){for(var t,r=0,i=this._childLayers.length;i>r;r++)if(t=this._childLayers[r],t.get("content")===e)return this.replace(r,1,[]),t.destroy(),void 0}})}(),function(){EmberLeaflet.CollectionBoundsMixin=Ember.Mixin.create(EmberLeaflet.BoundsMixin,{locations:Ember.computed("@each.location",function(){return this.filterProperty("location").mapProperty("location")})})}(),function(){var e=Ember.get,t=Ember.set,r=Ember.setProperties;EmberLeaflet.DraggableMixin=Ember.Mixin.create({isDragging:!1,isDraggable:!0,dragstart:function(){t(this,"isDragging",!0)},dragend:function(){r(this,{location:this._layer.getLatLng(),isDragging:!1})},_updateDraggability:Ember.observer(function(){this._layer&&this._layer._map&&(e(this,"isDraggable")?this._layer.dragging.enable():this._layer.dragging.disable())},"isDraggable","layer")})}(),function(){var e=Ember.get;EmberLeaflet.MarkerLayer=EmberLeaflet.Layer.extend({content:null,options:null,location:Ember.computed.alias("content.location"),zIndexOffset:EmberLeaflet.computed.optionProperty(),opacity:EmberLeaflet.computed.optionProperty(),events:["click","dblclick","mousedown","mouseover","mouseout","contextmenu","dragstart","drag","dragend","move","remove","popupopen","popupclose"],_detectClustering:function(){for(var e=this;e._parentLayer;)if(e=e._parentLayer,e._isCluster)return!0;return!1},_updateLayerOnLocationChange:Ember.observer(function(){var t=e(this,"location");if(t&&!this._layer)this._createLayer();else if(this._layer&&!t)this._destroyLayer();else{var r=this._layer&&this._layer.getLatLng();r&&t&&!r.equals(t)&&(this._detectClustering()?(this._destroyLayer(),this._createLayer()):this._layer.setLatLng(t))}},"location"),_newLayer:function(){return L.marker(e(this,"location"),e(this,"options"))},_createLayer:function(){if(!this._layer&&e(this,"location")){this._super(),this._layer.content=e(this,"content");var t=this._layer.onAdd,r=this;this._layer.onAdd=function(){r.propertyWillChange("layer"),t.apply(this,arguments),r.propertyDidChange("layer")},this.notifyPropertyChange("layer")}},_destroyLayer:function(){this._layer&&this._super()}})}(),function(){EmberLeaflet.MarkerCollectionLayer=EmberLeaflet.CollectionLayer.extend({itemLayerClass:EmberLeaflet.MarkerLayer})}(),function(){EmberLeaflet.MarkerClusterLayer=EmberLeaflet.ContainerLayer.extend({options:{},_isCluster:!0,_newLayer:function(){return new L.MarkerClusterGroup(this.get("options"))},_removeChild:function(e){this._layer.removeLayer(e),e._map&&e._map.removeLayer(e)}})}(),function(){function e(e){return Ember.computed("options",function(i,n){if(i=e||i,arguments.length>1){if(this._layer){var o={};o[i]=n,this._layer.setStyle(o)}return r(this,"options")||t(this,"options",{}),this.get("options")[i]=n,n}return this._layer.options[i]})}var t=Ember.set,r=Ember.get;EmberLeaflet.PathLayer=EmberLeaflet.Layer.extend({stroke:e(),color:e(),weight:e(),opacity:e(),fill:e(),fillColor:e(),fillOpacity:e(),dashArray:e()})}(),function(){var e=Ember.get,t=EmberLeaflet.convert.latLngFromLatLngArray;EmberLeaflet.PointPathLayer=EmberLeaflet.PathLayer.extend({location:Ember.computed.alias("content.location"),_createLayer:function(){!this._layer&&e(this,"location")&&this._super()},_updateLayerOnLocationChange:Ember.observer(function(){var r=t(e(this,"location"));if(r&&!this._layer)this._createLayer();else if(this._layer&&!r)this._destroyLayer();else if(this._layer){var i=this._layer.getLatLng();i&&r&&!i.equals(r)&&this._layer.setLatLng(r)}},"location")})}(),function(){var e=Ember.get,t=EmberLeaflet.convert.latLngFromLatLngArray;EmberLeaflet.CircleLayer=EmberLeaflet.PointPathLayer.extend({radius:Ember.computed.alias("content.radius"),_updateLayerOnRadiusChange:Ember.observer(function(){var t=e(this,"radius");if(t&&!this._layer)this._createLayer();else if(this._layer&&!t)this._destroyLayer();else{var r=this._layer&&this._layer.getRadius();r&&t&&r!==t&&this._layer.setRadius(t)}},"radius"),_newLayer:function(){return L.circle(t(e(this,"location")),e(this,"radius"),e(this,"options"))},_destroyLayer:function(){this._layer&&this._super()}})}(),function(){var e=Ember.get,t=EmberLeaflet.convert.latLngFromLatLngArray;EmberLeaflet.ArrayPathLayer=EmberLeaflet.PathLayer.extend({init:function(){this._super(),this._setupLocationObservers()},destroy:function(){return this._teardownLocationObservers(),this._super()},locationsProperty:null,locationProperty:null,locations:Ember.computed(function(){var r=e(this,"locationProperty"),i=e(this,"locationsProperty"),n="content"+(i?"."+i:""),o=e(this,n)||Ember.A();return r&&(o=o.mapProperty(r)),o=o.filter(function(e){return!!e}),o=o.map(t)}).property("content","locationProperty","locationsProperty").volatile(),_contentWillChange:Ember.beforeObserver(function(){this._contentLocationsWillChange(),this._teardownLocationObservers()},"content","locationsProperty","locationProperty"),_contentDidChange:Ember.observer(function(){this._setupLocationObservers(),this._contentLocationsDidChange()},"content","locationsProperty","locationProperty"),_setupLocationObservers:function(){var t=e(this,"content"),r=e(this,"locationProperty"),i=e(this,"locationsProperty");if(t){var n=i?"content."+i:"content";i&&(Ember.addBeforeObserver(this,n,this,"_contentLocationsWillChange"),Ember.addObserver(this,n,this,"_contentLocationsDidChange"));var o=i?e(t,i):t;if(Ember.assert("Content object or locations property must be array-like",!o||!!o.addArrayObserver),o&&o.addArrayObserver(this),r){var a=n+".@each."+r;Ember.addBeforeObserver(this,a,this,"_contentLocationsWillChange"),Ember.addObserver(this,a,this,"_contentLocationsDidChange")}}},_teardownLocationObservers:function(){var t=e(this,"content"),r=e(this,"locationProperty"),i=e(this,"locationsProperty");if(t){var n=i?"content."+i:"content";i&&(Ember.addBeforeObserver(this,n,this,"_contentLocationsWillChange"),Ember.addObserver(this,n,this,"_contentLocationsDidChange"));var o=i?e(t,i):t;if(o&&o.removeArrayObserver(this),r){var a=n+".@each."+r;Ember.removeBeforeObserver(this,a,this,"_contentLocationsWillChange"),Ember.removeObserver(this,a,this,"_contentLocationsDidChange")}}},_contentLocationsWillChange:function(){this.propertyWillChange("locations")},_contentLocationsDidChange:function(){this.propertyDidChange("locations")},arrayWillChange:function(){this.propertyWillChange("locations")},arrayDidChange:function(){this.propertyDidChange("locations")}})}(),function(){var e=Ember.get;EmberLeaflet.PolylineLayer=EmberLeaflet.ArrayPathLayer.extend({options:{},events:["click","dblclick","mousedown","mouseover","mouseout","contextmenu","add","remove","popupopen","popupclose"],_newLayer:function(){return L.polyline(e(this,"locations"),e(this,"options"))},locationsDidChange:Ember.observer(function(){this._layer&&this._layer.setLatLngs(e(this,"locations"))},"locations")}),EmberLeaflet.PolygonLayer=EmberLeaflet.PolylineLayer.extend({_newLayer:function(){return L.polygon(e(this,"locations"),e(this,"options"))}})}(),function(){Ember.get,EmberLeaflet.PathBoundsLayer=EmberLeaflet.ArrayPathLayer.extend(EmberLeaflet.BoundsMixin,{})}(),function(){var e=Ember.get;EmberLeaflet.RectangleLayer=EmberLeaflet.PathBoundsLayer.extend({events:["click","dblclick","mousedown","mouseover","mouseout","contextmenu","add","remove","popupopen","popupclose"],_newLayer:function(){return L.rectangle(e(this,"bounds"),e(this,"options"))},_createLayer:function(){e(this,"bounds")&&this._super()},boundsDidChange:Ember.observer(function(){var t=e(this,"bounds");this._layer&&!t?this._destroyLayer():t&&!this._layer?this._createLayer():t&&this._layer&&this._layer.setBounds(t)},"locations")})}(),"undefined"==typeof location||"localhost"!==location.hostname&&"127.0.0.1"!==location.hostname||console.warn("You are running a production build of Ember on localhost and won't receive detailed error messages. If you want full error messages please use the non-minified build provided on the Ember website."); \ No newline at end of file diff --git a/packages/ember-leaflet/lib/mixin/popup.js b/packages/ember-leaflet/lib/mixin/popup.js index 5495f01..e680ae0 100644 --- a/packages/ember-leaflet/lib/mixin/popup.js +++ b/packages/ember-leaflet/lib/mixin/popup.js @@ -72,6 +72,12 @@ EmberLeaflet.PopupMixin = Ember.Mixin.create({ this._popupView._insertElementLater(function() { self._popupView.$().appendTo(self._popup._contentNode); }); + + // After the view has rendered, call update to ensure + // popup is visible with autoPan + Ember.run.schedule('afterRender', this, function() { + self._popup.update(); + }); }, _destroyPopupContent: function() {