muxahuk1214
@muxahuk1214
html/html5; css/css3/scss; js/jQuery; php/nodejs;

API Yandex Map 2 geoobject.Point летает вместе с картой по центру. Как прикрепить Point к определённому месту?

Вот код:
ymaps.ready(function () {

			var gObjects = [{
				"type": "Feature",
				"name": "",
				"style": "#id1422517012444625547",
				"geometry": {
					"type": "LineString",
					"coordinates": [
						[37.58193, 55.91089],
						[37.58121, 55.91116],
						[37.5809, 55.91128],
						[37.5807, 55.91142],
						[37.58077, 55.91167],
						[37.58075, 55.91185],
						[37.58067, 55.9121],
						[37.5805, 55.91234],
						[37.58065, 55.91248],
						[37.58025, 55.91258],
						[37.57994, 55.91282],
						[37.57965, 55.91298],
						[37.57715, 55.91418],
						[37.57689, 55.91442],
						[37.57631, 55.91459],
						[37.57428, 55.91556],
						[37.572, 55.91664],
						[37.57098, 55.91729],
						[37.57064, 55.91748],
						[37.57033, 55.91771],
						[37.57006, 55.91842],
						[37.56986, 55.91894],
						[37.56978, 55.91904],
						[37.56967, 55.91909],
						[37.56951, 55.9191],
						[37.56673, 55.91746],
						[37.56581, 55.91698],
						[37.5653, 55.91671],
						[37.56483, 55.91644],
						[37.56459, 55.91656]
					]
				}
			}, {
				"type": "Feature",
				"name": "Офис и склад Аль-трейд",
				"style": "#id1422515632652808079",
				"geometry": {
					"type": "LineString",
					"coordinates": [
						[37.56105, 55.91926],
						[37.56338, 55.91905],
						[37.56316, 55.91831],
						[37.56377, 55.91826],
						[37.56348, 55.91739],
						[37.56388, 55.91735],
						[37.56353, 55.91618],
						[37.56027, 55.91649],
						[37.56105, 55.91926]
					]
				}
			}, {
				"type": "Feature",
				"name": "Внутренняя сторона МКАД",
				"style": "#id1422516247783473813",
				"geometry": {
					"type": "LineString",
					"coordinates": [
						[37.58141, 55.91078],
						[37.58487, 55.91036],
						[37.58811, 55.90978],
						[37.59008, 55.90928],
						[37.59059, 55.90895],
						[37.59033, 55.9087],
						[37.58968, 55.90858],
						[37.5882, 55.9083],
						[37.5879, 55.90846],
						[37.58802, 55.90846],
						[37.58781, 55.90869],
						[37.58923, 55.9106],
						[37.5896, 55.91076],
						[37.59006, 55.9108],
						[37.59041, 55.91076],
						[37.59077, 55.9106],
						[37.59099, 55.91042],
						[37.59104, 55.91022],
						[37.59057, 55.90978],
						[37.59, 55.90968],
						[37.58931, 55.90971]
					]
				}
			}, {
				"type": "Feature",
				"name": "Внешняя сторона МКАД",
				"style": "#id1422517027907995963",
				"geometry": {
					"type": "LineString",
					"coordinates": [
						[37.59244, 55.90892],
						[37.58965, 55.90962],
						[37.58677, 55.91027],
						[37.58453, 55.91063],
						[37.58173, 55.91093]
					]
				}
			}, {
				"type": "Feature",
				"name": "Из центра Москвы",
				"style": "#id1422517318711839074",
				"geometry": {
					"type": "LineString",
					"coordinates": [
						[37.58723, 55.90274],
						[37.5874, 55.90782],
						[37.58789, 55.90882]
					]
				}
			}, {
				"type": "Feature",
				"name": "КПП №1",
				"style": "#id1422516525983358305",
				"geometry": {
					"type": "Polygon",
					"coordinates": [
						[
							[37.56457, 55.91648],
							[37.56463, 55.91652],
							[37.56457, 55.91648]
						]
					]
				}
			},
			{
				"type": "Feature",
				"name": "Офис и склад Аль-трейд",
				"style": "twirl#yellowDotIcon",
				"number": "",
				"geometry": {
					"type": "Point",
					"coordinates": [[37.562049999999999, 55.917650000000002]]
				}
			}];

			var qStyles =  {
				"id1422517012444625547": {
					"strokeColor": "00339a99",
					"strokeWidth": 5
				},
				"id1422515632652808079": {
					"strokeColor": "00339a99",
					"strokeWidth": 5
				},
				"id1422516247783473813": {
					"strokeColor": "00339a99",
					"strokeWidth": 5
				},
				"id1422517027907995963": {
					"strokeColor": "00339a99",
					"strokeWidth": 5
				},
				"id1422517318711839074": {
					"strokeColor": "00339a99",
					"strokeWidth": 5
				},
				"id1422516525983358305": {
					"strokeColor": "ff0000e6",
					"strokeWidth": 5,
					"outline": "1",
					"fill": "1",
					"fillColor": "ff000099"
				}
			};

			
					
			var map = new ymaps.Map('map-frame', {
				center: [55.917650000000002, 37.562049999999999], //[55.912428,37.579655],//55.910896,37.575208	
				zoom: 15,
				type: "yandex#satellite",
				behaviors: ['scrollZoom', 'drag'],
				//bounds: [ [55.899610000000003, 37.550780000000003], [55.921309999999998, 37.60228] ],
				//strictBounds: true
			}, {
				autoFitToViewport: "always",
				geoObjectStrokeOpacity: 1,
				geoObjectFillOpacity: 1,
				geoObjectStrokeColor: "ff0000e6",
				geoObjectStrokeWidth: 5,
				geoObjectFillColor: "ff000099",
				geoObjectIconContentLayout: ymaps.templateLayoutFactory.createClass("$[properties.number]"),
				geoObjectBalloonContentBodyLayout: ymaps.templateLayoutFactory.createClass("$[properties.name]")
			} );

			map.controls.add("mapTools")
				// Добавление кнопки изменения масштаба 
				.add("zoomControl")
				// Добавление списка типов карты
				.add("typeSelector");
			

			for (var H in qStyles) {
				if (qStyles.hasOwnProperty(H)) {
					ymaps.option.presetStorage.add("ctor#" + H, qStyles[H])
				}
			}
			for( var o = 0; o < gObjects.length; o++ ) {
				var gO = gObjects[o];
				for( var C in gO.geometry.coordinates ) {
					if( gO.geometry.type == 'Polygon' ) {
						for( var M in gO.geometry.coordinates[C] ) {
							gO.geometry.coordinates[C][M] = [ gO.geometry.coordinates[C][M][1], gO.geometry.coordinates[C][M][0] ];
						}
					} else {
						gO.geometry.coordinates[C] = [ gO.geometry.coordinates[C][1], gO.geometry.coordinates[C][0] ];
					}
					
				}

				if( gO.geometry.type == 'Point' ) {
					gO.geometry = new ymaps.geometry.Point( gO.geometry.coordinates, { pixelRendering: "static" } );
					gO.geometry.options.set( 'pixelRendering', 'static' );
				}
				var g1 = new ymaps.GeoObject({
					geometry: gO.geometry,
					properties: {
						name: gO.name,
						number: gO.number,
						pixelRendering: "static"
					}
				}, {
					pixelRendering: "static",
					preset: gO.style.indexOf("#") === 0 ? "ctor" + gO.style : gO.style
				} );
				g1.options.set( 'pixelRendering', 'static' );
				g1.geometry.events.add( 'change', function( e ) {
					console.log( e );
				} );
				map.geoObjects.add( g1 );
				gObjects[o] = g1;
			}

			map.setBounds( [ [55.899610000000003, 37.550780000000003], [55.921309999999998, 37.60228] ] );
				
			});


Карта загружается, все элементы создаються, но Point ( который должен просто указывать на здание ) двигается вместе с картой и находиться всегда по середине неё.

pixelRendering ставлю на static - не помогает. Может как-то не так это делаю ( добавил везде куда только мог ).
Кто подскажет в чём косяк или может можно как-то по другому поставить указатель на здание ?
  • Вопрос задан
  • 504 просмотра
Решения вопроса 1
muxahuk1214
@muxahuk1214 Автор вопроса
html/html5; css/css3/scss; js/jQuery; php/nodejs;
Нашёл ошибку.
У меня стоит луп, на то что бы перевернуть координаты ( т.к. они заданы в обратном порядке в объекте gObjects ) и координаты к Point отличаются от других в этом объекте. Получалось что они не заданы были по этому по центру летало..
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы