Download the PHP package sibilino/yii2-openlayers without Composer

On this page you can find all versions of the php package sibilino/yii2-openlayers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-openlayers

OpenLayers 3 Widget for Yii 2

Build Status Scrutinizer Code Quality Total Downloads

Changelog for v2


Version 2 of this widget is not fully compatible with version 1.

Overview


This widget encapsulates the [OpenLayers 3] (http://openlayers.org/) library for easy use in Yii 2. It automatically registers the OpenLayers library and creates a map on the target div.

The widget also facilitates defining the complex configuration options for a map, featuring:

Installation


Composer

This is the preferred way of installing the widget. Just add sibilino/yii2-openlayers to the composer.json file of your Yii 2 application and perform a Composer Update as usual.

Manually

If for some reason you cannot or do not want to use Composer, then you must create the widget folder manually, and then configure your Yii 2 application to autoload the widget classes.

First, create the folder structure sibilino/yii2-openlayers/widget inside the vendor subfolder of your Yii 2 application.

Then, download the widget .zip file and extract the contents of its widget subfolder into the folder you created in the previous step.

Next, edit your application's config file (usually config/main.php or config/web.php) and add the following alias:

Remember to use the namespace sibilino\yii2\openlayers when calling any of the widget's classes:

Usage


In your view, echo the widget method as usual. The options for the OpenLayers Map() can be specified in mapOptions. The widget will automatically publish the OpenLayers library and output the div that will receive the map.

Configuration


The widget supports the following configuration options (actual OpenLayers.js options go in the mapOptions array):

Specifying map options


The problem with OpenLayers map options is that they require complex JavaScript structures. Two approches are available:

  1. Managing your configuration in PHP and then translating it to JavaScript.
  2. Managing your configuration directly in JavaScript.

If your map configuration is relatively simple and depends mostly on data structures that already exist in your PHP application, approach #1 will probably be easier. This widget contains the OL class that can facilitate PHP to JavaScript translation. See below for details.

When your configuration begins getting complex, the OL class begins to show limitations and you must use JsExpressions, which are no longer easy to nest and basically mean you are again writing plain JavaScript. In this case, approach #2 is probably necessary. This widget provides a JavaScript module that easily passes your configuration from a script file to the created map. See below for details.

Mixing up both approaches can be the best way to easily define your map configuration.

Map options as PHP array


The idea is to define the JavaScript options for OpenLayers as a PHP array, using new OL('something') when the JavaScript requires new ol.something(), and let the widget manage the translation to JavaScript automatically.

For example:

For configuration details, read the next section.

For details and examples on OpenLayers configuration, see [the official OpenLayers 3 documentation] (http://openlayers.org/).

Simplified mapOptions


Passing JavaScript and the OL class


Many of the OpenLayers options must be specified by an instance of a JavaScript object under the "ol" namespace. This would traditionally require a JsExpression with a string such as new ol.layer.Tile() (for a Tile object), with further complications to pass configuration to the constructed object. To avoid this cumbersome notation, the OL class can be used. Its constructor accepts a classname, which can include namespace information, and an array of options for the classname's constructor. For example:

Each OL object behaves as a JsExpression that will generate the JavasCript code to instantiate the specified classname with the options. In the case of the example, the resulting code would be:

In the end, this allows the PHP configuration array to be created just like the desired JavaScript configuration object, but using new OL('Something') whenever new ol.Something() is required.

Specifying options using shortcut strings


When specifying the mapOptions['view'] or mapOptions['layers'] arrays, you can identify the some objects by specifying them with a string, instead of creating the corresponding OL instance. The options that support such a string shortcut are mapOptions['view'] and any layer in mapOptions['layers']. For example:

In addition, whenever a layer has been defined using a type string, the source can also be specified using a type string. For example:

Map options as JavaScript


The widget publishes a JavaScript module that is exposed in the global scope as sibilino.olwidget. Options for the creation of the map with id mapId can be specified as an object in the sibilino.olwidget.mapOptions array, associated with the mapId key. For example:

You can register this kind of script by setting its web-accessible URL in the mapOptionScript property of the PHP widget. For example:

Alternatively, you can access the sibilino.olwidget module from any JavaScript code that is loaded after the module script. To ensure proper script order, you can use a dependency to sibilino\yii2\openlayers\OLModuleBundle. For example:

Accessing the map object

If you have JavaScript code that needs to work with the map object created by the widget in your PHP code, you can find it using sibilino.olwidget.getMapById(mapId). This function returns the map object created by the widget with the id mapId. For example:


All versions of yii2-openlayers with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sibilino/yii2-openlayers contains the following files

Loading the files please wait ....