Creating interactive popups using Web Map Service (WMS) with the

I am looking for a way to make a leaflet map loaded from a geoserver interactive by displaying popups with information. Can someone provide a solution using jsfiddle to help me understand? I am struggling to figure out how to achieve this. Essentially, I want to bring a layer from the geoserver and have popup information available in each part of the map. The code snippet I currently have is:

var stComerciaisLayer= L.tileLayer.wms("http://...:8080/geoserver/wms/", {
          layers: 'IGEO:setor_comercial_geo',
          format: 'image/png',
          transparent: true,
          attribution: "Test"
        });

Could you please guide me on how to add popups to this setup? Thank you!


I copied the following exactly as it is:

http://bl.ocks.org/rclark/6908938

However, it doesn't work:

<script src="L.TileLayer.BetterWMS.js"></script>

var stComerciaisLayer= L.tileLayer.betterWms("http://...:8080/geoserver/wms/", {
          layers: 'IGEO:setor_comercial_geo',
          format: 'image/png',
          transparent: true,
          attribution: "Some test"
        });

L.TileLayer.BetterWMS.js

L.TileLayer.BetterWMS = L.TileLayer.WMS.extend({

  // Rest of the script content...

});

// Rest of the scripts continued...
  

The error message I receive is:

Failed to load http://...:8080/geoserver/wms/?REQUEST=GetFeatureInfo&SERVICE=WMS&SRS=EPSG%3A4326&STYLES=&TRANSPARENT=true&VERSION=1.1.1&FORMAT=image%2Fpng&BBOX=-38.74431610107422%2C-4.0605082148574105%2C-38.26400756835938%2C-3.726884196645965&HEIGHT=974&WIDTH=1399&LAYERS=IGEO%3Asetor_comercial_geo&QUERY_LAYERS=IGEO%3Asetor_comercial_geo&INFO_FORMAT=application%2Fjson&X=821&Y=172: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.



leaflet.js:5 Uncaught TypeError: Cannot read property 'lat' of undefined

Answer №1

The error message you're seeing is related to Cross-Origin Resource Sharing (CORS).

This means that your geoserver isn't set up to send CORS headers, causing your browser to block loading data from the server due to the Same-origin policy.

You can find resources to help you configure CORS headers for your geoserver on sites like Stack Overflow or GIS Stack Exchange, such as this question about CORS setup for Tomcat and Geoserver.

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

Passing data from one NodeJS page to another

I am working on creating a User management system in Node. My goal is to have a page that displays all users in a table format. When the edit button is clicked, I want to navigate to another page with detailed information about the selected user. However, ...

Wrapping dynamic page titles with comment tags in NextJS for cleaner code

I am currently working on NextJS version 12. In my project, I have a file named Layout.js which contains the following code: import Head from "next/head"; const Layout = ({children, pageTitle, mainClass}) => { return ( <> ...

Transferring PHP array data to JavaScript using echo

I'm currently in the process of working on a project that requires extracting data from a database and converting it into a JavaScript array. This array will be used to dynamically update a graph. Below is the PHP code I have written to retrieve the ...

Changing the value of a form input name after a $scope.$watch event is activated

In my AngularJS 1.4 project, I have a form input element where I am attempting to dynamically set the name attribute. <input type="email" name="{{ctrl.name}}" class="form-control" id="email" ng-minlength="5" required> The assignment of the name att ...

Delay loading of external JavaScript with data attributes

Exploring options for lazy loading this code snippet: <script async src="https://comments.app/js/widget.js?3" data-comments-app-website="TvibSQx_" data-limit="5" data-color="29B127" data-dislikes="1" dat ...

Issue with printing data consecutively using Javascript

My JavaScript code aims to display the content of the body tag again when the add button is clicked. The purpose is to add authors, with each author being added in sequence. For example, if there is only 1 author present, the user simply selects whether th ...

What causes the disparity in functionality between simple html and css in an Angular 2 project compared to a vanilla html website?

When incorporating the following html/css into a new Angular project created with Angular CLI using 'ng new ProjectName', I encountered issues. Despite adding the CSS to app.component.css or styles.css and the HTML to app.component.html, the Angu ...

Session availability extends to subdomains, even though it may not be visible in a physical

Currently in the process of building a website Red Sec using a single account for all subdomains: Latest Updates Community Forum Personal Blog News Feed Support Us All pages share the same layout with different content by linking them to . Below i ...

Creating individual components for <select> and <option> elements in ReactJS

I am uncertain about how references function when the select and option tags are used together. When I split them into separate React components, they stop working. How can I resolve this issue? Here is a basic example: <select> {() => ( ...

Enhancing JSON data in Datatables with additional text

I'm currently looking for a way to insert some text into my data before generating a table using jQuery DataTables. As an example, if my JSON data looks like [1,5,6,12], I would like it to be displayed as [1 seconds, 5 seconds, 6 seconds, 12 seconds] ...

Transform seconds into an ISO 8601 duration using JavaScript

Dealing with ISO 8601 durations can be quite tricky. Efficiently converting seconds to durations is my current challenge, especially in JavaScript. Stay tuned for my solution and the Jest test script coming up next. ...

Receiving encoded characters in the response

URL: I have encountered an issue where I am trying to retrieve the PDF file from the URL above using code. In tools like Postman or Insomnia, I am able to see the output as expected in PDF format. However, when I attempt it with code, I am receiving rando ...

The JSON date has been modified

I run a web application that allows users to post messages to a restful API in order to save the information in the database. The issue I'm facing is that when data is submitted from the UI, the date appears as "effStartDate":"2016-08-13". However, i ...

Performing AJAX request when a link is clicked within a Wordpress website

I am looking for a way to initiate a PHP function in my Wordpress site when a link is clicked, rather than using a form submission. I have tried using an AJAX request but it doesn't seem to be working. Any suggestions would be greatly appreciated. Be ...

"Implementing filtering logic for an array of objects with multiple conditions in a React application

I am looking to apply filters to a person list based on criteria such as city, job, age, and gender. How can I apply filters based on five conditions in React? I tried using filter chaining but it did not work for me. In the useEffect hook, I applied indiv ...

What is the reason behind the perpetual hiding of the button?

<div class="app__land-bottom" v-if="isVisible"> <a href="#projects"> <img ref="arrowRef" id="arrow" src="./../assets/down.png" alt srcset /> </a> </div> When ...

Having trouble with your jQuery image slider?

As a newcomer to jQuery, I have been experimenting with it to gain some experience. I recently tried to integrate a jQuery image slider from slidesjs.com into my local website but unfortunately, it is not functioning as expected. Additionally, I would lik ...

Crafting interactive image checkboxes

At present, the checkboxes in my application are quite basic with labels. However, our app designer has requested that we revamp this feature and make it more appealing by using clickable images that still function like checkboxes. Allow me to provide an ...

Updating a .txt file using JavaScript

Is there a method on the client side to add text to a file called text.txt using JavaScript? In Python: f = open("text.txt","w") f.write("Hello World") f.close() The code snippet above would input "Hello World" into the text file. I am looking for a sim ...

What is the method to retrieve the ID name of an HTML tag based on its value?

Is there a way to determine the ID of an HTML tag based on its content? For example, if I have the following textboxes: I need to identify the id with the value "A2" So the expected result is id=option2 because its value is A2 <input type="text ...