development

Google maps KML not playing nice

If you have or are planning on using custom layers of data in KML files over a Google map then you may want to note this down.

By default the layer will recalculate the centre of the map and the zoom level based on the data in the KML. For me on a recent project this was an issue as the user was placing a marker to centre the map, setting a zoom level per map and adding a KML file to each map. But if their KML file only included data for 1 half of their reserve then  the user would be presented with a map defaulting to showing half of the location rather then the optimal zoom level set in the CMS.

The solution is about as simple as they come.

When setting the custom KML file pass this setting after the filename to force it to show some respect for your existing map configuration.

var customKML = new google.maps.KmlLayer('my-kml-file.kml', {preserveViewport:true});

 

Subscribe to RSS - development

Like what you see

You can of course always follow me on twitter to get regular updates