You won't be able to view over 15 KML layers on a page that relies on Google Maps API

I've encountered an unusual issue: I need to create multiple KML layers from separate KML files and display them on a single map window. The number of files ranges from just a couple to less than fifty. Currently, my code works perfectly when given 1, 4, or 15 KML files (as URIs) in an array. So, it's safe to say that the code is functional and the KML files are formatted correctly.

For example, here's how I initialize my map with an array containing 23 KML URIs:

<body id="body" onload="initmap(new Array('https://CENCORED/kml/project64.kml', 'https://CENCORED/kml/project65.kml', 'https://CENCORED/kml/project66.kml', 'https://CENCORED/kml/project67.kml', 'https://CENCORED/kml/project69.kml', 'https://CENCORED/kml/project70.kml', 'https://CENCORED/kml/project71.kml', 'https://CENCORED/kml/project72.kml', 'https://CENCORED/kml/project75.kml', 'https://CENCORED/kml/project76.kml', 'https://CENCORED/kml/project80.kml', 'https://CENCORED/kml/project81.kml', 'https://CENCORED/kml/project82.kml...

However, issues arise when providing the code with an array of sixteen (16) or more KML URIs. In these cases, the KML files fail to render on the map canvas, even though there are no visible errors. How do I know this? Well, although the files may not be rendering visually, the InfoWindows associated with each KML file still appear when clicked, indicating that they exist within the map but are not displaying as intended.

Below is the complete code from my map_display.js file, which includes the initmap() function that is being called:

function initmap(urls){
    // Creating an option object for the map
    var myLatlng = new google.maps.LatLng(63.349501, 26.817627);
    var options = {
        zoom: 6,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    // Initializing the map
    var map = new google.maps.Map(document.getElementById('map_canvas'), options);

    if(urls != null) {
        for(var i=0;i<urls.length;i++) {
            var url = urls[i];
            url = url+"?dummy="+(new Date()).getTime();
            var ctaLayer = createKML(url);
            ctaLayer.setMap(map);
        }
    }

    function createKML(url){

        var ctaLayer = new google.maps.KmlLayer(url, {suppressInfoWindows: true, preserveViewport: true});

        // Creating a correct reference for project edit URL
        var editUrl = urls[i];
        var s1 = editUrl.indexOf("project");
        s1 = s1+7;
        var s2 = editUrl.indexOf(".kml");
        editUrl = editUrl.substring(s1, s2);

        var baseUrl = getbaseUrl();

        var infoItems = new Array();
        infoItems = getInfo(editUrl);

        editUrl = '<b>' + infoItems[1] + '</b><br />' + infoItems[0] + '<br /><br /><a href="' + baseUrl + '/frontend/viewproject/' + editUrl + '">Katso projektin tiedot</a>';
        // Creating an InfoWindow object
        var infowindow = new google.maps.InfoWindow({ content: editUrl });

        google.maps.event.addListener(ctaLayer, 'click', function(kmlEvent) {
            var clickPos = kmlEvent.latLng;
            var posX = new google.maps.LatLng(clickPos.lat(), clickPos.lng());

            infowindow.close();
            infowindow.setPosition(posX);
            infowindow.open(map);

        });

        return ctaLayer;
    }

    function getbaseUrl(){

        var baseUrl = "https://" + window.location.hostname;
        var firstpath = window.location.pathname;
        var first_slash = firstpath.indexOf("/", 1);
        firstpath = firstpath.substring(0, first_slash);
        baseUrl = baseUrl + firstpath;

        return baseUrl;
    }

    function getInfo(pid){

        var jsoninfo = new Array();

        var xmlhttp;
        if (window.XMLHttpRequest)
        {
            xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }

        var json_location = getbaseUrl() + '/frontend/project_json/' + pid;

        xmlhttp.open("GET",json_location,false);
        xmlhttp.send();

        var json_answer = eval('(' + xmlhttp.responseText + ')');

        jsoninfo[0] = json_answer["projectName"];
        jsoninfo[1] = json_answer["builder"];

        return jsoninfo;
    }

}

I'm seeking some assistance. Unfortunately, I can't provide a live system for reference as it's password-protected and part of a larger page.

Answer â„–1

My experience with the default KML layer provided by Google has been somewhat limited in terms of success. For a better option, I suggest giving GeoXML3 or geoxml-v3 (which is not the same project) a try. Personally, I have used GeoXML3 to create a campus map and also experimented with creating my own educational hello world GeoXML3 map on Github.

Answer â„–2

KML layers function by incorporating the URLs of the KML files within the URL of each tile. When multiple KML layers are added, the cumulative length of the tile URLs exceeds 2048 characters, which is the maximum limit for URLs. To address this issue, consider shortening the URLs of the KML layers in use.

Answer â„–3

According to information found on Google's official documentation:

The Google Map has a restriction on the number of KML Layers that can be visible at once. If this limit is surpassed, none of your layers will show up on the map. The limitation is determined by the combined length of all URLs sent to the KMLLayer class, meaning it might differ for each application. On an average basis, you should aim to load around 10 to 20 layers before reaching this imposed threshold.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way for me to store the message I sent using discord.js in a variable?

I'm looking to send a message in the channel and then react to it by getting that message for a message reaction. bot.sendMessage({ to: channelID, message: '@everyone\n' + message.slice(16) + '\n\nThis message is a ...

Updating specific data in MongoDB arrays: A step-by-step guide

{ "_id":{"$oid":"5f5287db8c4dbe22383eca58"}, "__v":0, "createdAt":{"$date":"2020-09-12T11:35:45.965Z"}, "data":["Buy RAM","Money buys freedom"], & ...

The flickering problem with HTML5 DOM

I created a HTML5 game using canvas and DOM elements, but I'm facing an issue with flickering DOM elements while playing. The problem seems to be more prevalent in mobile browsers, particularly Chrome. My game includes a full screen canvas with vario ...

locomotory mesh decentralized sorting

I am attempting to implement in-browser sorting for my flexigrid. Currently, the grid is displaying data from a static XML file exactly how I want it, but the table itself does not sort because it is working off of local data. While researching solutions, ...

Ensuring that all checkboxes have been selected

I have 5 checkboxes all with the attribute name set as relative-view. To confirm that all of them are checked, I know how to verify the first and last one: expect(element.find('input[name="relative-view"]').first().prop("checked")).toBe(true); ...

Using JQuery, identify cells located in the first column of a table excluding those in the header section

In the past, I had code that looked like this: $(elem).parents('li').find(...) I used this code when elem was an item in a list, making it easy to reference all items in the list. But now, I've made some changes and decided to use a table ...

Discover the ultimate guide to creating an interactive website using solely JavaScript, without relying on any server-side

I'm facing a challenge: I have a desire to create a website that is mainly static but also includes some dynamic components, such as a small news blog. Unfortunately, my web server only supports static files and operates as a public dropbox directory. ...

JavaScript date input formatting with HTML

When using the input date picker in HTML, the default format displayed is MM-DD-YYYY. <input type="date" id="gdatum" /> Is there any method to change the mask to DD-MM-YYYY? ...

The script for choosing pages is malfunctioning

I'm having trouble with a script on my website. It works on the index page, but not on other pages. <div id="pages"></div>   <script>      a = location.href;      b = a.split('-');      c = b.length;    ...

Mastering the Art of Displaying Links in Columns within a Table Using ReactJS

I have the following code that fetches data from the backend and displays it in a table. Everything is working correctly. Now, I need to make the first column in the table appear as a link. How can I achieve that? const EditController = () => { c ...

Angular JS causing text alignment issues in table cells when viewed on mobile devices

I have created a web application that requires both desktop and mobile views, utilizing Angular JS. Everything is functioning as expected except for the text alignment within tables. I attempted using <td align="left">, but it did not produce any cha ...

React Switch not displaying various pages correctly

After creating a new component to switch between pages on my React app, I encountered an issue where the HomePage renders correctly when entering the site, but clicking on navlinks does not work. Additionally, when trying to access the url /contacto, ins ...

Utilize AxiosAbstraction to transmit a Patch request from a Vue.js application to a PHP backend

I need help with sending a PATCH request to update the birthdate of a user (promotor) from Vue.js frontend to PHP backend. The issue I'm facing is that the new date of birth is not getting saved in the database, and the existing date of birth in the d ...

Utilizing Jquery to extract a specific string from a URL and fetch a remote element

Recently delving into Jquery, I'm in search of a code snippet that can capture the current page URL and load a remote element if it contains a specific string. For instance: Consider these sample page URLs: "http://......./Country/AU/result-search- ...

Having trouble with vscode [ctrl+click] on 'vue single-file components' and 'go to definition'? It's not working for me

// src/ui/tabbar/Index.vue <template> <div> my-tabbar component here </div> </template> // src/ui/index.js import MyTabbar from './tabbar/Index.vue' export default { install(Vue) { Vue.component(MyTabbar.na ...

Issue with Angular 17 button click functionality not functioning as expected

Having trouble with a button that should trigger the function fun(). Here's the code snippet I'm using. In my TS file: fun(): void { this.test = 'You are my hero!'; alert('hello') } Here is the respective HTML: &l ...

Adjust grading system based on user interaction with JavaScript

I am currently working on a grading system for a website and I am attempting to modify the interpretation of grades when a column is clicked. Specifically, I am looking to convert Average (%) to Letters to 4.0 Grade Average. To achieve this, I am using Jqu ...

Semantic UI form validation is initiated by clicking any button

Within my Semantic UI form (<div class="ui form">), it seems that every button is triggering the form validation, even if it's not a submit button. I have two different types of buttons below: <button class="ui blue right labeled icon prima ...

I'm having trouble with Material Design Slide Toggle as it lacks event.StopPropagation functionality. Any suggestions on what alternative I

When working with the Slide Toggle in Material Design, I noticed that it does not have a stopPropagation event. This is because the "MdSlideToggle.prototype._onChangeEvent" already includes a call to stopPropagation. So, what should be used instead? <m ...

The requested resource at http://localhost/Grafica/%7Bd.icon%7D/ was not found (Error 404)

Creating a tooltip in a weather chart, I want to display an image of the sky condition. Below is the HTML code: <div id="tooltip"> <table class="table table-condensed"> <tr><th>Time (local)</th><th data-text="d ...