Skip to content

Instantly share code, notes, and snippets.

@prebm
Forked from tuxite/map.html
Last active July 15, 2016 10:01
Show Gist options
  • Save prebm/382b4a33217aa335bb64b8a5cfe07c35 to your computer and use it in GitHub Desktop.
Save prebm/382b4a33217aa335bb64b8a5cfe07c35 to your computer and use it in GitHub Desktop.
Example of OpenLayers 3 map inside an ExtJS 4 Panel
<!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" />
<!-- OpenLayers 3 stylesheet -->
<link rel="stylesheet" href="http://openlayers.org/en/v3.17.1/css/ol.css" type="text/css">
</head>
<body>
<!-- OpenLayers 3 js -->
<script src="http://openlayers.org/en/v3.17.1/build/ol.js" type="text/javascript"></script>
<script src="map.js"></script>
</body>
</html>
/* 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.View({
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
]
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment