Skip to content

Commit 40ece0d

Browse files
committed
angular-ui#1674 removed child check, just append if the parent exists
1 parent cb3a20b commit 40ece0d

File tree

5 files changed

+207
-107
lines changed

5 files changed

+207
-107
lines changed

dist/angular-google-maps.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5423,13 +5423,16 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
54235423
]);
54245424

54255425
}).call(this);
5426-
;(function() {
5426+
;
5427+
/*global angular:true, google:true */
5428+
5429+
(function() {
54275430
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
54285431
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
54295432
hasProp = {}.hasOwnProperty;
54305433

54315434
angular.module('uiGmapgoogle-maps.directives.api.models.parent').factory('uiGmapSearchBoxParentModel', [
5432-
'uiGmapBaseObject', 'uiGmapLogger', 'uiGmapEventsHelper', '$timeout', '$http', '$templateCache', function(BaseObject, Logger, EventsHelper, $timeout, $http, $templateCache) {
5435+
'uiGmapBaseObject', 'uiGmapLogger', 'uiGmapEventsHelper', function(BaseObject, Logger, EventsHelper) {
54335436
var SearchBoxParentModel;
54345437
SearchBoxParentModel = (function(superClass) {
54355438
extend(SearchBoxParentModel, superClass);
@@ -5534,7 +5537,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
55345537
SearchBoxParentModel.prototype.addToParentDiv = function() {
55355538
var ref;
55365539
this.parentDiv = angular.element(document.getElementById(this.scope.parentdiv));
5537-
if (((ref = this.parentDiv[0]) != null ? ref.firstChild : void 0) == null) {
5540+
if ((ref = this.parentDiv) != null ? ref.length : void 0) {
55385541
return this.parentDiv.append(this.input);
55395542
}
55405543
};

dist/angular-google-maps_dev_mapped.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5423,13 +5423,16 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
54235423
]);
54245424

54255425
}).call(this);
5426-
;(function() {
5426+
;
5427+
/*global angular:true, google:true */
5428+
5429+
(function() {
54275430
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
54285431
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
54295432
hasProp = {}.hasOwnProperty;
54305433

54315434
angular.module('uiGmapgoogle-maps.directives.api.models.parent').factory('uiGmapSearchBoxParentModel', [
5432-
'uiGmapBaseObject', 'uiGmapLogger', 'uiGmapEventsHelper', '$timeout', '$http', '$templateCache', function(BaseObject, Logger, EventsHelper, $timeout, $http, $templateCache) {
5435+
'uiGmapBaseObject', 'uiGmapLogger', 'uiGmapEventsHelper', function(BaseObject, Logger, EventsHelper) {
54335436
var SearchBoxParentModel;
54345437
SearchBoxParentModel = (function(superClass) {
54355438
extend(SearchBoxParentModel, superClass);
@@ -5534,7 +5537,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
55345537
SearchBoxParentModel.prototype.addToParentDiv = function() {
55355538
var ref;
55365539
this.parentDiv = angular.element(document.getElementById(this.scope.parentdiv));
5537-
if (((ref = this.parentDiv[0]) != null ? ref.firstChild : void 0) == null) {
5540+
if ((ref = this.parentDiv) != null ? ref.length : void 0) {
55385541
return this.parentDiv.append(this.input);
55395542
}
55405543
};

dist/angular-google-maps_dev_mapped.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<!DOCTYPE html>
2+
<html xmlns:ng="http://angularjs.org/" ng-app="appMaps">
3+
4+
<head>
5+
<meta charset="utf-8" />
6+
7+
<script src="../bower_components/angular/angular.js"></script>
8+
<script src="../bower_components/lodash/lodash.js"></script>
9+
<script src="../bower_components/angular-simple-logger/dist/angular-simple-logger.js"></script>
10+
<script src="../dist/angular-google-maps.js"></script>
11+
12+
<style type="text/css">
13+
html, body, #map_canvas {
14+
height: 100%;
15+
width: 100%;
16+
margin: 0px;
17+
}
18+
19+
#map_canvas {
20+
position: relative;
21+
}
22+
23+
24+
.angular-google-map-container {
25+
position: absolute;
26+
top: 50px;
27+
bottom: 0;
28+
right: 0;
29+
left: 0;
30+
}
31+
label{
32+
margin-right: 5px;
33+
}
34+
</style>
35+
</head>
36+
37+
<body>
38+
<div id="map_canvas" ng-controller="mainCtrl">
39+
<div id="searchbox">
40+
<label>Enter an address: </label>
41+
</div>
42+
<script type="text/ng-template" id="searchbox.tpl.html">
43+
<input type="text" placeholder="Search Box">
44+
</script>
45+
<ui-gmap-google-map center="map.center" zoom="map.zoom" draggable="true" options="options">
46+
<ui-gmap-search-box parentdiv="'searchbox'" template="searchbox.template" events="searchbox.events"></ui-gmap-search-box>
47+
<ui-gmap-marker coords="marker.coords" idkey="marker.id">
48+
</ui-gmap-marker>
49+
</ui-gmap-google-map>
50+
</div>
51+
<!--example-->
52+
</body>
53+
<script>
54+
angular.module('appMaps', ['uiGmapgoogle-maps'])
55+
.config(function(uiGmapGoogleMapApiProvider) {
56+
uiGmapGoogleMapApiProvider.configure({
57+
// key: 'your api key',
58+
v: '3.20', //defaults to latest 3.X anyhow
59+
libraries: 'places' // Required for SearchBox.
60+
});
61+
})
62+
.controller('mainCtrl', function ($scope, $log) {
63+
$scope.map = {center: {latitude: 40.1451, longitude: -99.6680 }, zoom: 20 };
64+
65+
$scope.marker = {
66+
id: Date.now()
67+
}
68+
var events = {
69+
places_changed: function (searchBox) {
70+
71+
var place = searchBox.getPlaces()[0];
72+
console.log(place.geometry.location.lat());
73+
var lat = place.geometry.location.lat(),lon = place.geometry.location.lng();
74+
$scope.marker = {
75+
id: Date.now(),
76+
coords: {
77+
latitude: lat,
78+
longitude: lon
79+
}
80+
};
81+
82+
$scope.map.center = {
83+
latitude: lat,
84+
longitude: lon
85+
86+
};
87+
88+
}
89+
}
90+
$scope.searchbox = { template:'searchbox.tpl.html', events:events};
91+
});
92+
</script>
93+
</html>
Lines changed: 101 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,103 @@
1+
###global angular:true, google:true ###
12
angular.module('uiGmapgoogle-maps.directives.api.models.parent')
2-
.factory 'uiGmapSearchBoxParentModel', ['uiGmapBaseObject', 'uiGmapLogger',
3-
'uiGmapEventsHelper', '$timeout', '$http', '$templateCache',
4-
(BaseObject, Logger, EventsHelper, $timeout, $http, $templateCache) ->
5-
class SearchBoxParentModel extends BaseObject
6-
@include EventsHelper
7-
constructor: (@scope, @element, @attrs, @gMap, @ctrlPosition, @template, @$log = Logger) ->
8-
unless @attrs.template?
9-
@$log.error 'template attribute for the search-box directive is mandatory. Places Search Box creation aborted!!'
10-
return
11-
12-
if angular.isUndefined @scope.options
13-
@scope.options = {}
14-
@scope.options.visible = true
15-
16-
if angular.isUndefined @scope.options.visible
17-
@scope.options.visible = true
18-
19-
if angular.isUndefined @scope.options.autocomplete
20-
@scope.options.autocomplete = false
21-
22-
@visible = @scope.options.visible
23-
@autocomplete = @scope.options.autocomplete
24-
25-
controlDiv = angular.element '<div></div>'
26-
controlDiv.append @template
27-
@input = controlDiv.find('input')[0]
28-
29-
@init()
30-
31-
init: =>
32-
@createSearchBox()
33-
34-
@scope.$watch('options', (newValue, oldValue) =>
35-
if angular.isObject newValue
36-
if newValue.bounds?
37-
@setBounds(newValue.bounds)
38-
if newValue.visible?
39-
if @visible != newValue.visible
40-
@setVisibility(newValue.visible)
41-
, true)
42-
43-
if @attrs.parentdiv?
44-
@addToParentDiv()
45-
else
46-
@addAsMapControl()
47-
48-
if not @visible
49-
@setVisibility(@visible)
50-
51-
if @autocomplete
52-
@listener = google.maps.event.addListener @gObject, 'place_changed', =>
53-
@places = @gObject.getPlace()
54-
else
55-
@listener = google.maps.event.addListener @gObject, 'places_changed', =>
56-
@places = @gObject.getPlaces()
57-
58-
@listeners = @setEvents @gObject, @scope, @scope
59-
@$log.info @
60-
61-
@scope.$on '$stateChangeSuccess', =>
62-
@addToParentDiv() if @attrs.parentdiv?
63-
64-
@scope.$on '$destroy', =>
65-
@gObject = null
66-
67-
addAsMapControl: =>
68-
@gMap.controls[google.maps.ControlPosition[@ctrlPosition]].push(@input)
69-
70-
addToParentDiv: =>
71-
@parentDiv = angular.element document.getElementById(@scope.parentdiv)
72-
@parentDiv.append @input if !@parentDiv[0]?.firstChild?
73-
74-
createSearchBox: =>
75-
if @autocomplete
76-
@gObject = new google.maps.places.Autocomplete @input, @scope.options
77-
else
78-
@gObject = new google.maps.places.SearchBox @input, @scope.options
79-
80-
setBounds: (bounds) =>
81-
if angular.isUndefined bounds.isEmpty
82-
@$log.error 'Error: SearchBoxParentModel setBounds. Bounds not an instance of LatLngBounds.'
83-
return
84-
else
85-
if bounds.isEmpty() == false
86-
if @gObject?
87-
@gObject.setBounds(bounds)
88-
89-
getBounds: =>
90-
@gObject.getBounds()
91-
92-
setVisibility: (val) =>
93-
if @attrs.parentdiv?
94-
if val == false then @parentDiv.addClass "ng-hide" else @parentDiv.removeClass "ng-hide"
95-
else
96-
if val == false then @gMap.controls[google.maps.ControlPosition[@ctrlPosition]].clear() else @gMap.controls[google.maps.ControlPosition[@ctrlPosition]].push(@input)
97-
@visible = val
98-
99-
100-
101-
SearchBoxParentModel
3+
.factory 'uiGmapSearchBoxParentModel', [
4+
'uiGmapBaseObject', 'uiGmapLogger','uiGmapEventsHelper',
5+
(BaseObject, Logger, EventsHelper) ->
6+
class SearchBoxParentModel extends BaseObject
7+
@include EventsHelper
8+
constructor: (@scope, @element, @attrs, @gMap, @ctrlPosition, @template, @$log = Logger) ->
9+
unless @attrs.template?
10+
@$log.error 'template attribute for the search-box directive is mandatory. Places Search Box creation aborted!!'
11+
return
12+
13+
if angular.isUndefined @scope.options
14+
@scope.options = {}
15+
@scope.options.visible = true
16+
17+
if angular.isUndefined @scope.options.visible
18+
@scope.options.visible = true
19+
20+
if angular.isUndefined @scope.options.autocomplete
21+
@scope.options.autocomplete = false
22+
23+
@visible = @scope.options.visible
24+
@autocomplete = @scope.options.autocomplete
25+
26+
controlDiv = angular.element '<div></div>'
27+
controlDiv.append @template
28+
@input = controlDiv.find('input')[0]
29+
30+
@init()
31+
32+
init: =>
33+
@createSearchBox()
34+
35+
@scope.$watch('options', (newValue, oldValue) =>
36+
if angular.isObject newValue
37+
if newValue.bounds?
38+
@setBounds(newValue.bounds)
39+
if newValue.visible?
40+
if @visible != newValue.visible
41+
@setVisibility(newValue.visible)
42+
, true)
43+
44+
if @attrs.parentdiv?
45+
@addToParentDiv()
46+
else
47+
@addAsMapControl()
48+
49+
if not @visible
50+
@setVisibility(@visible)
51+
52+
if @autocomplete
53+
@listener = google.maps.event.addListener @gObject, 'place_changed', =>
54+
@places = @gObject.getPlace()
55+
else
56+
@listener = google.maps.event.addListener @gObject, 'places_changed', =>
57+
@places = @gObject.getPlaces()
58+
59+
@listeners = @setEvents @gObject, @scope, @scope
60+
@$log.info @
61+
62+
@scope.$on '$stateChangeSuccess', =>
63+
@addToParentDiv() if @attrs.parentdiv?
64+
65+
@scope.$on '$destroy', =>
66+
@gObject = null
67+
68+
addAsMapControl: =>
69+
@gMap.controls[google.maps.ControlPosition[@ctrlPosition]].push(@input)
70+
71+
addToParentDiv: =>
72+
@parentDiv = angular.element document.getElementById(@scope.parentdiv)
73+
@parentDiv.append @input if @parentDiv?.length
74+
75+
createSearchBox: =>
76+
if @autocomplete
77+
@gObject = new google.maps.places.Autocomplete @input, @scope.options
78+
else
79+
@gObject = new google.maps.places.SearchBox @input, @scope.options
80+
81+
setBounds: (bounds) =>
82+
if angular.isUndefined bounds.isEmpty
83+
@$log.error 'Error: SearchBoxParentModel setBounds. Bounds not an instance of LatLngBounds.'
84+
return
85+
else
86+
if bounds.isEmpty() == false
87+
if @gObject?
88+
@gObject.setBounds(bounds)
89+
90+
getBounds: =>
91+
@gObject.getBounds()
92+
93+
setVisibility: (val) =>
94+
if @attrs.parentdiv?
95+
if val == false then @parentDiv.addClass "ng-hide" else @parentDiv.removeClass "ng-hide"
96+
else
97+
if val == false then @gMap.controls[google.maps.ControlPosition[@ctrlPosition]].clear() else @gMap.controls[google.maps.ControlPosition[@ctrlPosition]].push(@input)
98+
@visible = val
99+
100+
101+
102+
SearchBoxParentModel
102103
]

0 commit comments

Comments
 (0)