Search code examples
jqueryangularimageimageview

Pan and Zoom Image Plugin


I am trying to implement something like google arts and culture image zoom and pan.

Look here for example.

I tried working with ng2-image-viewer library but can't seem to be able to work it out.

Following is the snippet i tried.

<app-image-viewer 
[images]="['https://images.nga.gov/en/web_images/niagara2.jpg']"
[loadOnInit]="true"
[idContainer]="'idOnHTML'">
</app-image-viewer>

Result:

enter image description here

As you can see, image is above the expected area, not proper controls and neither is that small rectangle that gives us the minimap.


Solution

  • Follow this:

    1- To install this library, run:

    npm install iv-viewer
    npm install ng2-image-viewer
    

    2- in AppModule

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    
    import { AppComponent } from './app.component';
    
    // Import your library
    import { ImageViewerModule } from 'ng2-image-viewer';
    
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
    
        // Specify your library as an import
        ImageViewerModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }
    

    3- Now just add the these codes on your angular-cli.json file:

    "styles": [
        "../node_modules/ng2-image-viewer/imageviewer.scss"
    ],
    

    4- Once your library is imported, you can use its components, directives and pipes in your Angular application:

    <!-- You can now use your library component in app.component.html -->
    <h1>
      Image Viewer
    </h1>
    <app-image-viewer [images]="['https://picsum.photos/900/500/?random', 'https://picsum.photos/900/500/?random', 'https://picsum.photos/900/500/?random']"
    [idContainer]="'idOnHTML'"
    [loadOnInit]="true"></app-image-viewer>
    

    DEMO