Tips on updating the text of markers in ng-map from 'A' to 'B' and vice versa

Looking to customize ng-map markup to display "start" and "end" instead of "A" and "B."

Referenced this resource, but encountered issues displaying both "start" and "A" in the markup.

Noticing a discrepancy in the distance between the source and destination compared to the actual Google Map.

In summary, three questions arise:

1) Modify text in markup to show "start" instead of "A"

2) Address the distance inconsistency

3) How to trigger map display upon clicking the "Draw Map" button using AngularJS

Provided below is the code snippet.

var mainModule = angular.module('mainApp',['ngRoute', 'ngMap']);
mainModule.controller('mapCtrl', function($scope){
$scope.sources = ["mumbai", "pune", "bangalore", "delhi", "netherlands"];
$scope.destinations = ["pune", "bangalore", "mumbai", "delhi", "andorra"];
$scope.origin = "mumbai";
$scope.dest = "pune";
$scope.drawMap = function(){
var sourceVal = $('#sourceDdl').val();
var destnVal = $("#destinationDdl").val();
$scope.origin = sourceVal;
$scope.dest = destnVal;
}

});
body {
    overflow: auto;
    background-color: #000000;
}

/* google map */
.ng-map-section{
width: 800px;
    height: 600px;
    overflow: hidden;
    position: relative;
    background: #e6e6e6;
    border: 20px solid #FFF;
    margin-top: 20px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.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="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-route.js"></script>
<script src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <title>ng-map</title>

    <link href="css/bootstrap.css" rel="stylesheet">
  
    

</head>
<body>

<div class="container ng-map-section" ng-app="mainApp" ng-controller="mapCtrl">
<div style="float:left;width:70%;">
<ng-map zoom="14" center="" style="height:600px">
<directions 
draggable="true" 
travel-mode="DRIVING" 
origin="{{origin}}" 
destination="{{dest}}"
suppressMarkers='true'>
</directions>
<custom-marker id="start" position="{{origin}}">
<div> Start </div>
</custom-marker>
<custom-marker id="end" position="{{dest}}">
<div> End </div>
</custom-marker>
</ng-map>

</div>
<div style="float:right;width:28%">
<label for="sourceDdl">Source: </label>
<select id="sourceDdl">
<option ng-repeat="source in sources" value="{{source}}">{{source}}</option>
</select>
<br><br>
<label for="destinationDdl">Destination: </label>
<select id="destinationDdl">
<option ng-repeat="destination in destinations"  value="{{destination}}">{{destination}}</option>
</select>
<br><br>
<label>Distance: {{map.directionsRenderers[0].directions.routes[0].overview_path.length}}</label><br>
<input type="button" ng-click="drawMap()" value="Draw Map">
</div>
<!--
<div id="directions-panel" style="width: 28%; float:left; height: 100%; overflow: auto; padding: 0px 5px">
</div>-->
</div>

</body>
</html>

https://i.sstatic.net/GDXRs.png

Answer №1

The attribute name must be changed to suppress-markers, so swap suppressmarkers='true' with suppress-markers="true"

Revised example

angular.module('mainApp', ['ngRoute', 'ngMap'])
    .controller('mapCtrl', function($scope) {
        $scope.sources = ["mumbai", "pune", "bangalore", "delhi", "netherlands"];
        $scope.destinations = ["pune", "bangalore", "mumbai", "delhi", "andorra"];
        $scope.origin = "mumbai";
        $scope.dest = "pune";
        $scope.drawMap = function() {
            var sourceVal = $('#sourceDdl').val();
            var destnVal = $("#destinationDdl").val();
            $scope.origin = sourceVal;
            $scope.dest = destnVal;
        }

    });
body {
    overflow: auto;
    background-color: #000000;
}

/* google map */
.ng-map-section{
width: 800px;
    height: 600px;
    overflow: hidden;
    position: relative;
    background: #e6e6e6;
    border: 20px solid #FFF;
    margin-top: 20px;
}
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.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="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-route.js"></script>
    <script src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>



    <div class="container ng-map-section" ng-app="mainApp" ng-controller="mapCtrl">
        <div style="float:left;width:70%;">
            <ng-map zoom="14" center="" style="height:600px">
                <directions 
                draggable="true" 
                travel-mode="DRIVING" 
                origin="{{origin}}" 
                destination="{{dest}}" 
                suppress-markers="true">
                </directions>
                <custom-marker id="start" position="{{origin}}">
                    <h3> Start </h3>
                </custom-marker>
                <custom-marker id="end" position="{{dest}}">
                    <h3> End </h3>
                </custom-marker>
            </ng-map>

        </div>
        <div style="float:right;width:28%">
            <label for="sourceDdl">Source: </label>
            <select id="sourceDdl">
                <option ng-repeat="source in sources" value="{{source}}">{{source}}</option>
            </select>
            <br>
            <br>
            <label for="destinationDdl">Destination: </label>
            <select id="destinationDdl">
                <option ng-repeat="destination in destinations" value="{{destination}}">{{destination}}</option>
            </select>
            <br>
            <br>
            <label>Distance: {{map.directionsRenderers[0].directions.routes[0].overview_path.length}}</label>
            <br>
            <input type="button" ng-click="drawMap()" value="Draw Map">
        </div>
        
    </div>

Answer №2

to number 1) Simply include a label="X"

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

Issues with the functionality of jQuery append and AngularJS ng-if not functioning

In my application using checkboxes, I control the visibility of charts with the ng-if directive and implement drag-and-drop functionality with angular-Dragula. The use of ng-if is essential for me as it allows me to manipulate visible div IDs and organize ...

How can I show a map using AJAX data with jQuery?

Currently, I am working on a project that has specific requirements: Create a button named "city map" on the page. Upon selecting a country and loading the list of cities using an AJAX GET method, click the button to open a new window that displays the ma ...

Even after setting the handler to return false, Angular continues to submit the form

In the following scenario, I have encountered an issue: Here is the HTML template snippet: <form [action]='endpoint' method="post" target="my_iframe" #confirmForm (ngSubmit)="submitConfirmation()"> <button type="submit" (click)="conf ...

Looking to automatically scroll to the bottom by clicking on text using javascript/jquery?

I am currently working on a website project where I have a specific requirement. I need the webpage to scroll towards the bottom when a particular text is clicked, using JavaScript/jQuery. <p class="ml-2 mb-2 d-flex view_profile_options"><a hre ...

Progression from Angular2-rc1 to Angular2-rc2 encounters TypeScript error: anticipating ',' (TS1005)

Encountering an issue with upgrading Angular2 from RC1 to RC2, following exception is being thrown: https://i.sstatic.net/bB6di.png Here's my main.ts file, I haven't made any changes to it during the upgrade process. Line 13 is where the bootstr ...

Inspecting input parameters for mistakes in gulpfile with yargs

I've been working on an Angular app gulpfile and I'm facing a challenge in catching errors related to the arguments. var gulp = require('gulp'); var args = require('yargs').argv; ... var isProduction = args.env === 'prod ...

Resolved AWS S3 access issue with a 403 Forbidden error by eliminating the "ACL" parameter during upload

While working on the frontend using React.js, I utilized the Javascript SDK for file uploads to my S3 bucket with my AWS root account. Despite following the official documentation, I consistently received a 403 Forbidden error. To resolve this issue, if yo ...

Displaying all hidden sections on a website

I'm trying to figure out if there's a way to expand all the collapsible sections on a webpage at once. One section that is relevant to my search looks like this: <tr> <td></td> <td style="..;"> <div s ...

The datetime value provided is not valid: Tuesday, July 27, 2021 at 8:47:50 PM according to India Standard Time

When trying to store a date in MySQL Workbench as "2022-07-27T15:17:50.401Z", it is getting converted and causing an error during query execution. I need the date to be stored in this format - "2022-07-27T15:17:50.401Z" What should be ...

Is there a way I can retrieve the appended link text upon clicking?

Hello everyone! I have successfully created my own jQuery/JavaScript auto complete search suggestions div. I have implemented a feature where it pulls in an XML dictionary full of words and uses regular expressions to suggest matches based on user input. H ...

Is it possible for me to modify the Event Listener functionality of PayPal buttons to trigger a hidden surprise, and then revert it back to its original settings afterwards?

I am currently working on implementing a fun easter egg feature on my website that will activate when a specific donation amount is entered. Is there a way to customize the behavior of the PayPal button so that instead of redirecting to the standard PayPa ...

Developing a Cloud Function for Stripe that is taking forever to finalize writing data to Firestore

Currently, I am facing an issue with my Google Cloud function (provided below) that handles webhooks from Stripe payments and stores some data in Firestore. The problem is that it seems to hang for approximately 3 minutes before completing. const Stripe = ...

The navigation bar buttons in my IONIC 2 app are unresponsive on both the

In Ionic 2 for Android, I encountered an issue with the title placement. To resolve this, I applied some CSS to center the title and added left and right buttons to the nav bar. However, when I tried to implement onclick functionality for these buttons, no ...

Is it possible to extract external JSON data using JQuery's $.getJSON function?

I am trying to retrieve a quote from the iheartquotes website and display it within a div when my webpage loads. However, for some reason, the code I have written is not working as expected. <script type="text/javascript"> $(document).ready( ...

Tips for creating a jquery modal form that can be reused

I currently have the following files : *vehicule_parc.php :* <script language=javascript src="../js/vehicule_parc.js"></script> <h3 class="headInfoBox" id="cch">Fuel Consumption >></h3> <hr /> <div id="cc"> ...

To trigger a Bootstrap 5 modal in a child component from a button click in the parent component in Angular without the need to install ng-bootstrap is possible with the following approach

To achieve the functionality of opening a modal in a child component upon clicking a button in the parent component without using ngx-bootstrap due to restrictions, one approach is to add data-bs-target and data-bs-toggle attributes to the button. Addition ...

Alpinejs Mega Menu Issue: Hover Functionality Glitchy

I'm working on a complex Mega Menu project that is activated upon hovering, using the powerful combination of Tailwind CSS and Alpinejs. The functionality is mostly there, but I've encountered some bugs along the way. Despite my attempts to impl ...

Convert a string that represents a Buffer into an actual Buffer object

I am looking for a way to change a string representing a Buffer into the actual encoded string. For instance, if I start with the string var str1 = "hello,there" And then convert it into a buffer using Buffer.from() buf1 = Buffer.from(str1) <Buffer ...

Guide on how to submit an image along with text using AJAX, PHP, and HTML

Hey there! I'm currently working on a project where I need to upload an image with comments added into a database using a combination of PHP, AJAX, and HTML. Let me show you the HTML part first: <form name="form1" enctype="multipart/form-data" ac ...

Is there a way to pass information from Express.js to React without using an API?

My goal is to build a Multi Page APP using both react and express. I find myself uncertain about how to access data sent by express in react without utilizing an API. I am curious if react has the capability to retrieve information stored in HTML props t ...