How to get on-click coordinates on angular google maps? - angularjs

I'm kind of a newb when it comes to AngularJS and Google's API for maps and I've been trying to get coordinates on click. I'm using this API.
I am getting an error: Uncaught TypeError: Cannot read property 'lat' of undefined
on "console.log(lat);" row
This is my angular controller:
app.controller("agencyController",['$scope', '$log','uiGmapGoogleMapApi', function($scope,$interval, GoogleMapApi){
markers = [],
angular.extend($scope, {
markeri : markers,
map : {
center: bgdcentar,
zoom:13,
options: {
mapTypeId : google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
streetViewControl: false,
styles: [{"featureType":"administrative","elementType":"labels.text.fill","stylers":[{"color":"#444444"}]},{"featureType":"landscape","elementType":"all","stylers":[{"color":"#f2f2f2"}]},{"featureType":"poi","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"road","elementType":"all","stylers":[{"saturation":-100},{"lightness":45}]},{"featureType":"road.highway","elementType":"all","stylers":[{"visibility":"simplified"}]},{"featureType":"road.arterial","elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"featureType":"transit","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"all","stylers":[{"color":"#46bcec"},{"visibility":"on"}]}],
disableDoubleClickZoom: true,
scaleControl: true,
scrollwheel: true,
panControl: true,
streetViewControl: false,
draggable: true,
overviewMapControl: true,
},
events:{
rightclick: function(event){
var lat = event.latLng.lat();
var lng = event.latLng.lng();
console.log(lat);
console.log(lng);
console.log('Stan dodat!');
markers.push();
},
},
},
searchbox : {
template: 'searchbox.tpl.html',
events:{
places_changed: function(searchBox){
},
parentdiv: 'map_canvas'
}
},
});
}]);
And this is a part of my html, the code is included in the controller so don't worry about that:
<div id="map_canvas">
<ui-gmap-google-map center='map.center' zoom='map.zoom' options='map.options' events='map.events' >
<ui-gmap-search-box template="searchbox.template" events="searchbox.events"></ui-gmap-search-box> <!-- search-->
<ui-gmap-markers models="markeri" coords="'self'" icon="'icon'"></ui-gmap-markers> <!-- markeri -->
</ui-gmap-google-map>
</div>

You need to replace:
rightclick: function(event){
//...
}
with:
rightclick: function (map, eventName, events) {
var event = events[0];
//...
}
where
map refers to map object,
eventName - the name of event
events - the list of event listeners
Example
angular.module('appMaps', ['uiGmapgoogle-maps'])
.config(function(uiGmapGoogleMapApiProvider) {
uiGmapGoogleMapApiProvider.configure({
//key: ''
});
})
.controller("mainCtrl", ['$scope', '$log', 'uiGmapGoogleMapApi',
function($scope, $interval, GoogleMapApi) {
angular.extend($scope, {
markers: [],
markerNo: 1,
map: {
center: {
latitude: 42.3349940452867,
longitude: -71.0353168884369
},
zoom: 13,
options: {
},
events: {
rightclick: function(map, eventName, events) {
var event = events[0];
var lat = event.latLng.lat();
var lng = event.latLng.lng();
$scope.$apply(function() {
$scope.markers.push({
latitude: lat,
longitude: lng,
id: $scope.markerNo
});
$scope.markerNo++;
});
},
},
}
});
}
]);
.angular-google-map-container {
position: absolute;
width: 100%;
height: 240px;
}
<script src="https://code.angularjs.org/1.3.14/angular.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>
<script src="http://rawgit.com/angular-ui/angular-google-maps/2.0.X/dist/angular-google-maps.js"></script>
<div id="map_canvas" ng-app="appMaps" ng-controller="mainCtrl">
<ui-gmap-google-map center='map.center' zoom='map.zoom' options='map.options' events='map.events'>
<ui-gmap-markers models="markers" coords="'self'" icon="'icon'"></ui-gmap-markers>
</ui-gmap-google-map>
</div>

Related

ui-calendar tooltip function not working

calendar to display a calendar and set of events(events being hardcoded as of now).But when i hover on the event the tooltip is not displayed.I searched for many answers online and none worked for me ,Everything else except tooltip is working.Please help.Following is my js code
var app = angular.module('myApp', ['ui.calendar', 'ui.router']);
app.controller('myNgController', ['$scope', '$http', 'uiCalendarConfig', function($scope, $http, uiCalendarConfig) {
$scope.SelectedEvent = null;
var isFirstTime = true;
$scope.events = [];
$scope.eventSources = [$scope.events];
$scope.events.push({
title: "event",
description: "jahsojoaisjjoijaso",
start: new Date("2017-05-03"),
end: new Date("2017-05-03"),
allDay: false,
stick: false
});
$scope.uiConfig = {
calendar: {
height: 450,
editable: false,
displayEventTime: false,
header: {
left: 'month basicWeek basicDay agendaWeek agendaDay',
center: 'title',
right: 'today prev,next'
},
eventClick: function(event) {
$scope.SelectedEvent = event;
},
eventAfterAllRender: function() {
if ($scope.events.length > 0 && isFirstTime) {
//Focus first event
uiCalendarConfig.calendars.myCalendar.fullCalendar('gotoDate', $scope.events[0].start);
isFirstTime = false;
}
}
}
};
$scope.eventRender = function( event, element, view ) {
element.attr({'tooltip': event.title,
'tooltip-append-to-body': true});
$compile(element)($scope);
};
}]);
and if i try the following code the whole event disappears.The event is no more displayed on the calender
var app = angular.module('myApp', ['ui.calendar', 'ui.router']);
app.controller('myNgController', ['$scope', '$http', 'uiCalendarConfig', function($scope, $http, uiCalendarConfig) {
$scope.SelectedEvent = null;
var isFirstTime = true;
$scope.events = [];
$scope.eventSources = [$scope.events];
$scope.events.push({
title: "event",
description: "jahsojoaisjjoijaso",
start: new Date("2017-05-03"),
end: new Date("2017-05-03"),
allDay: false,
stick: false
});
$scope.uiConfig = {
calendar: {
height: 450,
editable: false,
displayEventTime: false,
header: {
left: 'month basicWeek basicDay agendaWeek agendaDay',
center: 'title',
right: 'today prev,next'
},
eventClick: function(event) {
$scope.SelectedEvent = event;
},
eventAfterAllRender: function() {
if ($scope.events.length > 0 && isFirstTime) {
//Focus first event
uiCalendarConfig.calendars.myCalendar.fullCalendar('gotoDate', $scope.events[0].start);
isFirstTime = false;
}
},
eventRender : function( event, element, view ) {
element.attr({'tooltip': event.title,
'tooltip-append-to-body': true});
$compile(element)($scope);
}
}
};
}]);
and the html code
<h1> calendar</h1>
<div ng-controller="myNgController">
<div class="row">
<div class="col-md-8">
<div id="calendar" ui-calendar="uiConfig.calendar" ng-model="eventSources" calendar="myCalendar"></div>
</div>
<div class="col-md-4">
<div class="alert alert-success" style="margin-top:50px" ng-controller="MyDbController">
<h2 style="margin-top:0px;text-align:center;" ng-repeat="elem in data"> {{elem.balance}} Available </h2>
<a ui-sref="apply" onclick="closeNav()" class="btn btn-success" role="button" style="display: block; margin: 0 auto;" >Reques(s)</a>
</div>
</div>
</div>
</div>
updated code as per answer ..
var app = angular.module('myApp', ['ui.calendar', 'ui.router']);
app.controller('myNgController',['$scope', '$timeout', '$http', '$compile', 'uiCalendarConfig', function($scope, $timeout, $http, $compile, uiCalendarConfig){
$scope.SelectedEvent = null;
var isFirstTime = true;
$scope.events = [];
$scope.eventSources = [$scope.events];
$scope.events.push({
title: "event",
description: "jahsojoaisjjoijaso",
start: new Date("2017-05-03"),
end: new Date("2017-05-03"),
allDay: false,
stick: false
});
$scope.uiConfig = {
calendar: {
height: 450,
editable: false,
displayEventTime: false,
header: {
left: 'month basicWeek basicDay agendaWeek agendaDay',
center: 'title',
right: 'today prev,next'
},
eventClick: function(event) {
$scope.SelectedEvent = event;
},
eventRender : function( event, element, view ) {
element.attr({'tooltip': event.title,
'tooltip-append-to-body': true});
$compile(element)($scope);
},
eventAfterAllRender: function() {
if ($scope.events.length > 0 && isFirstTime) {
//Focus first event
$timeout(function(){
uiCalendarConfig.calendars.myCalendar.fullCalendar('gotoDate', $scope.events[0].start);
isFirstTime = false;
});
}
}
}
};
You must set that function in the calendar configuration definition (Reference):
$scope.uiConfig = {
calendar: {
eventRender: $scope.eventRender,
... reset of the configuration
}
}
Don't forget to inject $compile to your controller:
app.controller('myNgController', ['$scope', '$http', '$compile', 'uiCalendarConfig', function($scope, $http, $compile, uiCalendarConfig) {
As for our discussion in the comments - You're getting "TypeError: Cannot read property 'fullCalendar' of undefined" error. Try the following
Inject $timeout to the controller:
app.controller('myNgController', ['$scope', '$timeout', '$http', '$compile', 'uiCalendarConfig', function($scope, $timeout, $http, $compile, uiCalendarConfig) {
And wrap this line with $timeout:
uiCalendarConfig.calendars.myCalendar.fullCalendar('gotoDate', $scope.events[0].start);
So the final result will be:
$timeout(function() {
uiCalendarConfig.calendars.myCalendar.fullCalendar('gotoDate', $scope.events[0].start);
});
This will make sure that you call fullCalendar only after the view was finished rendering.
And for dessert - Take a look on how you set the tooltip:
element.attr({
'tooltip': event.title,
'tooltip-append-to-body': true
});
Note that it adds tooltip="<title of event> and tooltip-append-to-body="true, but in order to show the tooltip, you need to set a title attribute. Change it to:
element.attr({
'title': event.title,
'tooltip-append-to-body': true
});
I guess that you think it's Bootstrap.UI tooltip (http://angular-ui.github.io/bootstrap/#!#tooltip) so in that case you need to make the necessary changes to implement it correctly. But using title will ensure that while hovering over the event the browser will show you the default tooltip (Using the native HTML "title" attribute).

AngularJS $stateProvider URL results in blank page

I'm using angular-ui-router and set up a 2nd controller similar to my 1st one which was working, but the route in the 2nd controller is not properly routing the app. Can someone please tell me where I went wrong?
html for first controller (works properly):
<div style="height: 100%"> <!--took out: ng-if="map.center !== undefined"-->
<ui-gmap-google-map
center='map.center'
zoom='map.zoom'
draggable='map.draggable'
dragging='map.dragging'
refresh='map.refresh'
options='map.options'
events='map.events'
pan='map.pan'>
<ui-gmap-circle
center='map.circle.center'
radius='map.circle.radius'
fill='map.circle.fill'
stroke='map.circle.stroke'
clickable='map.circle.clickable'
draggable='map.circle.draggable'
editable='map.circle.editable'
visible='map.circle.visible'
events='map.circle.events'>
</ui-gmap-circle>
</ui-gmap-google-map>
<script src='//maps.googleapis.com/maps/api/js?key=AIzaSyD_g7xCYEi-U54SYfTXQ_lukRsChkWgjXQ'></script>
</div>
1st controller (works properly ):
(function (window, ng) {
ng.module('app', ['uiGmapgoogle-maps', 'ui.router'])
.config(function ($stateProvider) { //had: , $stateChangeError included in the function parameters, but that caused error
$stateProvider.state('searchRadius', {
url: '/:lat/:lon',
templateUrl: 'searchRadius.html', //changed from index to searchRadius.html
controller: 'MapsCtrl',
});
})
.controller('MapsCtrl', ['$scope', "uiGmapLogger", "uiGmapGoogleMapApi", "$interval", "$state", "$stateParams",
function ($scope, $log, GoogleMapApi, $interval, $state, $stateParams) {
$log.currentLevel = $log.LEVELS.debug;
var center = { latitude: parseFloat($stateParams.lat), longitude: parseFloat($stateParams.lon) };
alert(JSON.stringify(center));
Object.freeze(center); //caused TypeError: Cannot assign to read only property ('latitude') ...
console.log($stateParams);
$scope.map = {
center: center,
pan: false,
zoom: 16,
refresh: false,
events: {},
bounds: {}
};
$scope.map.circle = {
id: 1,
center: center,
radius: 500, //(current time - date lost)*km/hour
stroke: {
color: '#08B21F',
weight: 2,
opacity: 1
},
fill: {
color: '#08B21F',
opacity: 0.5
},
geodesic: false, // optional: defaults to false
draggable: false, // optional: defaults to false
clickable: true, // optional: defaults to true
editable: false, // optional: defaults to false
visible: true, // optional: defaults to true
events: {
dblclick: function () {
$log.debug("circle dblclick");
},
radius_changed: function (gObject) {
var radius = gObject.getRadius();
$log.debug("circle radius radius_changed " + radius);
}
}
}
//Increase Radius:
$interval(function(){
$scope.map.circle.radius += 30; //dynamic var
}, 1000); //end of interval function
} ]); //end of controller
})(window, angular);
2nd html (blank page):
<!--Add ability to input location as address-->
<div>
<ui-gmap-google-map
center='map.center'
zoom='map.zoom'
draggable='map.draggable'
dragging='map.dragging'
refresh='map.refresh'
options='map.options'
events='map.events'
pan='map.pan'>
<ui-gmap-circle
center='map.circle.center'
radius='map.circle.radius'
fill='map.circle.fill'
stroke='map.circle.stroke'
clickable='map.circle.clickable'
draggable='map.circle.draggable'
editable='map.circle.editable'
visible='map.circle.visible'
events='map.circle.events'>
</ui-gmap-circle>
</ui-gmap-google-map>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDWKJRXSux3dAdEYOYqjkoi2MCW8dutFbY&callback=initMap">
</script>
</div>
2nd controller (results in blank page with no errors):
(function (window, ng) {
ng.module('app', ['uiGmapgoogle-maps', 'ui.router'])
.config(function ($stateProvider) { //had: , $stateChangeError included in the function parameters, but that caused error
$stateProvider.state('getLocation', {
url: '/getLocation',
templateUrl: 'getlocation.html', //changed from index to searchRadius.html
controller: 'GetlocationCtrl',
});
})
.controller('GetlocationCtrl', ['$scope', "uiGmapLogger", "uiGmapGoogleMapApi", "$state", "$stateParams",
function ($scope, $log, GoogleMapApi, $state, $stateParams) {
$log.currentLevel = $log.LEVELS.debug;
var center = { latitude: 49.22, longitude: -122.66 }; //default center
alert(JSON.stringify(center));
console.log($stateParams);
$scope.map = {
center: center,
pan: false,
zoom: 16,
refresh: false,
events: {},
bounds: {}
};
$scope.map.circle = {
id: 1,
center: center,
radius: 500, //(current time - date lost)*km/hour
stroke: {
color: '#08B21F',
weight: 2,
opacity: 1
},
fill: {
color: '#08B21F',
opacity: 0.5
},
geodesic: false, // optional: defaults to false
draggable: false, // optional: defaults to false
clickable: true, // optional: defaults to true
editable: false, // optional: defaults to false
visible: true, // optional: defaults to true
events: {
dblclick: function () {
$log.debug("circle dblclick");
},
radius_changed: function (gObject) {
var radius = gObject.getRadius();
$log.debug("circle radius radius_changed " + radius);
}
}
}
} ]); //end of controller
})(window, angular);
(i) You are using $routerProvider which is not necessarily required
(ii) Also when i check your code, you are loading the first module after loading the 2nd controller. Place your scripts like this in index.html ,
<script src="searchRadius.js"></script>
<script src="getLoc.js"></script>

how to get a particular location on google maps with markers from a angular dropdown list

I am trying to do some location search on google maps,its like i am having a angular multi-select drop-down where i am having several locations, if i select a single location or more ,i have to show them on maps using markers,and how to get our current location any suggestions on how to do it please.
Dropdown code
<div class="m-r"
ng-dropdown-multiselect=""
options="locations"
selected-model="search.locations"
extra-settings="multiSelectSettingsFunction"
translation-texts ="locationsTexts"
settings="selectSettings">
</div>
Google maps code
<ui-gmap-google-map center="map.center" refresh="true" zoom="map.zoom" draggable="true" data-tap-disabled="true">
<ui-gmap-window show="map.window.show" coords="map.window.model" options="map.window.options" closeClick="map.window.closeClick()">
<div style="color: black" background-color="#337ab7">
{{map.window.title}}
{{map.window.venue}}
</div>
</ui-gmap-window>
<ui-gmap-markers idkey="marker.id" models="map.markers" coords="'self'" doCluster="false" fit="'true'" icon="'icon'" events="map.markersEvents " options="'options'"></ui-gmap-markers>
</ui-gmap-google-map>
controller.js
app.controller("MainController", [ '$anchorScroll', '$scope', '$http', '$modal', '$log', '$timeout', '$location', '$rootScope', '$window','$mdSidenav' , function ($anchorScroll, $scope, $http, $modal, $log, $timeout, $location, $rootScope, $window,$mdSidenav) {
$scope.searchBack = window.sessionStorage.searchBack;
$scope.search = {
pax: '',
data: '',
locations : [],
distance : []
}
$scope.$watch('search.locations', function(newVal, oldVal){
//console.log(newVal);
//$scope.setSearch();
}, true);
$scope.locationsTexts = {
buttonDefaultText: 'Locations',
dynamicButtonTextSuffix: 'Locations',
}
$scope.multiSelectSettings = {
displayProp: 'locations',
idProp: 'locations',
scrollableHeight: '256px',
scrollable: true,
enableSearch: true,
buttonDefaultText: 'asd',
dynamicButtonTextSuffix: 'Locations',
//showCheckAll: false,
};
$scope.locations = [
{id: 1, label: "kothapet"},
{id: 2, label: "Dsnr"},
{id: 3, label: "Malakpet"},
{id: 4, label: "Chadarghat"},
{id: 5, label: "Koti"},
{id: 6, label: "abids"}
];
Maps Controller
app.controller('MapController2', function($scope, $rootScope, $http) {
var data = {};
data.map = {
zoom: 16,
center: {
latitude: 17.399,
longitude: 78.52
},
markers: [
{
id: 1,
latitude: 17.3762,
longitude: 78.5461,
title: 'Location:Nagole',
venue:'Venue: Ng builders'
},
{
id: 2,
latitude: 17.3710,
longitude: 78.5410,
title: 'Location:Kothapet',
venue:'Venue: A Builders'
},
{
id: 3,
latitude: 17.3688,
longitude: 78.5247,
title: 'Location:Dilsukhnagar',
venue:'Venue: B Builders'
},
{
id: 4,
latitude: 17.3667,
longitude: 78.500,
title: 'Location:Malakpet',
venue:'Venue: C Builders'
}],
markersEvents: {
click: function(marker, eventName, model, arguments) {
console.log('Marker was clicked (' + marker + ', ' + eventName);//+', '+mydump(model, 0)+', '+mydump(arguments)+')');
$scope.map.window.model = model;
$scope.map.window.model = model;
$scope.map.window.title = model.title;
$scope.map.window.venue = model.venue;
$scope.map.window.show = true;
}
},
window: {
marker: {},
show: false,
closeClick: function() {
this.show = false;
},
options: {}, // define when map is ready
title: ''
}
};
//$scope.window = false;
$scope.onMarkerClicked = function (m) {
//this.windowOptions = !this.windowOptions;
console.log('Marker was clicked');
console.log(m);
};
$scope.closeClick = function () {
this.window = false;
};
$scope.map = data.map;
});
1) To resolve location by address name utilize Google Maps Geocoding API, for example:
var resolveAddress = function(address) {
var deffered = $q.defer();
$http({
url: 'http://maps.googleapis.com/maps/api/geocode/json?address=' + address + '&sensor=false',
method: 'GET'
}).
success(function(data) {
deffered.resolve(data);
}).
error(function(error) {
deffered.reject();
});
return deffered.promise;
};
2) For angularjs-dropdown-multiselect component you could utilize events to add events what the directive fires, for example onItemSelect which triggers once the item is selected:
<div class="m-r"
ng-dropdown-multiselect=""
options="locations"
selected-model="search.locations"
translation-texts="locationsTexts"
settings="selectSettings"
events="{ onItemSelect: showItemOnMap }">
</div>
$scope.showItemOnMap = function(item) {
//...
};
The following demo demonstrates how to display markers on map from items selected in angularjs-dropdown-multiselect control
Demo

Angular Google Maps "Marker" directive not working

Building a website that has 2 different google maps on the same page. The maps load fine. Im trying to add markers to the maps, and keep getting this error."MarkersParentModel: no valid models attribute "
My controller is :
angular.module('footStoreApp')
.controller('ContactpageCtrl', function ($scope, uiGmapGoogleMapApi) {
uiGmapGoogleMapApi.then(function(maps) {
});
$scope.map = { center: { latitude: 32.830593, longitude: -79.825432 }, zoom: 14 };
$scope.marker = {
id: 1,
coords: {
latitude: 32.830593,
longitude: -79.825432
},
};
$scope.map2 = { center: { latitude: 32.863488, longitude: -80.023833 }, zoom: 14 };
$scope.marker2 = {
id: 2,
coords: {
latitude: 32.863488,
longitude: -80.023833
}
}
});
The directives are :
<div>
<ui-gmap-google-map center='map.center' zoom='map.zoom'><ui-gmap-markers idkey='marker.id' coords='marker.coords'>
</ui-gmap-markers></ui-gmap-google-map>
</div>
<ui-gmap-google-map center='map2.center' zoom='map2.zoom'><ui-gmap-markers idkey='marker2.id' coords='marker2.coords'>
</ui-gmap-markers></ui-gmap-google-map>
You have used ui-gmap-markers directive instead of ui-gmap-marker.
See the documentation (http://angular-ui.github.io/angular-google-maps/#!/api). there are two directives (marker and markers).
Corrected Code:
var myApp = angular.module('myapp', ['uiGmapgoogle-maps']);
myApp.controller('MyCtrl1', function ($scope, uiGmapGoogleMapApi) {
uiGmapGoogleMapApi.then(function (maps) {
$scope.map = {
center: {
latitude: 32.830593,
longitude: -79.825432
},
zoom: 14
};
$scope.marker = {
id: 1,
coords: {
latitude: 32.830593,
longitude: -79.825432
}
};
$scope.map2 = {
center: {
latitude: 32.863488,
longitude: -80.023833
},
zoom: 14
};
$scope.marker2 = {
id: 2,
coords: {
latitude: 32.863488,
longitude: -80.023833
}
}
});
})
.angular-google-map-container {
height: 400px;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.8.0/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-google-maps/2.1.1/angular-google-maps.min.js"></script>
<div ng-app="myapp">
<div ng-controller="MyCtrl1">
<ui-gmap-google-map center='map.center' zoom='map.zoom'>
<ui-gmap-marker idkey='marker.id' coords='marker.coords'></ui-gmap-marker>
</ui-gmap-google-map>
<hr/>
<ui-gmap-google-map center='map2.center' zoom='map2.zoom'>
<ui-gmap-marker idkey='marker2.id' coords='marker2.coords'></ui-gmap-marker>
</ui-gmap-google-map>
</div>
</div>

Polylines angularjs setVisible: not a boolean

I'm trying to implement polylines into my map application, I get dynamics latlng and push them into an array of polylines,but I'getting an error that I don't know why:
Error: setVisible: not a boolean
but the visible is set to true, what is wrong with it?
var x = 0;
$scope.enderecos.forEach(function (posicao) {
$scope.markers.push({
id: x,
coords: {
latitude: parseFloat(posicao.latitude),
longitude: parseFloat(posicao.longitude)
}
});
$scope.polylines.push({
id: x,
path:[{
latitude: parseFloat(posicao.latitude),
longitude: parseFloat(posicao.longitude)
}],
stroke: {
color: '#6060FB',
weight: 4
},
editable: true,
draggable: false,
geodesic: false,
visible: true
});
x++;
});
html:
<div class="angular-google-map-container">
<ui-gmap-google-map center="map.center" zoom="map.zoom" draggable="true" options="map.options" events="map.events"
control="googlemap">
<ui-gmap-window coords="MapOptions.markers.selected.coords" show="windowOptions.show" options="windowOptions"
closeClick="closeClick()">
<div>Hello</div>
</ui-gmap-window>
<ui-gmap-polylines models="polylines" path="'path'" stroke="'stroke'" visible="'visible'"
geodesic="'geodesic'" editable="'editable'" draggable="'draggable'" static="true">
</ui-gmap-polylines>
<ui-gmap-markers models="markers" idkey="markers.id" coords="'coords'" click="'onClick'"
events="markers.events"></ui-gmap-markers>
</ui-gmap-google-map>
</div>
This is my complete mapController:
.controller('MapController', function ($scope, uiGmapGoogleMapApi, $stateParams, uiGmapIsReady, ShowList) {
var viagens_id = $stateParams.viagens_id;
ShowList.enderecoViagem(viagens_id).then(function (listview) {
$scope.enderecos = listview;
$scope.MapOptions = {
minZoom: 3,
zoomControl: false,
draggable: true,
navigationControl: false,
mapTypeControl: false,
scaleControl: false,
streetViewControl: false,
disableDoubleClickZoom: false,
keyboardShortcuts: true,
markers: {
selected: {}
},
styles: [{
featureType: "poi",
elementType: "labels",
stylers: [{
visibility: "off"
}]
}, {
featureType: "transit",
elementType: "all",
stylers: [{
visibility: "off"
}]
}]
};
uiGmapGoogleMapApi.then(function (maps) {
maps.visualRefresh = true;
$scope.googlemap = {};
$scope.map = {
center: {
latitude: $scope.enderecos[0].latitude,
longitude: $scope.enderecos[0].longitude
},
zoom: 12,
pan: 1,
options: $scope.MapOptions,
control: {},
events: {
tilesloaded: function (maps, eventName, args) {
},
dragend: function (maps, eventName, args) {
},
zoom_changed: function (maps, eventName, args) {
}
}
};
});
$scope.windowOptions = {
show: false
};
$scope.onClick = function (data) {
$scope.windowOptions.show = !$scope.windowOptions.show;
console.log('$scope.windowOptions.show: ', $scope.windowOptions.show);
console.log('This is a ' + data);
//alert('This is a ' + data);
};
$scope.closeClick = function () {
$scope.windowOptions.show = false;
};
$scope.title = "Window Title!";
$scope.markers = [];
$scope.polylines = [];
var x = 0;
$scope.enderecos.forEach(function (posicao) {
$scope.markers.push({
id: x,
coords: {
latitude: parseFloat(posicao.latitude),
longitude: parseFloat(posicao.longitude)
}
});
$scope.polylines.push({
id: x,
path: [{
latitude: parseFloat(posicao.latitude),
longitude: parseFloat(posicao.longitude)
}],
stroke: {
color: '#6060FB',
weight: 4
},
editable: true,
draggable: false,
geodesic: true,
visible: true
});
x++;
});
$scope.addMarkerClickFunction = function (markersArray) {
angular.forEach(markersArray, function (value, key) {
value.onClick = function () {
$scope.onClick(value.data);
$scope.MapOptions.markers.selected = value;
};
});
};
uiGmapIsReady.promise() // if no value is put in promise() it defaults to promise(1)
.then(function (instances) {
console.log(instances[0].map); // get the current map
})
.then(function () {
$scope.addMarkerClickFunction($scope.markers);
});
});
})
I think that your error is in this line:
<ui-gmap-polylines models="polylines" path="'path'" stroke="'stroke'" visible="'visible'"geodesic="'geodesic'" editable="'editable'" draggable="'draggable'" static="true">
</ui-gmap-polylines>
You put the variable "visible" between two simple quotes " ' ". This transforms the variable visible into the String visible. You are evaluating the string 'visible', not the boolean true
Try this:
<ui-gmap-polylines models="polylines" path="path" stroke="stroke" visible="visible"geodesic="geodesic" editable="editable" draggable="draggable" static="true">
</ui-gmap-polylines>

Resources