DoroginRuslan / distribution-of-tasks

0 stars 0 forks source link

yamaps #18

Open DoroginRuslan opened 10 months ago

DoroginRuslan commented 10 months ago

app.cmp.html

PROVIDE YOUR OWN API KEY

<button (click) = "addPoint()">fsdfds

app-md.ts import { NgModule } from "@angular/core"; import { BrowserModule } from "@angular/platform-browser"; import { FormsModule } from '@angular/forms';

import { AngularYandexMapsModule, YaConfig } from "angular8-yandex-maps";

import { AppComponent } from "./app.component";

const mapConfig: YaConfig = { apikey: "61f5780b-ee71-47a9-93a5-6ac5fd5262e2", lang: "en_US" };

@NgModule({ declarations: [AppComponent], imports: [BrowserModule, AngularYandexMapsModule.forRoot(mapConfig), FormsModule], providers: [], bootstrap: [AppComponent] }) export class AppModule {}

app-comp.ts import { Component, OnInit, ViewChild, ElementRef, } from '@angular/core';

declare const ymaps: any;

@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], })

export class AppComponent implements OnInit { points: string[] =[]; map: any; latitude = 41.3; longitude = 69.3; @ViewChild('yamaps') el!: ElementRef;

constructor() { }

ngOnInit() : void { this.points = ["юбилейная 10, мытищи", 'Красные ворота, Москва']; ymaps.ready().done(() => this.createMap());

} private createMap(): void { this.map = new ymaps.Map('map', { center: [this.latitude, this.longitude], zoom: 14 }); const placeMark = new ymaps.Placemark([this.latitude, this.longitude]); this.map.geoObjects.add(placeMark); }

addPoint() {

const placeMark = new ymaps.Placemark([this.latitude-1, this.longitude-1]); this.map.geoObjects.add(placeMark); } }

index.html

loading

main.ts import './polyfills';

import { enableProdMode } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';

platformBrowserDynamic().bootstrapModule(AppModule).then(ref => { // Ensure Angular destroys itself on hot reloads. if (window['ngRef']) { window['ngRef'].destroy(); } window['ngRef'] = ref;

// Otherwise, log the boot error }).catch(err => console.error(err));

DoroginRuslan commented 10 months ago

app.comp.html

div id="map" style="width: 100%; height: 600px" #yamaps>/div> button (click) = "addPoint()">fsdfds