Git Product home page Git Product logo

ol-vite's Introduction

OpenLayers

OpenLayers is a high-performance, feature-packed library for creating interactive maps on the web. It can display map tiles, vector data and markers loaded from any source on any web page. OpenLayers has been developed to further the use of geographic information of all kinds. It is completely free, Open Source JavaScript, released under the BSD 2-Clause License.

Getting Started

Install the ol package:

npm install ol

Import just what you need for your application:

import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import XYZ from 'ol/source/XYZ';

new Map({
  target: 'map',
  layers: [
    new TileLayer({
      source: new XYZ({
        url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'
      })
    })
  ],
  view: new View({
    center: [0, 0],
    zoom: 2
  })
});

See the following examples for more detail on bundling OpenLayers with your application:

For more detail on quick prototyping without the use of a Node.js based setup, see the Skypack example.

Sponsors

OpenLayers appreciates contributions of all kinds. We especially want to thank our fiscal sponsors who contribute to ongoing project maintenance.


Pozi logo

Pozi helps connect communities through spatial thinking. We love Openlayers and it forms a core part of our platform. https://pozi.com/ https://app.pozi.com/


yey'maps logo

yey'maps is a scalable cloud GIS suite that is developed with the powerful Openlayers API and the GDAL library. https://www.yeymaps.io/


ela-compil logo

We develop leading Physical Security Information Management (PSIM) software. OpenLayers is the core of our map engine and we love it! https://ela.pl/


Ubigu Oy logo

We advance holistic utilization and availability of spatial information, for a better planned, built and managed society. https://www.ubigu.fi/


Scribble Maps logo

Build custom maps and identify insights across real estate, engineering, research, business, exploration, construction, manufacturing - and so much more. https://www.scribblemaps.com/


See our GitHub sponsors page or Open Collective if you too are interested in becoming a regular sponsor.

TypeScript support

The ol package includes auto-generated TypeScript declarations as *.d.ts files.

Supported Browsers

OpenLayers runs on all modern browsers (with greater than 1% global usage). This includes Chrome, Firefox, Safari and Edge. For older browsers, polyfills will likely need to be added.

Documentation

Check out the hosted examples, the workshop or the API documentation.

Bugs

Please use the GitHub issue tracker for all bugs and feature requests. Before creating a new issue, do a quick search to see if the problem has been reported already.

Contributing

Please see our guide on contributing if you're interested in getting involved.

Community

Test Status

ol-vite's People

Contributors

ahocevar avatar dependabot[bot] avatar tschaub avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ol-vite's Issues

Unable to define a pixel operation on a raster image

Starting from the template in this repository, I tried using a RasterSource with a custom “pixel” operation, but the code fails with a weird ReferenceError.

Here is the relevant part of my code (the full diff is available here):

// compute an array of colors for every possible byte value
const colors = [];
for (let i = 0 ; i < 256 ; i++) {
  colors[i] = [i, 256 - i, i, 255];
}

const rasterSource = new RasterSource({
  sources: [rawLayer],
  operationType: 'pixel',
  operation: (pixels) => {
    const pixel = pixels[0];
    return colors[pixel[2]]; // apply the color from the look up table
  },
});

In the browser, it fails with error “ReferenceError: colors is not defined.” This is weird because the variable colors is defined before the rasterSource definition.

If I open the browser debugger I see the chunk produced by Vite:

const __minion__ = (function createMinion(operation) {
  let workerHasImageData = true;
  try {
    new ImageData(10, 10);
  } catch (_) {
    workerHasImageData = false;
  }
  function newWorkerImageData(data, width, height) {
    if (workerHasImageData) {
      return new ImageData(data, width, height);
    } else {
      return { data, width, height };
    }
  }
  return function(data) {
    const buffers = data["buffers"];
    const meta = data["meta"];
    const imageOps = data["imageOps"];
    const width = data["width"];
    const height = data["height"];
    const numBuffers = buffers.length;
    const numBytes = buffers[0].byteLength;
    if (imageOps) {
      const images = new Array(numBuffers);
      for (let b = 0; b < numBuffers; ++b) {
        images[b] = newWorkerImageData(
          new Uint8ClampedArray(buffers[b]),
          width,
          height
        );
      }
      const output2 = operation(images, meta).data;
      return output2.buffer;
    }
    const output = new Uint8ClampedArray(numBytes);
    const arrays = new Array(numBuffers);
    const pixels = new Array(numBuffers);
    for (let b = 0; b < numBuffers; ++b) {
      arrays[b] = new Uint8ClampedArray(buffers[b]);
      pixels[b] = [0, 0, 0, 0];
    }
    for (let i = 0; i < numBytes; i += 4) {
      for (let j = 0; j < numBuffers; ++j) {
        const array = arrays[j];
        pixels[j][0] = array[i];
        pixels[j][1] = array[i + 1];
        pixels[j][2] = array[i + 2];
        pixels[j][3] = array[i + 3];
      }
      const pixel = operation(pixels, meta);
      output[i] = pixel[0];
      output[i + 1] = pixel[1];
      output[i + 2] = pixel[2];
      output[i + 3] = pixel[3];
    }
    return output.buffer;
  };
})((pixels) => {
    const pixel = pixels[0];
    return colors[pixel[2]];
  });self.addEventListener("message", function(event) {  const buffer = __minion__(event.data);  self.postMessage({buffer: buffer, meta: event.data.meta}, [buffer]);});

I am not sure what it means precisely, but indeed, that code contains the definition of the function operation without the definition of the variable colors, hence the ReferenceError.

Is there something special I should do to use Vite with openlayers without running into that type of errors?

You can reproduce the issue by cloning my branch and running npm run start and then opening your browser.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.