-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding Javascript after the map definition #7
Comments
Just an update. I copied from a backup the old yii2-openlayers code, made a few changes to add the overlay layer using the typical javascript way of adding the layer, and everything worked ok. I then recopied in the new yii2-openlayer code and it didnt work (just wanted to make sure the changes I made didnt fix the issue). |
The map objects are no longer accessible as a plain javascript variable, so Seems that I forgot to explain all this in the documentation, so I will However, I don't really understand what you are doing with that popup 2016-01-02 3:55 GMT+01:00 gursel58 notifications@github.com:
|
I did try using the new OL(.. to define the Overlay layer and I got a JavaScript error echo OpenLayers::widget([ I did try and use Thanks |
Ok, the getMapById function is bugged then. I will release a fix as soon as For the moment you can use var Regarding your overlay, you are defining it inside the "layers" array. It 2016-01-06 1:32 GMT+01:00 gursel58 notifications@github.com:
|
getMapById works |
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',
]),
]),
]);
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 + '
'});
$(element).popover('show');
});
");
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
The text was updated successfully, but these errors were encountered: