npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ol-coords

v1.0.3

Published

Fly to coordinates Control for OpenLayers

Downloads

6

Readme

Coordinate Control for OpenLayers 🎯

Version Github: bugraaydin1

Add coordinates control over OpenLayers map. The coordinate entered is evaluated as the current view's projection and centered on the map. If the view's projection changes, coordinate will be expected in latter projection.

Install

npm install ol-coords

Usage

There is 3 ways of using this control in your project:

React (etc.)

Install ol package if not already installed

npm install ol

Use the control as:

codesandbox demo

import React, { useEffect } from "react";
import CoordsControl from "ol-coords/dist/ol-coords";
...
import "ol/ol.css";

function App() {
	useEffect(() => {
		new Map({
			target: "map",
			layers: [
				new TileLayer({
					source: new OSM(),
				}),
			],
			controls: [
				new ZoomSlider(),
				new CoordsControl({ placeholder: "Fly to coords" }),
			],
			view: new View({
				zoom: 7,
				center: [34, 39],
				projection: getProjection("EPSG:4326"),
			}),
		});
	}, []);

	return (
		<div>
			<h2>OpenLayers Coords Control - for React</h2>
			<div id="map" className="map" />
		</div>
	);
}

export default App;
parameters:

placeholder: String

CDN (without bundler)

codesandbox demo

  • Create index.html file and load OpenLayers javascript & css file from CDN.
  • Create map.js and load this script as type="module" in index.html
<link
	rel="stylesheet"
	href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.9.0/css/ol.css"
	type="text/css"
/>
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.9.0/build/ol.js"></script>

<body>
	<h2>Coordinate Control Map</h2>
	<div id="map" class="map"></div>
	<script type="module" src="map.js"></script>
</body>

Finally, import CoordsControl where you define the map as we do in map.js:

import CoordsControl from "https://cdn.skypack.dev/-/[email protected]/dist=es2020,mode=imports/optimized/ol-coords.js";

new ol.Map({
	target: "map",
	layers: [
		new ol.layer.Tile({
			source: new ol.source.OSM(),
		}),
	],
	controls: ol.control.defaults({ attribution: true }).extend([
		new ol.control.ZoomSlider(),
		new CoordsControl({
			placeholder: "Fly to coordinates",
		}),
	]),
	view: new ol.View({
		zoom: 7,
		center: [34, 39],
		projection: ol.proj.get("EPSG:4326"),
	}),
});
parameters:

placeholder: String

  • This method can be used only on modern browsers supporting ES Modules.

CDN (with bundler - Parcel, Webpack, Browserify etc.)

import CoordsControl from node_modules where you define the map as we do in map.js:

import CoordsControl from "./node_modules/ol-coords/dist/cdn/ol-coords-cdn.js";

// define ol.Map same as in CDN (without bundler)
parameters:

placeholder: String

For browsers to understand import statement, you need to use a bundler.

Parcel

  • You can install parcel running npm i --save-dev parcel

  • Then just run parcel index.html to open the app in browser: http://localhost:1234/

Author

👤 bugraaydin1

🤝 Contributing

Contributions, issues and feature requests are welcome: issues page.