показывать маркеры и отображать другие при нажатии (переключении) - PullRequest
0 голосов
/ 07 декабря 2018

Я ищу способ переключения маркеров. Когда я нажимаю на кнопку, отображается маркер A, а маркеры исчезают, и наоборот.У меня есть 2 кнопки, первая показывает маркеры полиции, вторая показывает маркеры пожарного.Пример: когда я нажимаю на кнопку полиции, маркеры пожарного должны исчезнуть, и маркеры пожарного появляются ...

извините, код не будет отображаться, я не знаю почему!я использовал like _so_, без результата ... ошибка: похоже, ваш пост в основном кодовый;пожалуйста, добавьте больше деталей.

надеюсь, что все понятно, спасибо

`getLocaltions(){
        document.addEventListener("deviceready", function() {
            var div = document.getElementById("map_canvas");

            var map_pomp = plugin.google.maps.Map.getMap(div);
            map_pomp.one(plugin.google.maps.event.MAP_READY, function() {
                // POMPIERS
                document.getElementById("pompier").addEventListener('click',() => {
                    const POMPIERS = {"lat": 48.8472725, "lng": 2.3841632999999547};
                    map_pomp.addCircle({
                    'center': POMPIERS,
                    'radius': 300,
                    'strokeColor' : '#AA00FF',
                    'strokeWidth': 5,
                    'fillColor' : 'yellow'
                    }, function(circlepomp) {

                    setTimeout(function() {
                        circlepomp.setRadius(2500);
                    }, 1000);
                    // circlepolice.remove();
                    });
                    var pomp = [
                        {
                        position: {lng: 2.3841632999999547, lat: 48.8472725},
                        title: "Sapeurs Pompiers",
                    icon: "img/pompier.png",
    animation: plugin.google.maps.Animation.DROP
                        },
                        {
                            position: {lng: 2.405336000000034, lat: 48.8547079},
                            title: "Sapeurs Pompiers Charonne",
                    icon: "img/pompier.png",
    animation: plugin.google.maps.Animation.DROP
                        },
                        {
                            position: {lng: 2.386519000000021, lat: 48.8362749},
                            title: "Centre de Secours Nativité Brigade des Sapeurs Pompiers de Paris",
                    icon: "img/pompier.png",
    animation: plugin.google.maps.Animation.DROP
                        },
                        {
                            position: {lng: 2.3618501999999353, lat: 48.85571950000001},
                            title: "Sapeurs Pompiers - Centre de Secours de Sévigné",
                    icon: "img/pompier.png",
    animation: plugin.google.maps.Animation.DROP
                        }
                    ];

                    // Add markers
                    var baseArrayClass = new plugin.google.maps.BaseArrayClass(pomp);

                    baseArrayClass.map(function(options, cb) {
                    // The variable "options" contains each element of the pomp.
                    //
                    // The variable "cb" is a callback function of iteration.
                    map_pomp.addMarker(options, cb);
                    }, function(markers) {

                    // Set a camera position that includes all markers.
                    var bounds = [];
                    pomp.forEach(function(POI) {
                        bounds.push(POI.position);
                    });

                    map_pomp.moveCamera({
                        target: bounds
                    }, function() {

                        // After camera moves open the last marker.
                        markers[markers.length - 4].showInfoWindow();
                    });

                    });

                });
            });



            // -------------------------------------------------------------------------------
            var map_police = plugin.google.maps.Map.getMap(div);
            map_police.one(plugin.google.maps.event.MAP_READY, function() { 
                // POLICE
                document.getElementById("police").addEventListener('click',() => {
                    const POLICE = {"lat": 48.8510612, "lng": 2.3671649000000343};
                    map_police.addCircle({
                    'center': POLICE,
                    'radius': 300,
                    'strokeColor' : '#AA00FF',
                    'strokeWidth': 5,
                    'fillColor' : '#ddd'
                    }, function(circlepolice) {

                    setTimeout(function() {
                        circlepolice.setRadius(2500);
                    }, 1000);
                    // circlepolice.remove();
                    });
                  var police = [
                    {
                        position: {lng: -6.838469 , lat: 34.023334 },
                        title: "Rabat",
                        'snippet' : "home",
                        icon: "img/home.png",
                        animation: plugin.google.maps.Animation.DROP
                    },
                    {
                        position: {lng: 2.380863399999953, lat: 48.84426},
                        title: "Commissariat central de police ",
                        'snippet' : "Paris 12e arrondissement",
                        icon: "img/police.png",
                        animation: plugin.google.maps.Animation.DROP
                    },
                    {
                        position: {lng: 2.3785209000000123, lat: 48.8543145},
                        title: "Préfecture de Police ",
                        'snippet' : " 11ème Arrondissement",
                        icon: "img/police.png",
                        animation: plugin.google.maps.Animation.DROP
                    },
                    {
                        position: {lng: 2.3671649000000343, lat: 48.8510612},
                        title: "Commissariat de Police",
                        'snippet' : "4e arrondissement",
                        icon: "img/police.png",
                        animation: plugin.google.maps.Animation.DROP
                    },
                    {
                        position: {lng: 2.348542199999997, lat: 48.8494763},
                        title: "Commissariat de Police ",
                        'snippet' : "5e arrondissement",
                        icon: "img/police.png",
                        animation: plugin.google.maps.Animation.DROP
                    },
                        {
                        position: {lng: 2.3558738000000403, lat: 48.83303009999999},
                        title: "Police Nationale",
                        icon: "img/police.png",
                        animation: plugin.google.maps.Animation.DROP
                    }
                  ];

                  // Add markers
                  var baseArrayClass = new plugin.google.maps.BaseArrayClass(police);

                  baseArrayClass.map(function(options, cb) {
                    // The variable "options" contains each element of the data.
                    //
                    // The variable "cb" is a callback function of iteration.
                    map_police.addMarker(options, cb);

                    }, function(markers) {

                        // Set a camera position that includes all markers.
                        var bounds = [];
                        police.forEach(function(POI) {
                        bounds.push(POI.position);
                        });

                        map_police.moveCamera({
                        target: bounds
                        }, function() {

                        // After camera moves open the last marker.
                        markers[markers.length - 3].showInfoWindow();
                        });
                    });
                });
            });
        });
    }`
...