Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.

Commit 7ca68d1

Browse files
committed
Merge pull request #139 from fwitzke/r1-dev
[r1-dev] supporting labels on markers directive
2 parents de66fb8 + 065b610 commit 7ca68d1

9 files changed

+141
-102
lines changed

dist/angular-google-maps.js

+47-20
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@
362362
return this.GmapUtil = {
363363
getLabelPositionPoint: function(anchor) {
364364
var xPos, yPos;
365+
if (anchor === void 0) {
366+
return void 0;
367+
}
365368
anchor = /^([\d\.]+)\s([\d\.]+)$/.exec(anchor);
366369
xPos = anchor[1];
367370
yPos = anchor[2];
@@ -507,8 +510,6 @@
507510
return self.markerLabel.setMap(theMap);
508511
});
509512
this.marker.setMap(this.marker.getMap());
510-
this.$log = directives.api.utils.Logger;
511-
this.$log.info(this);
512513
}
513514

514515
MarkerLabelChildModel.prototype.getSharedCross = function(crossUrl) {
@@ -576,36 +577,43 @@
576577
MarkerChildModel.include(directives.api.utils.GmapUtil);
577578

578579
function MarkerChildModel(index, model, parentScope, gMap, $timeout, defaults, doClick, gMarkerManager) {
580+
var self,
581+
_this = this;
582+
this.index = index;
583+
this.model = model;
584+
this.parentScope = parentScope;
585+
this.gMap = gMap;
586+
this.defaults = defaults;
587+
this.doClick = doClick;
588+
this.gMarkerManager = gMarkerManager;
579589
this.watchDestroy = __bind(this.watchDestroy, this);
590+
this.setLabelOptions = __bind(this.setLabelOptions, this);
591+
this.isLabelDefined = __bind(this.isLabelDefined, this);
580592
this.setOptions = __bind(this.setOptions, this);
581593
this.setIcon = __bind(this.setIcon, this);
582594
this.setCoords = __bind(this.setCoords, this);
583595
this.destroy = __bind(this.destroy, this);
584596
this.maybeSetScopeValue = __bind(this.maybeSetScopeValue, this);
585597
this.createMarker = __bind(this.createMarker, this);
586598
this.setMyScope = __bind(this.setMyScope, this);
587-
var _this = this;
588-
this.index = index;
589-
this.gMarkerManager = gMarkerManager;
590-
this.model = model;
591-
this.defaults = defaults;
592-
this.parentScope = parentScope;
593-
this.iconKey = parentScope.icon;
594-
this.coordsKey = parentScope.coords;
595-
this.clickKey = parentScope.click();
596-
this.optionsKey = parentScope.options;
597-
this.myScope = parentScope.$new(false);
598-
this.myScope.model = model;
599-
this.gMap = gMap;
600-
this.setMyScope(model, void 0, true);
601-
this.createMarker(model);
602-
this.doClick = doClick;
603-
this.$log = directives.api.utils.Logger;
599+
self = this;
600+
this.iconKey = this.parentScope.icon;
601+
this.coordsKey = this.parentScope.coords;
602+
this.clickKey = this.parentScope.click();
603+
this.labelContentKey = this.parentScope.labelContent;
604+
this.optionsKey = this.parentScope.options;
605+
this.labelOptionsKey = this.parentScope.labelOptions;
606+
this.myScope = this.parentScope.$new(false);
607+
this.myScope.model = this.model;
608+
this.setMyScope(this.model, void 0, true);
609+
this.createMarker(this.model);
604610
this.myScope.$watch('model', function(newValue, oldValue) {
605611
if (newValue !== oldValue) {
606612
return _this.setMyScope(newValue, oldValue);
607613
}
608614
}, true);
615+
this.$log = directives.api.utils.Logger;
616+
this.$log.info(self);
609617
this.watchDestroy(this.myScope);
610618
}
611619

@@ -618,6 +626,7 @@
618626
}
619627
this.maybeSetScopeValue('icon', model, oldModel, this.iconKey, this.evalModelHandle, isInit, this.setIcon);
620628
this.maybeSetScopeValue('coords', model, oldModel, this.coordsKey, this.evalModelHandle, isInit, this.setCoords);
629+
this.maybeSetScopeValue('labelContent', model, oldModel, this.labelContentKey, this.evalModelHandle, isInit);
621630
this.maybeSetScopeValue('click', model, oldModel, this.clickKey, this.evalModelHandle, isInit);
622631
return this.createMarker(model, oldModel, isInit);
623632
};
@@ -726,7 +735,11 @@
726735
}
727736
this.opts = this.createMarkerOptions(scope.coords, scope.icon, scope.options);
728737
delete this.gMarker;
729-
this.gMarker = new google.maps.Marker(this.opts);
738+
if (this.isLabelDefined(scope)) {
739+
this.gMarker = new MarkerWithLabel(this.setLabelOptions(this.opts, scope));
740+
} else {
741+
this.gMarker = new google.maps.Marker(this.opts);
742+
}
730743
this.gMarkerManager.add(this.gMarker);
731744
return google.maps.event.addListener(this.gMarker, 'click', function() {
732745
if (_this.doClick && (_this.myScope.click != null)) {
@@ -735,6 +748,17 @@
735748
});
736749
};
737750

751+
MarkerChildModel.prototype.isLabelDefined = function(scope) {
752+
return scope.labelContent != null;
753+
};
754+
755+
MarkerChildModel.prototype.setLabelOptions = function(opts, scope) {
756+
opts.labelAnchor = this.getLabelPositionPoint(scope.labelAnchor);
757+
opts.labelClass = scope.labelClass;
758+
opts.labelContent = scope.labelContent;
759+
return opts;
760+
};
761+
738762
MarkerChildModel.prototype.watchDestroy = function(scope) {
739763
var _this = this;
740764
return scope.$on("$destroy", function() {
@@ -1916,6 +1940,9 @@ not 1:1 in this setting.
19161940
this.scope.doCluster = '=docluster';
19171941
this.scope.clusterOptions = '=clusteroptions';
19181942
this.scope.fit = '=fit';
1943+
this.scope.labelContent = '=labelcontent';
1944+
this.scope.labelAnchor = '@labelanchor';
1945+
this.scope.labelClass = '@labelclass';
19191946
this.$timeout = $timeout;
19201947
this.$log.info(this);
19211948
}

dist/angular-google-maps.min.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/example-controller.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,24 @@ function ExampleController ($scope, $timeout, $log) {
1717
genRandomMarkers = function(numberOfMarkers,scope){
1818
markers = []
1919
for(var i=0; i < numberOfMarkers; i++){
20-
markers.push(createRandomMarker(scope.map.bounds))
20+
markers.push(createRandomMarker(i, scope.map.bounds))
2121
}
2222
scope.map.randomMarkers = markers;
2323
};
2424

25-
createRandomMarker = function(bounds) {
25+
createRandomMarker = function(i, bounds) {
2626
var lat_min = bounds.southwest.latitude,
2727
lat_range = bounds.northeast.latitude - lat_min,
2828
lng_min = bounds.southwest.longitude,
2929
lng_range = bounds.northeast.longitude - lng_min;
3030

3131
latitude = lat_min + (Math.random() * lat_range);
3232
longitude = lng_min + (Math.random() * lng_range);
33-
return {latitude:latitude,longitude:longitude};
33+
return {
34+
latitude: latitude,
35+
longitude: longitude,
36+
title: 'm' + i
37+
};
3438
};
3539

3640
angular.extend($scope, {
@@ -74,18 +78,21 @@ function ExampleController ($scope, $timeout, $log) {
7478
{
7579
latitude: 46,
7680
longitude: -77,
77-
showWindow: false
81+
showWindow: false,
82+
title: '[46,-77]'
7883
},
7984
{
8085
latitude: 33,
8186
longitude: -77,
82-
showWindow: false
87+
showWindow: false,
88+
title: '[33,-77]'
8389
},
8490
{
8591
icon: 'plane.png',
8692
latitude: 35,
8793
longitude: -125,
88-
showWindow: false
94+
showWindow: false,
95+
title: '[35,-125]'
8996
}
9097
],
9198
dynamicMarkers: [],

example/example.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ body {
3737
font-weight: bold;
3838
text-align: center;
3939
width: 40px;
40-
border: 2px solid black;
40+
border: 1px solid black;
4141
white-space: nowrap;
4242
}
4343

example/example.html

+6-23
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ <h1>angular-google-maps example</h1>
4747
<layer type="BicyclingLayer" show="map.showBicycling"></layer>
4848
<layer namespace="weather" type="WeatherLayer" show="map.showWeather"></layer>
4949

50-
<marker coords="searchLocation">
51-
</marker>
50+
<marker coords="searchLocation"/>
51+
5252
<markers models="map.randomMarkers" coords="'self'" icon="'icon'" click="'onClicked'"
53-
doCluster="map.doClusterRandomMarkers" clusterOptions="map.clusterOptions">
53+
doCluster="map.doClusterRandomMarkers" clusterOptions="map.clusterOptions">
5454
</markers>
55-
56-
<markers models="map.markers2" coords="'self'" icon="'icon'" click="'onClicked'">
55+
56+
<markers models="map.markers2" coords="'self'" icon="'icon'" click="'onClicked'"
57+
labelContent="'title'" labelAnchor="22 0" labelClass="marker-labels">
5758
<windows show="'showWindow'" closeClick="'closeClick'">
5859
<p ng-non-bindable>This is an info window at {{ latitude | number:4 }}, {{ longitude | number:4 }}!</p>
5960

@@ -114,24 +115,6 @@ <h1>angular-google-maps example</h1>
114115
<fieldset>
115116
<table class="table">
116117
<tbody>
117-
<tr>
118-
<td>
119-
<ul>
120-
<li class="dropdown">
121-
<a class="dropdown-toggle"
122-
data-toggle="dropdown"
123-
href="#">
124-
Products
125-
<b class="caret"></b>
126-
</a>
127-
<ul class="dropdown-menu">
128-
<li><a href="#">Consumer</a></li>
129-
<li><a href="#>">Broadcast</a></li>
130-
</ul>
131-
132-
</ul>
133-
</td>
134-
</tr>
135118
<tr>
136119
<td>
137120
<strong>Layers</strong>

src/coffee/directives/api/markers.coffee

+5
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ not 1:1 in this setting.
1515
super($timeout)
1616
self = @
1717
@template = '<span class="angular-google-map-markers" ng-transclude></span>'
18+
1819
@scope.models = '=models'
1920
@scope.doCluster= '=docluster'
2021
@scope.clusterOptions= '=clusteroptions'
2122
@scope.fit= '=fit'
23+
@scope.labelContent= '=labelcontent'
24+
@scope.labelAnchor= '@labelanchor'
25+
@scope.labelClass= '@labelclass'
26+
2227
@$timeout = $timeout
2328
@$log.info(@)
2429

src/coffee/directives/api/models/child/label-child-model.coffee

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
constructor: (gMarker,opt_options) ->
55
super()
66
self = @
7+
78
@marker = gMarker
89
@marker.set("labelContent" , opt_options.labelContent)
910
@marker.set("labelAnchor" , @getLabelPositionPoint( opt_options.labelAnchor ))
@@ -39,8 +40,6 @@
3940

4041
@marker.setMap( @marker.getMap() )
4142

42-
@$log = directives.api.utils.Logger
43-
@$log.info(@)
4443
getSharedCross:(crossUrl)=>
4544
@markerLabel.getSharedCross(crossUrl)
4645
setTitle:()=>

src/coffee/directives/api/models/child/marker-child-model.coffee

+35-20
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
@ngGmapModule "directives.api.models.child", ->
22
class @MarkerChildModel extends oo.BaseObject
33
@include directives.api.utils.GmapUtil
4-
constructor:(index,model,parentScope,gMap,$timeout,defaults,doClick,gMarkerManager)->
5-
@index = index
6-
@gMarkerManager = gMarkerManager
7-
@model = model
8-
@defaults = defaults
9-
@parentScope = parentScope
10-
@iconKey = parentScope.icon
11-
@coordsKey = parentScope.coords
12-
@clickKey = parentScope.click()
13-
@optionsKey = parentScope.options
14-
@myScope = parentScope.$new(false)
15-
@myScope.model = model
16-
@gMap = gMap
17-
@setMyScope(model,undefined,true)
18-
@createMarker(model)
19-
@doClick = doClick
20-
@$log = directives.api.utils.Logger
4+
constructor:(@index, @model, @parentScope, @gMap, $timeout, @defaults, @doClick, @gMarkerManager)->
5+
self = @
6+
7+
@iconKey = @parentScope.icon
8+
@coordsKey = @parentScope.coords
9+
@clickKey = @parentScope.click()
10+
@labelContentKey = @parentScope.labelContent
11+
@optionsKey = @parentScope.options
12+
@labelOptionsKey = @parentScope.labelOptions
13+
@myScope = @parentScope.$new(false)
14+
15+
@myScope.model = @model
16+
@setMyScope(@model, undefined, true)
17+
@createMarker(@model)
18+
2119
@myScope.$watch('model',(newValue, oldValue) =>
2220
if (newValue != oldValue)
2321
@setMyScope(newValue,oldValue)
2422
,true)
2523

24+
@$log = directives.api.utils.Logger
25+
@$log.info(self)
2626
@watchDestroy(@myScope)
2727

2828
setMyScope:(model, oldModel = undefined,isInit = false) =>
2929
@maybeSetScopeValue('icon',model,oldModel,@iconKey,@evalModelHandle,isInit,@setIcon)
3030
@maybeSetScopeValue('coords',model,oldModel,@coordsKey,@evalModelHandle,isInit,@setCoords)
31+
@maybeSetScopeValue('labelContent',model,oldModel,@labelContentKey,@evalModelHandle,isInit)
3132
@maybeSetScopeValue('click',model,oldModel,@clickKey,@evalModelHandle,isInit)
3233
@createMarker(model,oldModel,isInit)
3334

@@ -71,7 +72,7 @@
7172
setCoords:(scope) =>
7273
if(scope.$id != @myScope.$id or @gMarker == undefined)
7374
return
74-
if (scope.coords?)
75+
if (scope.coords?)
7576
@gMarker.setPosition(new google.maps.LatLng(scope.coords.latitude, scope.coords.longitude))
7677
@gMarker.setVisible(scope.coords.latitude? and scope.coords.longitude?)
7778
@gMarkerManager.remove(@gMarker)
@@ -97,15 +98,29 @@
9798
delete @gMarker
9899
unless scope.coords ? scope.icon? scope.options?
99100
return
100-
@opts = @createMarkerOptions(scope.coords,scope.icon,scope.options)
101+
@opts = @createMarkerOptions(scope.coords, scope.icon, scope.options)
102+
101103
delete @gMarker
102-
@gMarker = new google.maps.Marker(@opts)
104+
if @isLabelDefined(scope)
105+
@gMarker = new MarkerWithLabel(@setLabelOptions(@opts, scope))
106+
else
107+
@gMarker = new google.maps.Marker(@opts)
108+
103109
@gMarkerManager.add(@gMarker)
104110
google.maps.event.addListener(@gMarker, 'click', =>
105111
if @doClick and @myScope.click?
106112
@myScope.click()
107113
)
108114

115+
isLabelDefined:(scope) =>
116+
scope.labelContent?
117+
118+
setLabelOptions:(opts, scope) =>
119+
opts.labelAnchor= @getLabelPositionPoint(scope.labelAnchor)
120+
opts.labelClass= scope.labelClass
121+
opts.labelContent= scope.labelContent
122+
opts
123+
109124
watchDestroy:(scope)=>
110125
scope.$on("$destroy", =>
111126
if @gMarker? #this is possible due to AsyncProcessor in that we created some Children but no gMarker yet

0 commit comments

Comments
 (0)