Plot data points from geojson onto a leaflet map using markers

How can I efficiently import geoJson data (containing over 2000 coordinates) into a leaflet map? Below is a brief snippet of geo json:

{
   "type": "FeatureCollection",
   "features": [
       {
           "type": "Feature",
           "geometry": {
               "type": "Point",
               "coordinates":  [ 44.8242557024,20.4048512901 ]
           },
           "properties": {}
       },
       {
           "type": "Feature",
           "geometry": {
               "type": "Point",
               "coordinates":  [ 44.8242557024,20.4048512901 ]
           },
           "properties": {}
       },...
    ]
}

The code snippet I have attempted is as follows:

<!doctype html>
<html>
<head>
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
    <!--[if lte IE 8]>
        <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.ie.css" />
    <![endif]-->
    <style type="text/css">
        body {
            padding: 0;
            margin: 0;
        }

        html, body, #cmap {
            height: 100%;
        }
    </style>
    <script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
    <script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
</head>
<body>
    <div id="cmap"></div>
    <script>
        var cupcakeTiles = L.tileLayer('https://api.mapbox.com/v4/mapbox.emerald/page.html?access_token=cj5h2mqa63sc92srx3bu62e2j', {
            maxZoom: 18
        });

    $.getJSON("convertcsv.geojson", function(data) {
        var geojson = L.geoJson(data, {
            onEachFeature: function (feature, layer) {
                layer.bindPopup(feature.properties.name);cj5h2mqa63sc92srx3bu62e2j
          }
      });

    var map = L.map('map', {
        center: [44, 20],
        zoom: 7
    });

    L.tileLayer('https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png', {       
        id: 'examples.map-20v6611k'
    }).addTo(map);

    new L.GeoJSON(meta1nJson).addTo(map);
  });
  </script>
</body>
</html>

However, when I run the code, nothing happens and only a gray background is displayed. I am uncertain about the mistake I may have made (or errors), but suspect there could be an issue with importing geojson data and the map token. I am fairly new to this so any help in advance would be greatly appreciated.

Answer №1

Your code appears to have several issues that need to be addressed. Firstly, it seems like the element with the id 'map' is not present in your HTML, causing the map layer placement to fail. You should use 'cmap' as the id in the provided code snippet.

var map = L.map('cmap', {
   center: [44, 20],
   zoom: 7
});

Additionally, the variable meta1nJson is not defined in your code, making the following code ineffective:

new L.GeoJSON(meta1nJson).addTo(map);

Even though the layer 'cupcakeTiles' is declared, it is never added to the map. Furthermore, there is an extra string in the code snippet below that needs to be removed.

 $.getJSON("convertcsv.geojson", function(data) {
var geojson = L.geoJson(data, {
  onEachFeature: function (feature, layer) {
    layer.bindPopup(feature.properties.name); //cj5h2mqa63sc92srx3bu62e2j
  }
});

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

Keeping track of important dates is ineffective using the calendar

I am facing an issue with developing a calendar that marks events on the correct dates. I am receiving the dates in the following format in PHP [ { "status": "OK", "statusCode": 200, "statusMensagem": & ...

encountered an issue while parsing information from the MySQL database table

My android app is designed to allow users to enter an area and then fetch all organizations from my MySQL table to display on the phone. However, I encountered the following error while running the application: Error parsing data org.json.JSONException: ...

JavaScript sorted arrays are an efficient way to keep data

In my dataset, I have an array of objects representing various products. Each product object includes a field called ratingReviews and another field called price, which can either be a string or an object. If the price is represented as an object, it conta ...

Serializing a JsonElement field using JAXB in a POJO

I have a custom ordinary Java object (POJO) class called Cat. It looks like: class Cat { public Cat() {} private String name; private JsonElement arbitraryProperties; } Within my application, I am using Jackson (JAXB) to work with the Cat resource ...

Error message HMR Webpack was found to be invalid

When using Webpack, I keep encountering the following error message: Invalid HMR message, along with a lengthy JSON string. Unfortunately, I couldn't find any helpful resources to assist me in debugging this issue. Do you have any suggestions? I&apo ...

Leveraging Angular-translate with state parameters

My current challenge involves using angular-translate for localization. Everything is working smoothly except for translating data within state parameters. As an example, consider a state configuration like this: .state('about', { url: "/ ...

The type hint feature in JSON4S is not functioning as expected

Here is a code snippet that has been causing an issue: implicit val formats = DefaultFormats + FullTypeHints(Contacts.classList) val serialized = Serialization.write(List(Mail(field = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cf ...

The onprogress event for the XMLHttpRequest object threw an error due to an Uncaught SyntaxError, indicating

I have implemented an ajax function successfully However, I am facing an issue where when using onprogress, I sometimes receive incomplete HTML response and the console displays Uncaught SyntaxError: Invalid or unexpected token but the function still cont ...

Decoding JSON data using Codable in Swift 4

I have been utilizing Swift 4 and Codables for parsing JSON data. Here is the sample JSON structure I am working with: { "data": { "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="80f4e5f3f4f5f3e5f2b1b4b3b ...

Converting Basic JSON Data with Rails ActiveResource

I am having an issue with a RESTful API call that is structured as follows: HTTP GET http://addresss:port/settings/{setting} The response from the API call is simply the value of the specified setting in the form of a string: "settingValue" I am attemp ...

Tips for using jQuery to add several image source URLs to an array

My JavaScript code uses jQuery to collect all image sources on document load and store them in an array: var sliderImg = []; sliderImg.push($('.thumbnail').children('img').attr('src')); Then, I have a click event set up to a ...

The React Component is limited to updating once

Exploring the React Native code below: import React from 'react'; import {Text, View, StyleSheet, Button} from 'react-native'; export default class Target extends React.Component { constructor(props){ super(props); ...

Include the aria-labelledby attribute in the jQuery Datatable Pagination

Check out the HTML output created by the Jquery Datatable plug-in for pagination(https://datatables.net/plug-ins/pagination/full_numbers_no_ellipses): <div class="dataTables_paginate paging_full_numbers" id="my-table_paginate" aria-l ...

Polymer event / callback for appending new child nodes

My current project involves creating a custom element, let's call it <parent-element>, that performs specific actions based on the presence of its childNodes. When I define the element like this: <parent-element> <div> </div&g ...

Adjust the text size of a label in material-ui

Hey everyone, I'm struggling with something here. I need to adjust the font size of the label that goes along with my textfield. So far, I've only been able to change the font size of the input itself and not the label. Here's the code for ...

What is the best way to create a React filter utilizing the Autocomplete component from MaterialUI and incorporating state management?

I am currently in the process of creating a filter using the Autocomplete component from MaterialUI. As I select options from the dropdown menu, several things are happening: The Autocomplete automatically adds the selected options to the Chip Array. The ...

Enhancing your scheduling capabilities with Kendo UI Web Scheduler - Dynamically managing resources dataSource

I've been attempting to dynamically change the resources dataSource in my Scheduler, but unfortunately, the changes I am making are not reflecting in the Scheduler interface. Here is how I have set up the scheduler: $("#scheduler").kendoScheduler ({ ...

Getting the value from a label and then setting it as the innerHTML of document.getElementById('label')

I have successfully implemented a JavaScript Google Maps functionality, but now I am facing an issue where I need to retrieve the type of HTML control and set it to JavaScript. Specifically, when attempting to extract the value from lblTitle, it is not f ...

Ways to efficiently display elements in a grid in real-time

Attempting to design a layout where each row consists of 3 cards using Bootstrap's Grid layout for responsiveness. The challenge lies in the fact that the card data is stored in JSON format, and the length of the JSON Object array may vary, leading t ...

Navigating external pages with Vue Router

Could really use some assistance. I've got a JSON file filled with various URL links, some internal and some external. This is what the JSON structure looks like: [ {stuff..., "Url":"https://www.google.com/", stuff..}, {stuff... ...