Commit aeeb9c75 authored by Yuri Bondarenko's avatar Yuri Bondarenko

проба яндекс карт

parent 26c7bc1d
...@@ -17299,6 +17299,11 @@ ...@@ -17299,6 +17299,11 @@
"integrity": "sha1-AI4G2AlDIMNy28L47XagymyKxBk=", "integrity": "sha1-AI4G2AlDIMNy28L47XagymyKxBk=",
"dev": true "dev": true
}, },
"ymaps": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/ymaps/-/ymaps-0.1.1.tgz",
"integrity": "sha512-LCMgNCvPqRjwW4FWUT+Ly6T93W44OCYWFzFnTkUwMq0uy4B3VIRUN+uinX++idXtrJCnA/32FxEb/E505a0YUQ=="
},
"zopflipng-bin": { "zopflipng-bin": {
"version": "4.1.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/zopflipng-bin/-/zopflipng-bin-4.1.0.tgz", "resolved": "https://registry.npmjs.org/zopflipng-bin/-/zopflipng-bin-4.1.0.tgz",
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
"webpack-stream": "^5.2.1" "webpack-stream": "^5.2.1"
}, },
"dependencies": { "dependencies": {
"swiper": "^4.4.2" "swiper": "^4.4.2",
"ymaps": "^0.1.1"
} }
} }
...@@ -4,3 +4,4 @@ ...@@ -4,3 +4,4 @@
/* CSS */ /* CSS */
@import url('../../components/common/common.css'); @import url('../../components/common/common.css');
@import url('../../components/swiper/swiper.css'); @import url('../../components/swiper/swiper.css');
@import url('../../components/ymaps/ymaps.css');
import SwiperSlider from '../../components/swiper'; import SwiperSlider from '../../components/swiper';
import YMaps from '../../components/ymaps';
document.addEventListener( 'DOMContentLoaded', () => { document.addEventListener( 'DOMContentLoaded', () => {
const swiperSlider = new SwiperSlider(); const swiperSlider = new SwiperSlider();
const ymaps = new YMaps();
}); });
\ No newline at end of file
...@@ -33,8 +33,7 @@ export default class Component { ...@@ -33,8 +33,7 @@ export default class Component {
*/ */
setState( newState = {} ){ setState( newState = {} ){
console.log( 'Component setState(): Compare states', this.objectEquals( this.state, newState ), this.state, newState ); // если состояния различаются - обновляем состояние и рендерим
if( !this.objectEquals( this.state, newState ) ){ if( !this.objectEquals( this.state, newState ) ){
Object.assign( this.state, newState ); Object.assign( this.state, newState );
this.render(); this.render();
......
...@@ -33,11 +33,11 @@ export default class SwiperSlider extends Component { ...@@ -33,11 +33,11 @@ export default class SwiperSlider extends Component {
} }
} ){ } ){
super( props ); super( props );
this.loadData(); this.loadData();
} }
/** /**
* загружаем данные * загружаем данные
*/ */
...@@ -97,10 +97,10 @@ export default class SwiperSlider extends Component { ...@@ -97,10 +97,10 @@ export default class SwiperSlider extends Component {
data.data.albums.edges.forEach( ( album, index ) => { data.data.albums.edges.forEach( ( album, index ) => {
const slide = `<div class="swiper-slide"> const slide = `<div class="swiper-slide">
<h3>Swiper ${index}</h3> <h3>Swiper ${index}</h3>
<p>Swiper ${index} slide</p> <p>Swiper ${index} slide</p>
<img src="${album.node.photos[0].resized.url}" alt="${album.node.title}" /> <img src="${album.node.photos[0].resized.url}" alt="${album.node.title}" />
</div>`; </div>`;
slides[index] = slide; slides[index] = slide;
...@@ -113,14 +113,17 @@ export default class SwiperSlider extends Component { ...@@ -113,14 +113,17 @@ export default class SwiperSlider extends Component {
}); });
} }
render(){
// console.log( this.state.slides ); /**
* рендерим свайпер
*/
render(){
if( this.swiper ){
this.swiper.destroy( true, true );
}
this.swiper = new Swiper( this.props.selector, this.props.options ); this.swiper = new Swiper( this.props.selector, this.props.options );
this.swiper.appendSlide( this.state.slides ); this.swiper.appendSlide( this.state.slides );
console.log( 'Swiper class: render() called' );
} }
......
...@@ -14,41 +14,43 @@ ...@@ -14,41 +14,43 @@
/* NEW CSS */ /* NEW CSS */
@custom-media --viewport-medium (width <= 50rem); @custom-media --viewport-medium (width <= 50rem);
@custom-selector :--heading h1, h2, h3, h4, h5, h6; @custom-selector :--heading h1, h2, h3, h4, h5, h6;
:root { :root {
--fontSize: 1rem; --fontSize: 1rem;
--mainColor: #12345678; --mainColor: #12345678;
--secondaryColor: lab(32.5 38.5 -47.6 / 90%); --secondaryColor: lab(32.5 38.5 -47.6 / 90%);
} }
html { html {
overflow: hidden auto; overflow: hidden auto;
} }
@media (--viewport-medium) { @media (--viewport-medium) {
body {
color: var(--mainColor); body {
font-family: system-ui; color: var(--mainColor);
font-size: var(--fontSize); font-family: system-ui;
line-height: calc(var(--fontSize) * 1.5); font-size: var(--fontSize);
overflow-wrap: break-word; line-height: calc(var(--fontSize) * 1.5);
padding-inline: calc(var(--fontSize) / 2 + 1px); overflow-wrap: break-word;
} padding-inline: calc(var(--fontSize) / 2 + 1px);
}
} }
:--heading { :--heading {
margin-block: 0; margin-block: 0;
} }
.hero:matches(main, .main) { .hero:matches(main, .main) {
background-image: image-set("img/background.jpg" 1x, "img/background-2x.jpg" 2x); background-image: image-set("img/background.jpg" 1x, "img/background-2x.jpg" 2x);
} }
a { a {
color: rgb(0 0 100% / 90%); color: rgb(0 0 100% / 90%);
&:hover { &:hover {
color: rebeccapurple; color: rebeccapurple;
} }
} }
\ No newline at end of file
<div class="ymaps-container">
<h2>Yandex Maps</h2>
<div id="map"></div>
</div>
\ No newline at end of file
import ymaps from 'ymaps';
import Component from '../component';
export default class YMaps extends Component {
constructor( props = {
selector: '#map',
lat: -8.369326,
lon: 115.166023
}){
super( props );
this.loadMap();
}
/**
* Загружаем карту
*/
loadMap(){
const el = document.querySelector( this.props.selector );
ymaps.load( '//api-maps.yandex.ru/2.1/?lang=en_RU' ).then( maps => {
this.state.mapInstance = new maps.Map( el, {
center: [ parseFloat( this.props.lat ), parseFloat(this.props.lon) ]
});
})
.catch( error => console.log( 'Failed to load Yandex Maps', error ) );
}
/**
*
*/
render(){
return false;
}
}
\ No newline at end of file
.ymaps-container {
padding: 50px 0;
}
#map {
width: 600px;
height: 400px;
}
\ No newline at end of file
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
<body> <body>
@@include( './components/swiper/index.html' ) @@include( './components/swiper/index.html' )
@@include( './components/ymaps/index.html' )
<script src="https://cdn.polyfill.io/v2/polyfill.js?features=default,fetch"></script> <script src="https://cdn.polyfill.io/v2/polyfill.js?features=default,fetch"></script>
<script src="/assets/js/app.js?@@rev"></script> <script src="/assets/js/app.js?@@rev"></script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment