adds the ability for the user to give map options when reading a WMC document, those options are taken into account with higher priority\n this patch also introduces the new util method isElement, r=me,elemoine, thanks Eric (Closes #2339)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9794 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -105,7 +105,9 @@
|
||||
} else {
|
||||
map.destroy();
|
||||
try {
|
||||
map = format.read(text, {map: "map"});
|
||||
var jsonFormat = new OpenLayers.Format.JSON();
|
||||
var mapOptions = jsonFormat.read(OpenLayers.Util.getElement('mapOptions').value);
|
||||
map = format.read(text, {map: mapOptions});
|
||||
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||
} catch(err) {
|
||||
document.getElementById("wmc").value = err;
|
||||
@@ -133,9 +135,10 @@
|
||||
Shows parsing of Web Map Context documents.
|
||||
</p>
|
||||
<div id="map" class="smallmap"></div>
|
||||
<button onclick="writeWMC();">write</button>
|
||||
<button onclick="readWMC();">read as new map</button>
|
||||
<button onclick="readWMC(true);">read and merge</button>
|
||||
<button onclick="writeWMC();">write</button><br />
|
||||
<button onclick="readWMC();">read as new map</button> with the following extra map options : <input type="text" id="mapOptions" value='{"div": "map", "allOverlays": true}'/><br />
|
||||
<button onclick="readWMC(true);">read and merge</button><br />
|
||||
<button onclick="pasteWMC();">try with another WMC document</button><br />
|
||||
<textarea id="wmc">paste WMC doc here</textarea>
|
||||
<div id="docs">
|
||||
This is an example of parsing WMC documents. <br />
|
||||
|
||||
@@ -71,9 +71,11 @@ OpenLayers.Format.WMC = OpenLayers.Class({
|
||||
* data - {String} or {DOMElement} data to read/parse.
|
||||
* options - {Object} The options object must contain a map property. If
|
||||
* the map property is a string, it must be the id of a dom element
|
||||
* where the new map will be placed. If the map property is an
|
||||
* where the new map will be placed. If the map property is an
|
||||
* <OpenLayers.Map>, the layers from the context document will be added
|
||||
* to the map.
|
||||
* to the map. If the map property is an object, this will be
|
||||
* considered as options to create the map with, in most cases, it would
|
||||
* have a div property.
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Map>} A map based on the context.
|
||||
@@ -95,7 +97,14 @@ OpenLayers.Format.WMC = OpenLayers.Class({
|
||||
if(options.map instanceof OpenLayers.Map) {
|
||||
map = this.mergeContextToMap(context, options.map);
|
||||
} else {
|
||||
map = this.contextToMap(context, options.map);
|
||||
var mapOptions = options.map;
|
||||
if(OpenLayers.Util.isElement(mapOptions) ||
|
||||
typeof mapOptions == "string") {
|
||||
// we assume mapOptions references a div
|
||||
// element
|
||||
mapOptions = {div: mapOptions};
|
||||
}
|
||||
map = this.contextToMap(context, mapOptions);
|
||||
}
|
||||
} else {
|
||||
// not documented as part of the API, provided as a non-API option
|
||||
@@ -231,17 +240,17 @@ OpenLayers.Format.WMC = OpenLayers.Class({
|
||||
*
|
||||
* Parameters:
|
||||
* context - {Object} The context object.
|
||||
* id - {String | Element} The dom element or element id that will contain
|
||||
* the map.
|
||||
* options - {Object} Default map options.
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Map>} A map based on the context object.
|
||||
*/
|
||||
contextToMap: function(context, id) {
|
||||
var map = new OpenLayers.Map(id, {
|
||||
contextToMap: function(context, options) {
|
||||
options = OpenLayers.Util.applyDefaults({
|
||||
maxExtent: context.maxExtent,
|
||||
projection: context.projection
|
||||
});
|
||||
}, options);
|
||||
var map = new OpenLayers.Map(options);
|
||||
map.addLayers(this.getLayersFromContext(context.layersContext));
|
||||
map.setCenter(
|
||||
context.bounds.getCenterLonLat(),
|
||||
|
||||
@@ -31,6 +31,20 @@ OpenLayers.Util.getElement = function() {
|
||||
return elements;
|
||||
};
|
||||
|
||||
/**
|
||||
* Function: isElement
|
||||
* A cross-browser implementation of "e instanceof Element".
|
||||
*
|
||||
* Parameters:
|
||||
* o - {Object} The object to test.
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean}
|
||||
*/
|
||||
OpenLayers.Util.isElement = function(o) {
|
||||
return !!(o && o.nodeType === 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Maintain existing definition of $.
|
||||
*/
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -8,6 +8,24 @@
|
||||
<script type="text/javascript">
|
||||
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
|
||||
var map;
|
||||
|
||||
function test_isElement(t) {
|
||||
t.plan(3);
|
||||
|
||||
// set up
|
||||
var o;
|
||||
|
||||
// tests
|
||||
o = {};
|
||||
t.eq(OpenLayers.Util.isElement(o), false,
|
||||
"isElement reports that {} isn't an Element");
|
||||
o = document.createElement("div");
|
||||
t.eq(OpenLayers.Util.isElement(o), true,
|
||||
"isElement reports that object returned by createElement is an Element");
|
||||
o = OpenLayers.Util.getElement("map");
|
||||
t.eq(OpenLayers.Util.isElement(o), true,
|
||||
"isElement reports that object returned by getElement is an Element");
|
||||
}
|
||||
|
||||
function test_$(t) {
|
||||
t.plan(1);
|
||||
|
||||
Reference in New Issue
Block a user