Override KML/KMZ default zoom level in Google Maps Viz

wqwi853

Member
I would like to have my google maps viz's zoom settings override the default zoom that's associated with my KML/KMZ overlays.

Every time I do a search or refresh, the KML/KMZ zoom takes precedence over my visualizations zoom settings.

When I turn on "Preserve Viewport" in my overlay settings, the map just centers in Kazakhstan.
 
There's nothing in the KML file that dictates the zoom level.

When I turn off preserve viewport in the maps viz itself, the map just centers itself on the other side of the world.
 
There are two maps. One has lots of shapes the other has lots of markers.

I had to break down the files into smaller KMZ's because it appeared that google didn't want to display the original, larger KMZ.

If I break it out into smaller KMZ's it seems like I can get the map to work.

Although the bubble data on the map with the blue polygons won't display correctly for whatever reason. If I open up the KMZ in google earth, all the bubble data looks fine.
 
You sent me a PM, but you didn't really answer the question:

Do you have any actual map markers showing?

If you only have an overlay, and no actual map markers showing, then "preserve viewport" won't work, as it'll try and center the viewport on nothing.

You may have to add some custom JS to handle the overlay events and manually center/zoom.

-- hugh
 
Okay, that makes sense. Would the custom JS need to be added to actual files on the web server or can I accomplish that with another element/plugin?
 
You'll have to add it to ./component/com_fabrik/js/viz_X.js (where X is the numeric ID of your map viz).

To make life easier, I just added an event, fired when the overlays have been added, so you'll need to do a github update to pick up this commit:

https://github.com/Fabrik/fabrik/commit/ab85c1ceb067c00a25db09ec98a015371443851d

Then in your viz_X.js, do something like this:

Code:
// use requirejs to wait till Fabrik has been initialized
requirejs(['fab/fabrik'], function() {
   // listen for the overlays.added event ...
   Fabrik.addEvent('fabrik.viz.googlemap.overlays.added', function(viz) {
      // viz is the map viz object, overlays are in the viz.options.overlays array, so iterate through that ...
      jQuery.each(viz.options.overlays, function(key, overlay) {
         // add a maps event listener for defaultviewpoert_changed for each overlay
         google.maps.event.addListener(overlay, 'defaultviewport_changed', function() {
            // set the bounds
            var bounds = overlay.getDefaultViewport();
            viz.map.setCenter(bounds.getCenter());
         });
      });
   });
});

Note that the innermost part of that, the defaultviewport_changed bit, I'm just cribbing from a Stack Overflow discussion about how to override the zoom / viewport change. I have no idea if it works, and you may need to fiddle with that.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top