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

webmap-sdk

v2.8.5

Published

Webmap SDK

Downloads

6

Readme

Webmap SDK

Logo

Travis CI Status Coverage Status License

Javascript SDK based on React, OpenLayers and Redux.

Getting started with SDK

This guide walks through the steps necessary to create a new React-Redux project that will feature maps through SDK.

Please use nvm

The Node Version Manager provides a clean and easy way to keep different versions of NodeJS installed simultaneously.

Install yarn

Yarn is yet another node package manager. However, it offers a number of performance features over npm.

npm install -g yarn

Initialize the new app

npx create-react-app sdk-starter
cd sdk-starter

Add the app dependencies

SDK-based apps do require additional dependencies. These include Redux for managing state.

yarn add redux react-redux ol ol-mapbox-style

Add sass support

Follow the instructions here.

Installing SDK

Only one of the following techniques are needed for installing the SDK.

From npm

This is the standard way of installing SDK. It is appropriate for those looking to develop a quick SDK app and do not need the latest features from the master branch.

It will install the dist-version of the library.

yarn add webmap-sdk

Add a basic map:

Add SDK Sass to the project

In your favorite editor open src/App.scss. On the first line add:

@import "webmap-sdk/stylesheet/sdk.scss";

Import SDK and Redux

Open src/App.js in your favorite editor. After the line import './App.scss';, add the following imports:

import { createStore, combineReducers } from 'redux';
import { Provider } from 'react-redux';
import SdkMap from 'webmap-sdk/components/map';
import SdkMapReducer from 'webmap-sdk/reducers/map';
import * as SdkMapActions from 'webmap-sdk/actions/map';

Change from Functional Component to ES6 Class

Create react ap uses Functional Components which will work with SDK, this tutorial and most examples use ES6 Classes

Change the App function to a ES6 Class

function App() {

becomes

class App extends React.Component {

Add a render function

return (
    <div className="App">
    ...
    ...
    </div>
);

to

  render() {
    return (
      <div className="App">
      ...
      </div>
    );
  }

Create a new store with the map reducer.

After the imports add a store with the SdkMapReducer:

const store = createStore(combineReducers({
  'map': SdkMapReducer,
}));

Configuring the initial map

The map configuration needs to happen outside of the render() method. render() will be called every time a prop or state element is changed and this would cause map layers to be added repeatedly causing ill effects. However, componentDidMount is only called once, after the component has been mounted.

After class App extends Component {, add the following lines:

  componentDidMount() {
    // add the OSM source
    store.dispatch(SdkMapActions.addOsmSource('osm'));

    // add an OSM layer
    store.dispatch(SdkMapActions.addLayer({
      id: 'osm',
      source: 'osm',
    }));
  }

Add the map component to the application

Remove the header part, and replace it with an SDK map:

  render() {
    return (
      <div className="App">
        <Provider store={store}>
          <SdkMap />
        </Provider>
      </div>
    );
  }

Fire up the browser

The create-react-app creates a built-in hot-compiler and server.

yarn start

Fin!

Congratulations! You should have a fully operational Webmap SDK React app!

Advanced

From GitHub

Instead of installing sdk from npm, you can also install it from github. This is the way to install SDK if the latest features are needed or development on SDK is planned.

The following steps will clone SDK, install its dependencies, build the library, and finally add it to the app.

cd ..
git clone https://github.com/planetfederal/sdk
cd sdk
npm install
npm run build:dist
cd ../sdk-starter
yarn add file:../sdk/dist

Unit testing

If you want to write unit tests in your application that use the SDK, make sure you have canvas installed as a devDependency. See here for more details.