Hoe kan ik OverlappingMarkerSpiderfier integreren in deze code?

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Snelle Jaap

Snelle Jaap

14/11/2017 13:58:20
Quote Anchor link
Hallo,

Ik probeer de extensie "OverlappingMarkerSpiderfier" te integreren in mijn google maps code. Ik zit namelijk met het probleem dat op mijn kaart een aantal markers precies dezelfde coordinaten hebben. Daarbij gebruik ik de markerclusterer van Google om dichtbij elkaar staande markers te grouperen. Wanneer twee markers dus op elkaar staan zal die gegroupeerde marker nooit splitten in de twee markers die eronder zitten, hoe ver je ook inzoomt.

Vandaar dat ik spiderfier wil gebruiken, dit splitst alle op elkaar staande markers en trekt ze uit elkaar wanneer je erop klikt.

Ik heb een poging gewaagd dit te integreren in mijn google maps code maar ik kom er niet uit.

Mijn oude zonder de integratie:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
(function($) {
    "use strict";

    var map;
    var bedrijvenlijst = []; // nieuwe array
    $.each( bedrijven, function( key, value ) {
      // console.log( key + ": " + value.plaats );
      bedrijvenlijst.push({
          title : value.title,
          alias : value.alias,
          image : value.image,
          address : value.straat + ' ' + value.plaats,
          position : {
              lat : parseFloat( value.lat ),
              lng : parseFloat( value.lng )
          },
          markerIcon : 'marker-green.png'
      });
    });

    var props = bedrijvenlijst; // Voeg de array toe
    // console.log('niet mobiel');
      setTimeout(function() {
          $('body').removeClass('notransition');

          if ($('#home-map').length > 0) {
              map = new google.maps.Map(document.getElementById('home-map'), options);

              var styledMapType = new google.maps.StyledMapType(styles, {
                  name : 'Styled'
              });

              map.mapTypes.set('Styled', styledMapType);
              map.setCenter(new google.maps.LatLng(51.8410662,4.3000354));
              map.setZoom(13);

              var markers = props.map(function(prop, i) {
                var marker = new google.maps.Marker({
                  position: prop.position,
                  icon: new google.maps.MarkerImage(
                      'images/' + prop.markerIcon,
                      new google.maps.Size(36, 36),
                      new google.maps.Point(0, 0),
                      new google.maps.Point(18, 36),
                      new google.maps.Size(36, 36)
                  ),
                });

                var infoboxContent = '<div class="infoW">' +
                                        '<div class="propImg">' +
                                            '<img style="object-fit:contain;" src="images/' + prop.image + '">' +
                                            '<div class="propBg">'+
                                                // '<div class="propPrice">' + prop.price + '</div>'+
                                                 '</div>' +
                            '</div>' +
                      '<div class="paWrapper">' +
                        '<div class="propTitle">' + prop.title + '</div>' +
                        '<div class="propAddress">' + prop.address + '</div>' +
                      '</div>' +
                      '<div class="clearfix"></div>' +
                      '<div class="infoButtons">' +
                        '<a class="btn btn-sm btn-round btn-gray btn-o closeInfo">Sluit</a>' +
                        '<a href="'+ prop.alias +'.html" class="btn btn-sm btn-round btn-green viewInfo">Bekijk</a>' +
                      '</div>' +
               '</div>';

               google.maps.event.addListener(marker, 'click', (function(marker, i) {
                   return function() {
                       infobox.setContent(infoboxContent);
                       infobox.open(map, marker);
                      //  map.setCenter(new google.maps.LatLng(marker.position.lat,marker.position.long));
                      //  map.event.trigger(map, 'resize');
                   }
               })(marker, i));

               $(document).on('click', '.closeInfo', function() {
                   infobox.open(null,null);
               });

               return marker;
             });

              var markerCluster = new MarkerClusterer(
                map,
                markers,
                {
                  imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'
                }
              );

              var addMarkers = function(props, map) {

              }

              addMarkers(props, map);
          }
      }, 300);
    var options = {
        zoom : 13,
        mapTypeId : 'Styled',
        disableDefaultUI: false,
        mapTypeControlOptions : {
            mapTypeIds : [ 'Styled' ]
        },
        zoomControl: true,
          zoomControlOptions: {
              position: google.maps.ControlPosition.RIGHT_CENTER
          },
          streetViewControl: true,
                    streetViewControlOptions: {
                        position: google.maps.ControlPosition.RIGHT_CENTER
                    },

        scrollwheel: false
    };
    var styles = [{
        stylers : [ {
            hue : "#cccccc"
        }, {
            saturation : -100
        }]
    }, {
        featureType : "road",
        elementType : "geometry",
        stylers : [ {
            lightness : 100
        }, {
            visibility : "simplified"
        }]
    }, {
        featureType : "road",
        elementType : "labels",
        stylers : [ {
            visibility : "on"
        }]
    }, {
        featureType: "poi",
        stylers: [ {
            visibility: "off"
        }]
    }];

    var infobox = new InfoBox({
        disableAutoPan: false,
        maxWidth: 202,
        pixelOffset: new google.maps.Size(-101, -285),
        zIndex: null,
        boxStyle: {
            background: "url('images/infobox-bg.png') no-repeat",
            opacity: 1,
            width: "202px",
            height: "245px"
        },
        closeBoxMargin: "28px 26px 0px 0px",
        closeBoxURL: "",
        infoBoxClearance: new google.maps.Size(1, 1),
        pane: "floatPane",
        enableEventPropagation: false
    });
})(jQuery);


En mijn poging tot integratie:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
(function($) {
    "use strict";


    var map;

    var bedrijvenlijst = []; // nieuwe array
    $.each( bedrijven, function( key, value ) {
      // console.log( key + ": " + value.plaats );
      bedrijvenlijst.push({
          title : value.title,
          alias : value.alias,
          image : value.image,
          address : value.straat + ' ' + value.plaats,
          position : {
              lat : parseFloat( value.lat ),
              lng : parseFloat( value.lng )
          },
          markerIcon : 'marker-green.png'
      });
    });

    var props = bedrijvenlijst; // Voeg de array toe
  setTimeout(function() {
          $('body').removeClass('notransition');

          if ($('#home-map').length > 0) {
              map = new google.maps.Map(document.getElementById('home-map'), options);

              var styledMapType = new google.maps.StyledMapType(styles, {
                  name : 'Styled'
              });

              map.mapTypes.set('Styled', styledMapType);
              map.setCenter(new google.maps.LatLng(51.8410662,4.3000354));
              map.setZoom(13);

              var oms = new OverlappingMarkerSpiderfier(map, {
                markersWontMove: true,
                markersWontHide: true,
                basicFormatEvents: true
              });

              var markers = props.map(function(prop, i) {
                var marker = new google.maps.Marker({
                  position: prop.position,
                  icon: new google.maps.MarkerImage(
                      'images/' + prop.markerIcon,
                      new google.maps.Size(36, 36),
                      new google.maps.Point(0, 0),
                      new google.maps.Point(18, 36),
                      new google.maps.Size(36, 36)
                  ),
                });

                var infoboxContent = '<div class="infoW">' +
                                        '<div class="propImg">' +
                                            '<img style="object-fit:contain;" src="images/' + prop.image + '">' +
                                            '<div class="propBg">'+
                                                // '<div class="propPrice">' + prop.price + '</div>'+
                                                 '</div>' +
                            '</div>' +
                      '<div class="paWrapper">' +
                        '<div class="propTitle">' + prop.title + '</div>' +
                        '<div class="propAddress">' + prop.address + '</div>' +
                      '</div>' +
                      '<div class="clearfix"></div>' +
                      '<div class="infoButtons">' +
                        '<a class="btn btn-sm btn-round btn-gray btn-o closeInfo">Sluit</a>' +
                        '<a href="'+ prop.alias +'.html" class="btn btn-sm btn-round btn-green viewInfo">Bekijk</a>' +
                      '</div>' +
               '</div>';

               google.maps.event.addListener(marker, 'spider_click', (function(marker, i) {
                   return function() {
                       infobox.setContent(infoboxContent);
                       infobox.open(map, marker);
                      //  map.setCenter(new google.maps.LatLng(marker.position.lat,marker.position.long));
                      //  map.event.trigger(map, 'resize');
                   }
               })(marker, i));

               $(document).on('click', '.closeInfo', function() {
                   infobox.open(null,null);
               });

               return marker;
             });

              var markerCluster = new MarkerClusterer(
                map,
                markers,
                {
                  imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m',
                  maxZoom: 15
                }
              );

              var addMarkers = function(props, map) {

              }

              oms.addMarkers(props, map);
          }
      }, 300);
  var options = {
        zoom : 13,
        mapTypeId : 'Styled',
        disableDefaultUI: false,
        mapTypeControlOptions : {
            mapTypeIds : [ 'Styled' ]
        },
        zoomControl: true,
          zoomControlOptions: {
              position: google.maps.ControlPosition.RIGHT_CENTER
          },
          streetViewControl: true,
                    streetViewControlOptions: {
                        position: google.maps.ControlPosition.RIGHT_CENTER
                    },

        scrollwheel: false
    };

    var styles = [{
        stylers : [ {
            hue : "#cccccc"
        }, {
            saturation : -100
        }]
    }, {
        featureType : "road",
        elementType : "geometry",
        stylers : [ {
            lightness : 100
        }, {
            visibility : "simplified"
        }]
    }, {
        featureType : "road",
        elementType : "labels",
        stylers : [ {
            visibility : "on"
        }]
    }, {
        featureType: "poi",
        stylers: [ {
            visibility: "off"
        }]
    }];

    var infobox = new InfoBox({
        disableAutoPan: false,
        maxWidth: 202,
        pixelOffset: new google.maps.Size(-101, -285),
        zIndex: null,
        boxStyle: {
            background: "url('images/infobox-bg.png') no-repeat",
            opacity: 1,
            width: "202px",
            height: "245px"
        },
        closeBoxMargin: "28px 26px 0px 0px",
        closeBoxURL: "",
        infoBoxClearance: new google.maps.Size(1, 1),
        pane: "floatPane",
        enableEventPropagation: false
    });
})(jQuery);
 
Er zijn nog geen reacties op dit bericht.



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.