Move marker on Openstreet map - Leaflet - maps

I use the following plug-in to move the marker on the map - https://github.com/openplans/Leaflet.AnimatedMarker
Faced with such a problem that the zoom the map, markers are beginning to jump on it. How is that correct?

you do not need a plugin.
this should do it
marker.setLatLng([lat, long]);

Related

Angularjs Openlayer draw polyline

I hope to find a quick answer for my problem.
I am using openlayer directive (https://github.com/tombatossals/angular-openlayers-directive) to draw a map in my App.
I would like to add polyline to the map which shows a route on this map.
I could not find any solution for this. Is it possible to draw these lines?
Thank you for your help!
If you want to draw a line between set of points, first transform each co-ordinate
points.push(ol.proj.transform([xx,yy],'EPSG:4326', 'EPSG:3857'));
then create LineString Geometry
var thing = new ol.geom.LineString(points);
and create a feature and add it to a layer
var feature = new ol.Feature({
name: "Thing",
geometry: thing
})
});
vectorSource.addFeature( feature );
Demo
https://plnkr.co/edit/WqWoFzjQdPDRkAjeXOGn?p=preview

How can I reinitialize ngMaps when changing routes in Angular, using ui-router?

I'm using ngMap and here's my relevant code:
<div map-lazy-load="https://maps.google.com/maps/api/js" map-lazy-load-params="{{googleMapsUrl}}" ng-style="{'height': feedActualHeight + 'px'}">
<ng-map id="iPadFeedMap" zoom="14" center="Times Square, New York, NY">
</ng-map>
</div>
This works great and loads the map perfectly. But when I navigate away and then come back to the page, the map is grayed out:
Is there a way to re-initialize the map when this page loads?
I experienced the exact same issue regardless of how center was being set (it failed both with lat/lng and a physical address), but the accepted answer wasn't quite working for me.
My solution was to use NgMap's lazy-init property to re-initialize the map each time I returned to it.
<ng-map id="dashboard-map"
center="Boston, MA"
lazy-init="true"
zoom="9"
map-type-id="TERRAIN">
</ng-map>
In my ctrl I used the following code to 1) find the uninitialized map in the DOM and 2) initialize it
// dashboardCtrl.js
NgMap.getMap({ id: "dashboard-map" }).
then(function(map) {
NgMap.initMap(map.id);
});
This way every time I hit my dashboard, the ctrl would run and re-init the map. It now shows properly every time.
This was a helpful thread to read through: https://github.com/allenhwkim/angularjs-google-maps/issues/387
It seems it only occurs in case when value for center attribute is provided as address value (e.g. Times Square, New York, NY). In that case the way the map center is determined consist of the following steps:
since ng-map leverages Google Maps Geocoding API, the corresponding method is invoked to resolve actual location (lat,lng)
Map object center property is getting updated
Since this issue never occurred for me when center attribute is provided as location value (e.g. [40.759011, -73.98447220000003]) i propose to change the way how map is initialized:
remove setting of center attribute center="Times Square, New
York,NY"
instead set map center as demonstrated below:
Example: set map center by address
NgMap.getMap("iPadFeedMap").then(function (map) {
NgMap.getGeoLocation($scope.address)
.then(function (latlng) {
map.setCenter(latlng);
});
});
$scope.address = "Times Square, New York, NY";
Demo

update markers when not watched

In angular-leaflet-directive is there a way how to update markers and paths on the map when we switch off the $watch using markersWatchOptions?
I think you are look for something similar to this example:
http://angular-ui.github.io/ui-leaflet/examples/0000-viewer.html#/mixed/overlays-markers-nested-no-watch-example
In which, markers are updated via getDirectiveControls().
There is more about it in this issue:
https://github.com/angular-ui/ui-leaflet/issues/239

Get marker location in Angular Leaflet Direction

I'm using Angular Leaflet Directive. In the example, say here form the docs (http://tombatossals.github.io/angular-leaflet-directive/#!/examples/dragging-markers), we have a marker that is draggable. Changing the location of the draggable Madrid marker is possible by clicking up and down on the lat/lng input.
Is there a way for the reverse to happen? That is, when the marker is dragged, the location is updated in those input values?
Alternately, is there a way to access a specific marker and retrieve its coordinates with the directive?
you should take a look at this link: http://tombatossals.github.io/angular-leaflet-directive/examples/0500-markers-simple-example.html
Specifically at those lines:
$scope.$on("leafletDirectiveMarker.dragend", function(event, args){
$scope.position.lat = args.model.lat;
$scope.position.lng = args.model.lng;
});
There is also a marker ID, if you have more than one marker on the map.
Also, you should know that when you drag marker, lat/lng properties of that marker update themselves, so you can use simple $watch, too.

Adding location to Google Map on page load with Angular UI

Thanks to #AJoslin I now have a working google map using only AngularUI and AngularJS.
Unfortunately there are two things I can't figure out how to do which may have to do with Google Map API and my lack of understanding of.
When the map initially loads, I already have a location so I wish to load it with a marker already on it. How do I do that?
I also wish to set the ng-click="myMap.panTo(marker.getPosition()) not to a new marker but to the initial location, which is the only marker I would have since I'm removing the add marker functionality out, once I can figure this one out.
Here is the working jsfiddle
http://jsfiddle.net/jorgecas99/xMw6U/
i think it should be achievable by setting the tilesloaded event, but didnt manage that way, so i ended up using a simple "trick", watching for myMap to appear.
$scope.$watch('myMap', function(){
$scope.setHome();
});
$scope.setHome = function() {
$scope.homeMarker = new google.maps.Marker({
map: $scope.myMap,
position: $scope.mapOptions.center
});
}

Resources