Last active
May 25, 2021 08:37
-
-
Save tuxite/9954263 to your computer and use it in GitHub Desktop.
Example of OpenLayers 3 map inside an ExtJS 4 Panel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Map Panel</title> | |
<!-- ExtJS --> | |
<script type="text/javascript" src="http://cdn.sencha.com/ext/gpl/4.2.1/examples/shared/include-ext.js"></script> | |
<script type="text/javascript" src="http://cdn.sencha.com/ext/gpl/4.2.1/examples/shared/options-toolbar.js"></script> | |
<link rel="stylesheet" type="text/css" href="http://cdn.sencha.com/ext/gpl/4.2.1/examples/shared/example.css" /> | |
<!-- Local OpenLayers 3 stylesheet --> | |
<link href='ol.css' rel="stylesheet"> | |
</head> | |
<body> | |
<!-- Local OpenLayers 3 js --> | |
<script src="ol.js"></script> | |
<script src="map.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global Ext, ol */ | |
/* jshint browser:true, devel:true, indent: 4 */ | |
Ext.application({ | |
name: 'OL3EXT4', | |
launch: function () { | |
var mappanel = Ext.create('Ext.panel.Panel', { | |
title: "Test Map", | |
layout: 'fit', | |
html: "<div id='test-map'></div>", // The map will be drawn inside | |
listeners: { | |
afterrender: function () { | |
var osm_source = new ol.source.OSM({ | |
url: 'http://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png' | |
}); | |
var osmLayer = new ol.layer.Tile({ | |
source: osm_source | |
}); | |
this.map = new ol.Map({ | |
target: 'test-map', | |
renderer: 'canvas', | |
layers: [osmLayer], | |
view: new ol.View2D({ | |
center: [-10764594.0, 4523072.0], | |
zoom: 5 | |
}) | |
}); | |
}, | |
// The resize handle is necessary to set the map! | |
resize: function () { | |
var size = [document.getElementById(this.id + "-body").offsetWidth, document.getElementById(this.id + "-body").offsetHeight]; | |
console.log(size); | |
this.map.setSize(size); | |
} | |
} | |
}); | |
Ext.create('Ext.container.Viewport', { | |
layout: 'fit', | |
items: [ | |
mappanel | |
] | |
}); | |
} | |
}); |
This is a useful example. Thanks a lot.
thanks
Thanks for the example. I updated the code to use it in bl.ocks.org http://bl.ocks.org/prebm/382b4a33217aa335bb64b8a5cfe07c35
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
many thanks