Insert element into array // Angular leaflet

As a newcomer to Angular, I require assistance on how to insert an item into the markers.venues.

This is my current code:

var app = angular.module("basicMapApp", ["leaflet-directive"]);
app.controller("CenterController",
    [ '$scope', function($scope) {
        angular.extend($scope, {
            defaults: {
                tileLayer: "https://dnv9my2eseobd.cloudfront.net/v3/foursquare.map-ikj05elx/{z}/{x}/{y}.png",
                maxZoom: 14,
                minZoom: 3,
            },
             center: {
                lat: 52.38,
                lng: 4.8777,
                zoom: 6
            },
             markers: {
                venues: {
                    Madrid: {
                        lat: 52.38,
                        lng: 4.8777,
                        message: "This is Madrid. But you can drag me to another position",
                        focus: false,
                        draggable: true
                    },
                    Barcelona: {
                        lat: 52.38,
                        lng: 5.8777,
                        message: "This is Barcelona. You can't drag me",
                        focus: false,
                        draggable: false
                    }
                }
            }
        });

    }]
);

Could someone please guide me on how to add a new item in the markers.venues using JavaScript?

I attempted the following but it did not work as expected:

 $scope.markers.venues.push({
    Amsterdam: {
                 lat: 52.38,
                 lng: 5.9777,
                 message: "This is Amsterdam. You can't drag me",
                 focus: false,
                 draggable: false
              }
     });

If you need more information on Angular leaflet, refer to the documentation here

Answer №1

give this a shot

   $scope..pins.places['Amsterdam']={
             lat: 52.38,
             lng: 5.9777,
             info: "You've reached Amsterdam. No dragging allowed",
             focus: false,
             movable: false
          }

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

Tips for creating an output directory when the TypeScript files are stored in the './src' location

Here is what I currently have: ./src/myfile.ts ./test/mytest.spec.ts I want tsc to output a javascript file (myfile.js) and a definition file (myfile.d.ts) in the ./build directory. This is my tsconfig.ts: { "compilerOptions": { "module": "common ...

Set boundaries for square dimensions and placement within the parent container

Struggling to confine a square within specific size constraints while keeping it neatly aligned within the parent container. Balancing these requirements has proven challenging. The layout consists of a main div with two columns on the left and a div occu ...

Issue with margins of sections when attempting to activate menu class while scrolling

My Objective: I want to create a website where the menu highlights the section that is currently being viewed as the user scrolls up and down. Progress So Far: I have successfully implemented a functioning menu that changes to "active" when the correspo ...

Revealed the previously hidden private variables within the Revealing Module Pattern

I have encountered an issue while implementing the Revealing Module Pattern, as I am struggling to expose a modified private property. var myRevealingModule = (function(){ var name = 'Samantha'; function updateName () { name = ...

What could be causing the Universal Code for Disqus to not function properly?

Struggling to get this code to work on my website. I've tried everything, from clearing caches and cookies to disabling plugins and extensions, but still no luck. Check out the code below: import React, { Component } from 'react' import { ...

Troubleshooting JavaScript's onchange Function Dysfunction

Here is the code snippet I am working with: <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="style.css"> <script src="jquery-2.2.1.min.js"></script> <script src="slike.js"></script> ...

What is the importance of having Express in the frontend?

As someone who is relatively new to the world of JavaScript and web applications, I recently came across an Express web application project that contained a public directory, client directory, and server directory. This has raised some questions for me. I ...

Ways to transmit information from a modal to a function

Trying to figure out how to update data in an ng-grid after submitting a modal form with multiple text input controls. Should the ajax create function be called within the $scope.open controller section or resolve? $scope.open = function (size) { var mo ...

Removing redundant names from an array using Typescript

My task involves retrieving a list of names from an API, but there are many duplicates that need to be filtered out. However, when I attempt to execute the removeDuplicateNames function, it simply returns an empty array. const axios = require('axios&a ...

Retrieving JSON data from a URL using AngularJS's HTTP get request

I am facing an issue with this code where I am trying to retrieve JSON data from my ASP.NET Web API using AngularJS. However, I am unable to fetch the data successfully. Below is the code snippet: <!DOCTYPE html> <html ng-app="myapp"> <he ...

Exploring the Synergy Between Play 2.3.x, Webjars, and Requirejs: Unveiling

Queries: Is there a way to streamline the process of setting paths and shims in requirejs for webjars and their dependencies without manual intervention? (Especially for webjars that include a requirejs.config() call?) Does anyone have a straightforward e ...

Limiting the input of special characters for the initial character of a pattern

When creating an input field, I need it to allow numbers, alphabets, and special characters like hashtags (#), dollar signs ($), percent symbols (%), caret (^) etc. The only condition is that the first character entered in the text box should not be a spec ...

Discovering the screen dimensions or viewport using Javascript in Bootstrap 4

Is there a method to identify the view port/screen size being utilized by Bootstrap 4 using Javascript? I've been struggling to find a dependable way to determine the current view port after a user resizes the browser. I attempted to use the Bootstra ...

What is the best way to transmit a 500x500 2D Integer Array using Websockets?

I'm encountering an issue where I believe it may be too time-consuming to JSON.stringify and send data to each individual user. For example, if 4 people connect at the same time, the server will become stalled during array parsing, resulting in signif ...

Preventing unnecessary 'unused parameter' alerts in TypeScript

I've come across this scenario multiple times and have finally decided to explore the correct approach for handling it. When dealing with an abstract parent class that declares a method, and some concrete sub-classes implementing actual logic in their ...

Enhancing date formatting with Angular and Pikaday

I am currently utilizing the angular-pikaday plugin (available at https://github.com/nverba/angular-pikaday) and encountering an issue with date formatting. My objective is to have a model containing a date string formatted as YYYY-MM-dd. To address this ...

Achieve Custom Styling in Material UI Stepper Label with ReactJS: Adjust Font Size and Margin Top

Is there a way to adjust the fontsize of the stepper label and the margin between the label and circle? The default marginTop is set to 16px, but I would like to reduce it. Any suggestions on how to achieve this? Check out the Codesandbox code using Mater ...

Troubleshooting: :before element not being hidden by jQuery slidetoggle()

My elements are all behaving correctly with the slidetoggle() function, except for my li:before class. I've attempted to manipulate the overflow, visibility, display, and other properties of both the :before pseudo-element and the li element, but the ...

Relocate the bxslider carousel to the specific div clicked on

Is it possible to move the slider to the selected div when using bxslider? I have a carousel below. Currently, when you click on the controls (left/right arrows), it only moves one slide/div at a time, keeping the active div always on the left side. Howev ...

How can I show a view page in a specific div element using CodeIgniter?

Here is how I'm implementing the dashboard view in my controller. My goal is to have a specific page, like the index page, displayed within a div element rather than opening in a new tab. public function index() { $this->load->view('in ...