Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ol

Package Overview
Dependencies
Maintainers
3
Versions
3436
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ol

OpenLayers mapping library

  • 10.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
292K
increased by6.61%
Maintainers
3
Weekly downloads
 
Created

What is ol?

The 'ol' npm package, also known as OpenLayers, is a powerful library for displaying map data in web browsers. It provides a comprehensive set of tools for working with maps, including support for various map layers, projections, and interactions. OpenLayers is highly customizable and can be used to create complex mapping applications.

What are ol's main functionalities?

Creating a Map

This code initializes a basic map using OpenStreetMap (OSM) as the tile source. The map is centered at a specific longitude and latitude and is set to a zoom level of 4.

const map = new ol.Map({
  target: 'map',
  layers: [
    new ol.layer.Tile({
      source: new ol.source.OSM()
    })
  ],
  view: new ol.View({
    center: ol.proj.fromLonLat([37.41, 8.82]),
    zoom: 4
  })
});

Adding Vector Layers

This code adds a vector layer to the map. The vector layer contains a single point feature, which is placed at a specific longitude and latitude.

const vectorLayer = new ol.layer.Vector({
  source: new ol.source.Vector({
    features: [
      new ol.Feature({
        geometry: new ol.geom.Point(ol.proj.fromLonLat([37.41, 8.82]))
      })
    ]
  })
});
map.addLayer(vectorLayer);

Handling Map Interactions

This code adds a select interaction to the map, allowing users to click on features. When a feature is selected, the selected features are logged to the console.

const select = new ol.interaction.Select();
map.addInteraction(select);
select.on('select', function(e) {
  console.log('Selected features:', e.selected);
});

Other packages similar to ol

Keywords

FAQs

Package last updated on 05 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc