Skip to content

Instantly share code, notes, and snippets.

@roy-bukapeta
Created February 13, 2017 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roy-bukapeta/f3d4c5be193cf96634f214ec815e53a8 to your computer and use it in GitHub Desktop.
Save roy-bukapeta/f3d4c5be193cf96634f214ec815e53a8 to your computer and use it in GitHub Desktop.
<?php
/* @var $this yii\web\View */
use yii\web\view;
use app\components\MapCanvas;
$this->title = 'My Yii Application';
?>
<div class="site-index">
<?= app\widget\MapCanvas::widget([
"id" => "",
"options" => [
"library-js" => "openlayers",
"setView"=> "-2, 117",
"setZoom"=> "5",
"height" => "450px",
"width" => "100%",
//'draw' => TRUE
]
]);?>
</div>
</div>
<?php
$script = "
var image = new ol.style.Circle({
radius: 5,
fill: null,
stroke: new ol.style.Stroke({color: 'red', width: 1})
});
var styles = {
'Point': new ol.style.Style({
image: image,
stroke: new ol.style.Stroke({
color: 'green',
width: 1
})
})
};
var styleFunction = function(feature) {
return styles[feature.getGeometry().getType()];
};
var geojsonObject = {
'type': 'FeatureCollection',
'crs': {
'type': 'name',
'properties': {
'name': 'EPSG:4326'
}
},
'features': [{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [-6.18424616128059,106.8310546875]
}
}]
};
var vectorSource = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(geojsonObject)
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource,
style: styleFunction
});
var view = map.getView();
map.addControl(new bukapeta.ol.BasemapProvider({
default : ['mapbox','streets-basic'],
apikey : {
mapbox : 'pk.eyJ1IjoiLWhhYmliLSIsImEiOiJjaWdjbmpsZzE0MXM3dmptM3NzN292NWVhIn0.AfZ7s3jnuqK-2nPzbfl7IA',
},
preset : ['all']
}));
map.addLayer(vectorLayer);
";
$this->registerJsFile('/web/js/bukapeta-ol.js',[/*'depends'=> ['\yii\web\JqueryAsset'],*/'position'=>\yii\web\View::POS_END]);
$this->registerJs($script, View::POS_END)?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment