I am trying to use the angular google maps(http://angular-ui.github.io/angular-google-maps/) directive in my application, so converting my code to work with that directive and stuck up in that process to apply custom shape to the markers.
Anybody who is familiar with angular google maps can help me to resolve this issue, please check the below mentioned code written in plain google maps library and let me know how to make this code working with the angular google maps directive.
new google.maps.Marker({
position: latLng,
map: map,
icon: {
url: 'path/to/icon',
origin:new google.maps.Point(0,0),
anchor:new google.maps.Point(3,4)
},
shape: {
coords:[0, 6, 7, 0, 16, 0, 23, 6, 12, 12],
type:"poly"
}
});
Yeah, I found the solution here, we need to set that as an attribute to OPTIONS object as mentioned below:
markers.push({
latitude: site.latitude,
longitude: site.longitude,
id: 1,
icon: {
url: 'path/to/icon',
origin: origin,
anchor: anchor
},
options: {
shape: {
coords: phaseMarker.coords,
type: "poly"
}
}
});
Note: I tried this even before posting this question, but that didn't worked well due to duplicate ID attribute for markers, so make sure we have unique ID for each marker if we have a set of markers in our map.
Related
I'm working on a mapbox app and I need to make a dynamic URL to reflect mapbox info like lat, long and zoom level.
ex: /?city=London&zoom=1&lat=30&lng=140. On page load map should be centred and zoomed accordingly. How to read/write page URL?
Just activate the hash : true in the Map initial settings
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/outdoors-v11',
center: [128, 47],
zoom: 16.5,
pitch: 60,
hash: true // just add this
});
It’s not the same param names but you’ll have the same information
Kind of an odd question/hard to find an answer. I'm relatively new to using angularjs and have a problem i'm confused about.
I've set up a google map using http://angular-ui.github.io/angular-google-maps/#!/ and have an issue.
So i have a $scope.homeBase where i am setting a lat & long for the owners 'Home Base', i want to use that location to set the on load map center, & a pin to show the location. So in my mind cool, set the one var and use it in both locations. Wrong.
So this works on load, but every time i pan the map, i guess it re-sets the map center location, which in turn binds to the map marker and sends the marker to the middle of the screen, on every pan.
Is there anyway to have the two not bound? or have separate vars? without them bound?
i thought a simple 'var homebase' would remove binding and not update the var. instead of using scope but it still binds?
This perhaps is a newb question but i appreciate any pointing in proper direction.
Thanks again
here's my code.
// uiGmapGoogleMapApi is a promise, The "then" callback function provides a maps object.
uiGmapGoogleMapApi.then(function() {
// Setting homebase coords, these will come from firebase
$scope.homeBase = { latitude: -34.18405, longitude: 150.71319 };
// Set default map.
$scope.map = {
center: $scope.homeBase,
pan: true,
zoom: 14,
events: {
click: function(){
}
}
};
// Set homebase marker.
$scope.homebaseMarker = {
id: 0,
coords: $scope.homeBase,
options: { draggable: false },
};
});
I was able to set the center on page load via
angular.copy(var)
Preamble
I'm using Angular Google Maps to indicate the location of different buildings across a campus. My initilization goes as follows:
$scope.map = {
control: {},
center:
{
latitude: $scope.Item.Latitude,
longitude: $scope.Item.Longitude
},
zoom: 16,
options: {
streetViewControl: true,
maxZoom: 20,
minZoom: 8,
mapTypeId: google.maps.MapTypeId.HYBRID
},
showTraffic: true,
showBicycling: true,
events: {
blacklist: ['drag', 'dragend', 'dragstart', 'center_changed']
}
};
That works flawlessly for the following visualization:
However, I just noticed that there is 3D data available for the region, and I would like to have it renderized as such:
Question
Is it possible, via Angular Google Maps, to configure my initialization in such a way as to show the map as indicated?
Bonus Question
...would it be possible to programatically have the 'camera' spin around the marker (or the center)?
This is the Map link for the reference images:
https://www.google.com/maps/#40.9570608,-76.8816097,179a,20y,180h,41.69t/data=!3m1!1e3
The best you can get with the Google Maps Javascript API is the 45° imagery.
Not like the 3D map visualization, 45° imagery only has:
1) the 45° tile...
2) 4 angels (0, 90, 180, 270)
3) only has SATELLITE mode. (Road names and other maps elements isn't shown even the maps is in HYBRID)
4) it is not available everywhere over the globe. (for example, 40.9570608,-76.8816097)
Look at this example for more information.
http://jsfiddle.net/u1qcf892/
I have a polyline which can contain a lot of points, and also can be changed according to the user behavior, I am currently using Angular Google maps 1.2.x and employment strategy is as follows:
myService.getPoints(id)
.success(function(data){
//in other controller have $scope.p = pService
pService.Polyline = [];
for(var i=0;i<data.length;i++){
var p = {
latitde : data.Latitudefield,
longitude : data.Longitudefield
}
pService.Polyline.push(p);
}
})
This works, but when the number of points is a lot (about 4000 points or more), the application becomes very slow, what strategy can be used to handle this?
This is how I did it to get a faster rendering.
$scope.trackings = [{
id: 1,
geotracks: [{
latitude: 23.0,
longitude: 72.58
}, {
latitude: 23.1,
longitude: 72.58
}]
}, {
id: 2,
geotracks: [{
latitude: 24.0,
longitude: 72.58
}, {
latitude: 23.1,
longitude: 71.58
}]
}];
<div class="row" ng-if="map.show">
<ui-gmap-google-map center="map.center" zoom="map.zoom">
<ui-gmap-polylines models="trackings" path="'geotracks'" static="true"></ui-gmap-polylines>
</ui-gmap-google-map>
</div>
The key here is static="true". I had to wrap it all in a ng-if="map.show" that I set true when data is ready, because the static keyword makes it, well, static (and not async). Hope this helps :)
Ref: http://angular-ui.github.io/angular-google-maps/#!/api/polylines
static: Boolean property which indicates that the Polyline coordinates are static.(I.e. will not change).
Declaring a static path will improve the performance of the directive as it does not need to monitor every coordinate in the path for changes during the Angular $digest cycle.
Notes:
Declaring a static path implies that it is not editable. As a result, the editable parameter will be ignored.
For static paths, the path attribute will watched by reference so the path may be changed in its entirety and the map will update.
Changes to the static declaration are ignored after the directive is instantiated. (NOT WATCHED)
I am using Google Maps for AngularJS and have the following Jade code:
#map_canvas
google-map(center='map.center', zoom='map.zoom', draggable='true', options='options', events='map.events')
marker(coords='marker.coords', options='marker.options', idkey='marker.id')
In my angular controller I have:
$scope.map = {center: {latitude: 42.2405, longitude: -8.7207 }, zoom: 12, events: {
click: function (map, eventName, args) {
$scope.marker.coords.latitude = args[0].latLng.lat();
$scope.marker.coords.longitude = args[0].latLng.lng();
console.log($scope.marker);
}
}
}
$scope.marker = {
id: 0,
coords: {
latitude: 42.2405, longitude: -8.7207
},
options: { draggable: true }
}
What I am trying is to update the marker location with every click.
At console.log($scope.marker); I can see that my marker does print the updated coordinates value but the red pin does not move on the map.
I can't figure what I am doing wrong.
EDIT:
The marker does move to the new location after I resize the map, so I figured it is a matter of the map no refreshing when marker location changes. Should this be reported as a bug? Anything I can do to solve it?
Finally! After reading a bit on $apply() here and here and finding solutions like this one where it mentions to:
wrap your callback body into $scope.$apply(function () { ... });. Remember
that your event is coming from "non-Angular" world.
I found this other post where it just adds $scope.$apply(); to the end of the click function.
This last solution was the only one working for me.
I've posted all the process cause I consider it interesting to learn about $apply().