Visualizzazione dei risultati da 1 a 6 su 6
  1. #1
    Utente di HTML.it L'avatar di supermac
    Registrato dal
    Jun 2001
    Messaggi
    1,856

    GoogleMaps cluster di markers non riesce

    FORUM SBAGLIATO, SPOSTATEMI PLEASE GRAZIE

    Non capisco, non riesco a fare i cluster di markers: continuo ad ottenere un milione di markers singoli e nella consolle di errore vedo marker.getPosition is not a function.
    Se posto un po' di codice qualcuno mi illumina?
    Here it is:
    codice:
        var mymap;
        var mapExists = !!document.getElementById("nomemappa");
        var allMyMarkers = [];
       
        var stylem = [
            {stili mappa }
        ]
    
        var customLabel = {
            P: {
                label: '',
                icon: '/Google%20Maps%20Markers/orange_MarkerP.png'
            },
            S: {
                label: '',
                icon: '/Google%20Maps%20Markers/blue_MarkerS.png'
            }
        };
    
    
    
        function initMap() {
            if (mapExists) {
                mymap = new google.maps.Map(document.getElementById('macmap'), {
                    center: new google.maps.LatLng(latitudine, longitudine),
                    zoom: 12,
                    styles: stylem 
                });
                
                var bounds = new google.maps.LatLngBounds();
                var infoWindow = new google.maps.InfoWindow;
    
                //hfQS > ashx > xml
                downloadUrl(document.getElementById("hfQS").innerText, function (data) {
                    var xml = data.responseXML;
                    var markers = xml.documentElement.getElementsByTagName('marker');
    
                    // Add a marker clusterer to manage the markers in locations array.
                    var markerCluster = new MarkerClusterer(mymap, markers, { imagePath: '/Google%20Maps%20Markers' });
           
                    Array.prototype.forEach.call(markers, function (markerElem) {
                        var name = markerElem.getAttribute('name');
    
                        var point = new google.maps.LatLng(
                            parseFloat(markerElem.getAttribute('lat')),
                            parseFloat(markerElem.getAttribute('lng')));
                        bounds.extend(point);
                        
                        var infowincontent = document.createElement('div');
                        var strong = document.createElement('h3');
                        strong.textContent = name;
                        infowincontent.appendChild(strong);
                  
                        var myicon = customLabel[type] || {};
    
                        var marker = new google.maps.Marker({
                            map: mymap,
                            position: point,
                            label: myicon.label,
                            icon: myicon.icon
                        });
                                            
                        markerCluster.addMarker(marker, false);
    
                        allMyMarkers.push(marker);
                            
                        marker.addListener('click', function () {
                            infoWindow.setContent(infowincontent);
                            infoWindow.open(mymap, marker);
                        });
    
                    }); //fine for
    
                    mymap.fitBounds(bounds);
    
                });
    
                // Override map zoom level once our fitBounds function runs 
                var boundsListener = google.maps.event.addListener((mymap), 'bounds_changed', function (event) {
                    this.setZoom(14);
                    google.maps.event.removeListener(boundsListener);
                });
            }
        }
    
    
        function downloadUrl(url, callback) {
            var request = window.ActiveXObject ?
                new ActiveXObject('Microsoft.XMLHTTP') :
                new XMLHttpRequest;
    
            request.onreadystatechange = function () {
                if (request.readyState == 4) {
                    request.onreadystatechange = doNothing;
                    callback(request, request.status);
                }
            };
    
            request.open('GET', url, true);
            request.send(null);
        }
    
        function doNothing() { }
    </script>
    
    <script src="/Scripts/markerclusterer.js"></script>
    <script async defer src="https://maps.googleapis.com/maps/api/js?key=chiave&callback=initMap"></script>
    Ultima modifica di supermac; 03-08-2018 a 12:33
    W la Ferari effetrenavenave!
    il computer è un somaro veloce! (neanche tanto ndr)

  2. #2

  3. #3

  4. #4
    Utente di HTML.it L'avatar di supermac
    Registrato dal
    Jun 2001
    Messaggi
    1,856
    up, grazie
    W la Ferari effetrenavenave!
    il computer è un somaro veloce! (neanche tanto ndr)

  5. #5
    Utente di HTML.it L'avatar di supermac
    Registrato dal
    Jun 2001
    Messaggi
    1,856
    Visto che ho anche un array di markers ho provato anche a usare il metodo addMarkers(allMyMarkers,true) dopo il mymap.fitbounds ma con lo stesso risultato... sempre getPosition is not a function :-(

    codice:
    ...
      //markerCluster.addMarker(marker, false);
    
                        marker.addListener('click', function () {
                            infoWindow.setContent(infowincontent);
                            infoWindow.open(mymap, marker);
                        });
    
                        //locations.push(point);
                        allMyMarkers.push(marker);
                    }); //fine array
                    mymap.fitBounds(bounds);
    
                    // Add a marker clusterer to manage the markers in locations array.
                    var markerCluster = new MarkerClusterer(mymap, markers, { imagePath: '/Google%20Maps%20Markers' });
                    markerCluster.addMarkers(allMyMarkers, true);
    
                });
    Esperti di mappe, aiuto!!!
    W la Ferari effetrenavenave!
    il computer è un somaro veloce! (neanche tanto ndr)

  6. #6
    Utente di HTML.it L'avatar di supermac
    Registrato dal
    Jun 2001
    Messaggi
    1,856
    ma che pistola!
    Risolto...
    // Add a marker clusterer to manage the markers in locations array.
    var markerCluster = new MarkerClusterer(mymap, allMyMarkers, { imagePath: '/Google%20Maps%20Markers' });
    W la Ferari effetrenavenave!
    il computer è un somaro veloce! (neanche tanto ndr)

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.