AngularJS ng-map defines the view position using rectangular coordinates

Is there a way to set the position of ng-map view using the ng-map directive not as the center value of [40.74, -74.18], but instead as a rectangle defined by the corner values of the map view (north, south, east, west)?

Currently, I have this code:

<ng-map zoom="11" center="[40.74, -74.18]" class="csiMap" default-style="false"></ng-map>

However, I am looking to define a rectangle rather than a center point.

Best regards, rizon

Answer №1

fitBounds function is utilized to adjust the viewport to encompass the specified bounds, as shown below with the ng-map library.

Example

angular.module('mapApp', ['ngMap'])
  .controller('mapController', function ($scope, NgMap) {

    NgMap.getMap().then(function (map) {
      $scope.map = map;
      $scope.bounds = [47.0, 30.0, -80.0, -110.0];


      var southWest = new google.maps.LatLng($scope.bounds[1], $scope.bounds[3]);
      var northEast = new google.maps.LatLng($scope.bounds[0], $scope.bounds[2]);
      var bounds = new google.maps.LatLngBounds(southWest, northEast);
      map.fitBounds(bounds);
    });

  });
<script src="https://maps.google.com/maps/api/js"></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>

<div ng-app="mapApp" ng-controller="mapController">
    <ng-map zoom="4">
    </ng-map>
</div>

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

How can I change the orientation of a cube using d3js?

Seeking guidance on creating an accurate chart using d3js How can I rotate the SVG to display the opposite angle as shown in the image? Any recommended resources for achieving this desired result would be greatly appreciated. The provided code only disp ...

Enhance your HTML rendering with Vue.js directives

Check out this cool code example I created. It's a simple tabs system built using Vue.js. Every tab pulls its content from an array like this: var tabs = [ { title: "Pictures", content: "Pictures content" }, { title: "Music", c ...

What is the best way to include an attribute to an object in a knockout observable array and ensure a notification is triggered?

Implementing Knockout.js in my project, I have an observable array included in the view model. function MyViewModel() { var self = this; this.getMoreInfo = function(thing){ var updatedThing = jQuery.extend(true, {}, thing); ...

The ng-app feature is causing the script to run endlessly

Currently, I am troubleshooting an issue within my angular application that is built on the asp.net web application empty template. The problem arises when I utilize ng-app; if I leave it blank, the $routeProvider fails to initialize. However, if I specify ...

Unable to retrieve accurate information

I am currently in the process of developing an application that utilizes Spring Boot and ReactJS. I encounter an issue where, despite entering correct data values in the form on the client side using the POST method, the response displays NULL values. Upo ...

"Error: The $ variable is not defined" - encountered while working with a date-time picker in Jade/Pug

I am attempting to implement a date/time picker in jade/pug that resembles the example provided on this page: . I am working with a Node/express js server. However, when I click on the glyphicon-calendar icon, the calendar fails to display. I have already ...

Is there a way to run only one instance of puppeteer.launch() and simply forward pages to it in Node.js?

I have a concern regarding the code snippet below. It appears to be launching the browser on every request, potentially causing server issues on Heroku. I would like to modify it so that puppeteer is launched as a Singleton instance, where it only needs ...

The Javascript regex allows for the presence of positive and negative numbers, with the option of a single minus symbol

oninput="this.value = this.value.replace(/[^-0-9.]/g, '') This code snippet is utilized in my current project. However, there seems to be an issue where the input can contain more than one minus sign, as shown here: ---23 To address this p ...

Sending Angular an error message from Express

In my application, users have the ability to add movies to their watchlist. I am working on preventing users from adding a movie that already exists in their watchlist. This is the addMovie function in my Angular controller: $scope.addMovie = function (m ...

Retrieve particular JSON information on a single webpage by selecting an element on a separate page

My goal is to fetch specific information from a JSON file and display it on different HTML pages by clicking a button. I will achieve this using jQuery and plain JS. For the first HTML page, I want to show all products from the JSON in an element with id= ...

Javascript tells the time difference between 1 minute and 1 minutes. A timer is set up to notify when the time is

self.calculateMessageTime = function calculateMessageTime(receiveDate){ var dateReceived = Date.parse(receiveDate); var now = new Date(); now = Date.now(); // in seconds var difference = Math.abs(dateReceived - now)/1000; if(differ ...

Adding the Authorization header in an Ajax request within ExtJS can be easily done by including the

I've been struggling to upload a file using ExtJS and web API. The issue I'm facing is that when trying to send an authorization header to the server, it always returns as null. I even attempted to include the header in the XHR request within the ...

Steps for wrapping a class with a higher order component

Is it feasible to encapsulate a class component within a higher order component (HOC) that is also a class? import React, { Component } from "react"; import { View } from "react-native"; import { Toast } from "react-native-easy-toast"; const withToast = ...

Ag Grid does not allow filtering on columns that have been grouped together

When looking at the image below, I notice that when I group by a column and then apply a filter, it shows '(Select All)' and '(blanks)' in the dropdown instead of the actual values from the grouped column such as '(12/01/2016)&apos ...

Include the model.obj file into the three.MESH framework

I am a beginner in three.js and I am developing an augmented reality application on the web to showcase plates of food. Currently, I have successfully displayed a cube. However, when I attempted to display a model.obj instead of using geometry and material ...

I struggle with generating a transition effect in the input box through label transformation

Why is the input box not using the specified CSS styles for the input and label tags? The transform property doesn't seem to be working as expected. I've highlighted the areas where I'm facing issues with bold text, and I've included bo ...

Implementing a switch feature with enable/disable functionality in a material table using table row data

Is there a way to incorporate an additional action in the Material table and have it included in the React material table along with the element? Furthermore, how can I obtain row data on onChange event while currently rendering it in the state? I would a ...

Uncertain about the type of data to send back for Ajax requests in Django?

Looking to improve the functionality of my like button by making it asynchronous using JavaScript. Currently, when I like a post and refresh the page, the like count increases. However, I want the like count to increase without refreshing. To achieve thi ...

Why isn't the page redirecting if the query is unable to locate the user?

Why does the application freeze when it fails to find a user, instead of redirecting to the main page? How can this issue be resolved? User.findOne({_id: userid}, function(err, user) { if(err) { res.redire ...

Using a loop to execute Javascript Promise.all()

I am currently facing an issue where I need to make a web API call twice inside a loop, and then wait for the results before pushing them into a larger array as subarrays. The code snippet below illustrates my approach: var latlngPairs = []; function extra ...