sibilino / yii2-openlayers Goto Github PK
View Code? Open in Web Editor NEWOpenLayers widget for Yii 2
License: MIT License
OpenLayers widget for Yii 2
License: MIT License
Having installed as stated in Readme, the browser console shows about 30 errors like:
[Error] Failed to load resource: Es wurde kein Server mit dem angegebenen Hostnamen gefunden. https://otile1-s.mqcdn.com/tiles/1.0.0/sat/4/9/7.jpg
Where is this Url coming from? Do I have to configure it in the extension?
I created a map with one tile layer and multiple vector layers. If I use the full vector layer specification all of the layers display properly, if I use the short cut layer specification only the tile and last vector layer is displayed.
in this example only the time layer and the last vector layer are displayed:
echo OpenLayers::widget([
'id' => 'lightning',
'options' => [],
'mapOptions' => [
'layers' => [
'Tile' => [ // Generates "new ol.layer.Tile()" JS. See below for an explanation of the OL class.
'source' => new OL('source.MapQuest', [
'layer' => 'sat',
]),
],
'Vector' => [
'source'=> new OL( 'source.Vector',[
'url' =>'/strikes2day_uncoor.json',
'format' => new OL('format.GeoJSON', [
'projection' => 'EPSG:3857',
]),
]),
],
'Vector' => [
'source' => new OL('source.Vector', [
'url' => '/strikes30day_test.kml',
'format' => new OL('format.KML', [
'projection' => 'EPSG:3857',
]),
])
],
'Vector' => [
'source' => new OL('source.Vector', [
'url' => '/MasterCircle.kml',
'format' => new OL('format.KML', [
'projection' => 'EPSG:3857',
]),
])
],
'Vector' => [
'source' => new OL('source.Vector', [
'url' => '/detectors.kml',
'format' => new OL('format.KML', [
'projection' => 'EPSG:3857',
]),
])
],
],
In this example all layers are displayed:
echo OpenLayers::widget([
'id' => 'lightning',
'options' => [],
'mapOptions' => [
'layers' => [
new OL('layer.Tile', [ // Generates "new ol.layer.Tile()" JS. See below for an explanation of the OL class.
'source' => new OL('source.MapQuest', [
'layer' => 'sat',
]),
]),
new OL('layer.Vector', [
'source'=> new OL( 'source.Vector',[
'url' =>'/strikes2day_uncoor.json',
'format' => new OL('format.GeoJSON', [
'projection' => 'EPSG:3857',
]),
]),
]),
new OL('layer.Vector', [
'source'=> new OL( 'source.Vector',[
'url' => '/strikes30day_test.kml',
'format' => new OL('format.KML', [
'projection' => 'EPSG:3857',
]),
]),
]),
new OL('layer.Vector', [
'source'=> new OL( 'source.Vector',[
'url' => '/MasterCircle.kml',
'format' => new OL('format.KML', [
'projection' => 'EPSG:3857',
]),
]),
]),
new OL('layer.Vector', [
'source'=> new OL( 'source.Vector',[
'url' => '/detectors.kml',
'format' => new OL('format.KML', [
'projection' => 'EPSG:3857',
]),
]),
]),
],
Am I misunderstanding the use of the short cut format ?
Otherwise the extension works great.
Thanks
Greg
Hello,
is it possible to have more example for using/configuring this widget ?
To be honest, I'm totally newbie in yii developpement and I meet many problem to understand how to use the widget.
I have a form with 2 textInput fields (latitude / longitude, in read only) and this widget.
My wish is when I clic on the map, a mark stay on this point and the fields are filled with the coordinates of it.
Can you help me ?
I am trying to implement the on.click functionality you pointed out in the previous issue and am having difficulty with defining it. Other then the on.click the map is working.
Here is the yii2 openlayer map definition:
echo OpenLayers::widget([
'id' => 'alertsite',
'options' => [],
// 'mapOptionScript' => 'olclick.js',
'mapOptions' => [
'layers' => [
new OL('layer.Tile', [ // Generates "new ol.layer.Tile()" JS. See below for an explanation of the OL class.
'name' => 'base',
'source' => new OL('source.MapQuest', [
'layer' => 'sat',
]),
]),
],
'view' => [ // No OL() is required here because of simplified option support (see below)
'center' => new JsExpression('ol.proj.transform([-114.0, 51.0], "EPSG:4326", "EPSG:3857")'),
'zoom' => 8,
'projection' => 'EPSG:3857'
],
],
]);
I used the sibilino.olwidget.mapOptions to define the Overlay layer
$this->registerJs("
sibilino.olwidget.mapOptions['alertsite'] = {
overlay : new ol.Overlay({
name:'popup'
}) };
");
I then added the javascript for the on.click event
$this->registerJs("
alertsite.on('click', function(evt) {
var element = popup.getElement();
var coordinate = evt.coordinate;
var hdms = ol.coordinate.toStringHDMS(ol.proj.transform(
coordinate, 'EPSG:3857', 'EPSG:4326'));
$(element).popover('destroy');
popup.setPosition(coordinate);
// the keys are quoted to prevent renaming in ADVANCED mode.
$(element).popover({
'placement': 'top',
'animation': false,
'html': true,
'content': '
The location you clicked was:
' + hdms + '
'I also tried changing the first line of the on.click to
sibilino.olwidget.mapOptions['alertsite'].on('click', function(evt) {
but got the same javascript error both times saying alertsite.on is not a function.
My thought is it is my confusion on how to name the function the same as the map.
Any thoughts ?
Thanks
Greg
I am trying to implement a stylefunction on one of my vector layers.
I have tried several different ways to get it to work without success:
my vector layer:
new OL('layer.Vector', [
'name' => '30 Days',
'group' =>'Uncorr',
'visible' => false,
option one define style to point to a function described earlier in javascript
'style' => 'function(feature,res){return strikestylefunction(feature,res);}',
option two tried using the new experimental ol.style.StyleFunction - it appears V3.10.1 does not have the experimental function included.
'style'=> new OL('style.StyleFunction',
['feature' => 'name',
'resolution'=> 'resolution',
'style'=>[
new OL('style.Style',[
'image' => new OL('style.Icon',[
'src' => '/bolt-9.png'
])
]),
],
]),
Any ideas how I should code the stylefunction ?
Thanks
Greg
I have a new yii2-advanced template setup
I added yii2-openlayers by composer
I added the code from the readme
<div id="test">
and nothing is displayed.
I am relatively new to Yii2 however have expierence with OL3.
Can you provide some insight on what I may have done wrong ?
Also if I dont comment out the 'center; I get an error about JsExpression
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.