Different marker groups in a strip

I use Angular and a booklet and want to create a map with different markers, for example: ships and bridges. I want to update them separately, without deleting and setting all the markers again. Therefore, when I got new ships, I just want to name the ship markers, update them, and the bridge markers will remain the same.

Now I tried something like this:

angular.module('angularMapApp') .controller('MainCtrl', ['$scope', 'RequestService', 'setShipMarkers', '$q', function($scope, RequestService, setShipMarkers, $q) { angular.extend($scope, { hamburg: { lat: 53.551086, lng: 9.993682, zoom: 13 }, markers: { ships: { m1: { lat: 42.20133, lng: 2.19110 }, m2: { lat: 42.21133, lng: 2.18110 } }, bridges: { m3: { lat: 42.19133, lng: 2.18110 }, m4: { lat: 42.3, lng: 2.16110 } } }, defaults: { tileLayer: 'http://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png', zoomControlPosition: 'topright', tileLayerOptions: { opacity: 0.9, detectRetina: true, reuseTiles: true, }, scrollWheelZoom: false } }); 

But this does not work, as I get the following error (after setting markers-nested: true in my opinion):

You must add layers to the directive if markers will use this functionality.

However, why do I need layers if I just want to call a group of different markers on the same layer. I just don't want to update them all at once.

So maybe someone can tell me how to get individual groups of markers and how to call them to update them.

+5
source share
1 answer

For each type of nested marker, you need to create your own group layer, which may be empty:

 layers: { overlays: { ships: { // use the same name as in the marker object name: "Ships", type: "group", visible: true }, bridges: { // use the same name as in the marker object name: "bridges", type: "group", visible: true } } } 

In doing so, you will also have to move the OSM base layer to the layers.baselayers object, but markers-nested="true" works this way.

Demo: http://plnkr.co/edit/HQx8bQmmsFUGcLxYt95N?p=preview

+1
source

Source: https://habr.com/ru/post/1241931/


All Articles