Utilizing the zIndex property on a map label does not produce any impact when combined with a GeoJSON layer

Utilizing the Google map label tool, I am trying to showcase certain property from GeoJSON data on a GeoJSON layer. However, the issue arises as the layer has a dark color and the label is appearing blurry behind the GeoJSON data layer. Despite attempting to apply a bigger zIndex for the label compared to the data layer, it seems to have no effect at all. You can see the problem in action on Plunker.

https://plnkr.co/edit/KvhIoRoibsbKk9e4k1Ch?p=preview

<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script src="geojson.js"></script>
<script src="https://maps.google.com/maps/api/js?libraries=placeses,visualization,drawing,geometry,places"></script>
<script src="https://code.angularjs.org/1.3.15/angular.js"></script>
<script src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>
<script src="https://googlemaps.github.io/js-map-label/src/maplabel-compiled.js"></script>
<script>
var app = angular.module('myApp', ['ngMap']);
app.controller('MyCtrl', function(NgMap) {
  var vm = this;

  NgMap.getMap().then(function(map) {
    vm.map = map;
    vm.map.data.setStyle(function(feature) {
      return({
        fillColor: feature.getProperty('fill') ? feature.getProperty('fill') : 'transparent',
        strokeWeight: 0.5,
        fillOpacity: feature.getProperty('fillOpacity') ? feature.getProperty('fillOpacity') : 0.5,
        zIndex: 1000
      });
    });
    vm.map.data.addGeoJson(geojson);
    vm.map.data.forEach(function (feature) {
      var centroid = feature.getProperty('centroid');
      var myLatlng = new google.maps.LatLng(centroid.coordinates[1], centroid.coordinates[0]);

      var mapLabel = new MapLabel({
          text: feature.getProperty('Shale_play'),
          position: myLatlng,
          map: vm.map,
          fontSize: 16,
          align: 'center',
          minZoom: 5,
          fontColor: '#0000ff',
          zIndex: 5000
      });

      mapLabel.set('position', myLatlng);
    });
  });
});
</script>
</head>
<body ng-controller="MyCtrl as vm">
  <ng-map zoom="8" center="35.3944545,-92.78723"></ng-map>
</body>
</html>

geojson.js

var geojson = {
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "properties": {
            "id": "geology_tightOilGas_eia20160311",
            "fillOpacity": "0.8",
            "fill": "#00aa22",
            "Basin": "Arkoma",
            "Lithology": "Shale",
            "Shale_play": "Fayetteville",
            "Source": "EIA",
            "Area_sq_mi": 5852.69474734,
            "Area_sq_km": 15158.4098071,
            "Age_shale": "Mississippian",
            "centroid": {
                "type": "Point",
                "coordinates": [-92.78723, 35.3944545]
            }
        },
        "geometry": {
            "type": "MultiPolygon",
            "coordinates": [
                [
                    [
                        [-94.277701, 35.202423],
                        [-94.382715, 35.322647],
                        [-94.393411, 35.533806],
                        [-94.36331599899995, 35.638342],
                        [-94.24130399899997, 35.682679],
                        [-94.023528, 35.690577],
                        [-93.875907, 35.691057],
                        [-93.491065, 35.684045],
                        [-92.952118, 35.658092],
                        [-92.664754, 35.666656],
                        [-92.30350699899998, 35.677098],
                        [-91.918848, 35.628261],
                        [-91.475479, 35.601242],
                        [-91.181049, 35.59428500100006],
                        [-91.274519, 35.529656],
                        [-91.388323, 35.449603],
                        [-91.544307, 35.31595599900004],
                        [-91.73661700099996, 35.176988],
                        [-91.867632, 35.102377],
                        [-92.012094, 35.097852],
                        [-92.29381300099999, 35.102714],
                        [-92.709335, 35.13337],
                        [-93.396545, 35.153332],
                        [-94.01489300099996, 35.168451],
                        [-94.277701, 35.202423]
                    ]
                ]
            ]
        }
    }]
};

Answer №1

If you're looking for a workaround, consider using the native google.maps.Marker object instead of the js-map-label library and its MapLabel object. You can customize the icon and label by providing an empty PNG image URL as the custom icon and specifying where the label should appear.

To implement this workaround, update your code as follows:

vm.map.data.forEach(function (feature) {
    var centroid = feature.getProperty('centroid');
    var myLatlng = new google.maps.LatLng(centroid.coordinates[1], centroid.coordinates[0]);

    var marker = new google.maps.Marker({
        position: myLatlng,
        map: vm.map,
        title: feature.getProperty('Shale_play'),
        icon: {
            labelOrigin: new google.maps.Point(0,0),
            url: "https://upload.wikimedia.org/wikipedia/commons/d/d2/Blank.png"
        },
        label: {
            text: feature.getProperty('Shale_play'),
            color: '#0000ff',
            fontWeight: "bold",
            fontSize: "16px"
        }
    });
});

You can see the result of this code in the provided screenshot:

https://i.stack.imgur.com/Rve0f.png

For a complete example, check out the plunker link below:

https://plnkr.co/edit/ciuPVzjNcVIuqmqq9ZC6?p=preview

I hope this solution works for you!

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

reasons why the keypress event may not be triggered

Hello there, I am trying to create a function that simulates pressing the 'tab' key. The function is supposed to restrict input within specific ranges and return the cursor to another range once the limit is reached. Additionally, if a user input ...

Pull information from API and populate a dropdown menu in an Angular material select input

I am facing an issue with displaying data from an API in a mat select input field. I have tried to iterate over the data using a for loop but it is not working as expected. Can someone help me figure out how to properly populate the mat select input with d ...

Finding the Middle Point of a Circle Using CEP/JavaScript

Using a specific set of calculations, I am able to create a circle in this manner: var yMinCir = height - 1515.80/2.667+8.5; var yMaxCir = height - 1545.80/2.667+8.5; var myCircle = page.ovals.add({geometricBounds:[yMinCir, 1312.63/2.667+8.5, yMaxCir, 1342 ...

The second click on ng-click does not seem to be functioning properly

Hello, I am new to AngularJS. I have managed to fetch the required data, but I'm facing an issue where clicking doesn't work for the second time. I have tried multiple solutions but none seem to be working. Could someone please help me solve this ...

Error in Dimplejs: Line is not visible when series is empty

I have a dimplejs.org line chart set up. I am trying to colorize the Clicks data points from blue to red (blue for fewer clicks and a gradient from blue to red for more clicks). When I set the series as shown below, it works fine but the tooltip only incl ...

Flask-SocketIO: Transmitting data between nodes using Redis adapter

When integrating SocketIO into an application running behind a node-balancer, the documentation recommends using SocketIO-Redis to facilitate event passing between nodes: const io = require('socket.io')(3000); const redis = require('socket.i ...

Interacting with API through AngularJS $http.get

I am a beginner in AngularJS and I am trying to grasp its concepts by studying example codes. Currently, I have found an interesting code snippet that involves the $http.get function. You can find it here: I attempted to replace the URL with my own, but ...

Update the content within every <td> element using AJAX/JQUERY on a table created from JSP

I have a database filled with descriptions and corresponding ID numbers. The table displays them like this: index.jsp <table> <tr> <td>Name:</td> <td>Id:</td> </tr> <c:forEach items ...

Utilize API to import sunrise and sunset times based on specific coordinates directly into a Google Sheet

After countless hours of trying to crack this code, I’m faced with a final hurdle. The challenge lies in parsing the output from the and storing either the sunrise or sunset time into a variable that can be exported as a result in a Google Sheet. The u ...

Transforming a jQuery menu into an active selection with Vue JS

I am looking to transition away from using jQuery and instead utilize Vue for the front end of a menu. Specifically, I need to add an active class and a 'menu-open' state to the appropriate nested list items, similar to what is achieved in the pr ...

Exploring AngularJS and Express with Node.js: navigating routes and refreshing pages

Everything seems to be running smoothly on my app, but the moment I hit F5 in my browser is when an issue arises. The structure of my app is as follows: Using nodeJs and express, with the following routes set up in Express: core.app.get('/', f ...

Creating a new JavaScript object using a Constructor function in Typescript/Angular

Struggling with instantiating an object from an external javascript library in Angular/Typescript development. The constructor function in the javascript library is... var amf = { some declarations etc } amf.Client = function(destination, endpoint, time ...

The dimensions on Next.js pages exceed those of the viewport by a significant margin

I have recently encountered a perplexing issue where the dimensions of my webpage appear to be 2.7 times larger than the viewport, even when there is no content or styles applied. The strange part is that it seems as though the page has been scaled up, eve ...

Extracting data on an AngularJS platform by using web scraping techniques

I have been working on an AngularJS application that currently retrieves JSON data from an API using http.get, and it's been working really well. Recently, I've been exploring the idea of passing a URL to a static webpage and scraping the result ...

What should be shown if the value is missing?"

Is it possible in Angular to display a dash "-" if there is no data in the variable o.Name using something like this: <th ng-repeat="o in Odds" >{{o.Name || "-"}}</th> Please provide a solution if available. ...

Mapping API for JavaScript, converting coordinates into precise locations

I have two coordinates: 54.674705589 and 25.289369548. I want to place these coordinates on a map when the button is clicked, similar to this example. However, the example provided is for addresses, not coordinates. Is it possible to modify this example t ...

What causes the reflection of JavaScript variables when there is a change in ng-model?

By declaring the object globally and assigning it during an HTTP call when the Angular controller loads, I am able to update the values of this object in the Angular scope variables and access them through ng-models. When a button is clicked and one of the ...

How can I append a hash to a URL using JavaScript without causing the page to scroll?

Is it possible to add a hash to the URL without scrolling the page using JavaScript? I navigate to the page I scroll down I click on a link that adds a hash (for example: http://www.example.com/#test) The page should not scroll back to the top. What is ...

The socket context provider seems to be malfunctioning within the component

One day, I decided to create a new context file called socket.tsx: import React, { createContext } from "react"; import { io, Socket } from "socket.io-client"; const socket = io("http://localhost:3000", { reconnectionDela ...

Submitting a nested JSON object in an AJAX request

When it comes to passing nested JSON through AJAX, the format of the sample request should be like this: { 'user': { 'email': email, 'password': password } } login(){ var email=document.getElementById(& ...