- writers: {
- "gml": {
- "featureMember": function(feature) {
- var node = this.createElementNSPlus("gml:featureMember");
- this.writeNode("feature:_typeName", feature, node);
- return node;
- },
- "MultiPoint": function(geometry) {
- var node = this.createElementNSPlus("gml:MultiPoint");
- var components = geometry.components || [geometry];
- for(var i=0, ii=components.length; i<ii; ++i) {
- this.writeNode("pointMember", components[i], node);
- }
- return node;
- },
- "pointMember": function(geometry) {
- var node = this.createElementNSPlus("gml:pointMember");
- this.writeNode("Point", geometry, node);
- return node;
- },
- "MultiLineString": function(geometry) {
- var node = this.createElementNSPlus("gml:MultiLineString");
- var components = geometry.components || [geometry];
- for(var i=0, ii=components.length; i<ii; ++i) {
- this.writeNode("lineStringMember", components[i], node);
- }
- return node;
- },
- "lineStringMember": function(geometry) {
- var node = this.createElementNSPlus("gml:lineStringMember");
- this.writeNode("LineString", geometry, node);
- return node;
- },
- "MultiPolygon": function(geometry) {
- var node = this.createElementNSPlus("gml:MultiPolygon");
- var components = geometry.components || [geometry];
- for(var i=0, ii=components.length; i<ii; ++i) {
- this.writeNode(
- "polygonMember", components[i], node
- );
- }
- return node;
- },
- "polygonMember": function(geometry) {
- var node = this.createElementNSPlus("gml:polygonMember");
- this.writeNode("Polygon", geometry, node);
- return node;
- },
- "GeometryCollection": function(geometry) {
- var node = this.createElementNSPlus("gml:GeometryCollection");
- for(var i=0, len=geometry.components.length; i<len; ++i) {
- this.writeNode("geometryMember", geometry.components[i], node);
- }
- return node;
- },
- "geometryMember": function(geometry) {
- var node = this.createElementNSPlus("gml:geometryMember");
- var child = this.writeNode("feature:_geometry", geometry);
- node.appendChild(child.firstChild);
- return node;
- }
- },
- "feature": {
- "_typeName": function(feature) {
- var node = this.createElementNSPlus("feature:" + this.featureType, {
- attributes: {fid: feature.fid}
- });
- if(feature.geometry) {
- this.writeNode("feature:_geometry", feature.geometry, node);
- }
- for(var name in feature.attributes) {
- var value = feature.attributes[name];
- if(value != null) {
- this.writeNode(
- "feature:_attribute",
- {name: name, value: value}, node
- );
+ deactivate: function() {
+ var deactivated = false;
+ if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) {
+ this.started = false;
+ this.pinching = false;
+ this.start = null;
+ this.last = null;
+ deactivated = true;
+ }
+ return deactivated;
+ },
+
+ /**
+ * Method: getDistance
+ * Get the distance in pixels between two touches.
+ *
+ * Parameters:
+ * touches - {Array(Object)}
+ *
+ * Returns:
+ * {Number} The distance in pixels.
+ */
+ getDistance: function(touches) {
+ var t0 = touches[0];
+ var t1 = touches[1];
+ return Math.sqrt(
+ Math.pow(t0.olClientX - t1.olClientX, 2) +
+ Math.pow(t0.olClientY - t1.olClientY, 2)
+ );
+ },
+
+
+ /**
+ * Method: getPinchData
+ * Get informations about the pinch event.
+ *
+ * Parameters:
+ * evt - {Event}
+ *
+ * Returns:
+ * {Object} Object that contains data about the current pinch.
+ */
+ getPinchData: function(evt) {
+ var distance = this.getDistance(evt.touches);
+ var scale = distance / this.start.distance;
+ return {
+ distance: distance,
+ delta: this.last.distance - distance,
+ scale: scale
+ };
+ },
+
+ CLASS_NAME: "OpenLayers.Handler.Pinch"
+});
+
+/* ======================================================================
+ OpenLayers/Control/PinchZoom.js
+ ====================================================================== */
+
+/* Copyright (c) 2006-2015 by OpenLayers Contributors (see authors.txt for
+ * full list of contributors). Published under the 2-clause BSD license.
+ * See license.txt in the OpenLayers distribution or repository for the
+ * full text of the license. */
+
+/**
+ * @requires OpenLayers/Handler/Pinch.js
+ */
+
+/**
+ * Class: OpenLayers.Control.PinchZoom
+ *
+ * Inherits:
+ * - <OpenLayers.Control>
+ */
+OpenLayers.Control.PinchZoom = OpenLayers.Class(OpenLayers.Control, {
+
+ /**
+ * Property: type
+ * {OpenLayers.Control.TYPES}
+ */
+ type: OpenLayers.Control.TYPE_TOOL,
+
+ /**
+ * Property: pinchOrigin
+ * {Object} Cached object representing the pinch start (in pixels).
+ */
+ pinchOrigin: null,
+
+ /**
+ * Property: currentCenter
+ * {Object} Cached object representing the latest pinch center (in pixels).
+ */
+ currentCenter: null,
+
+ /**
+ * APIProperty: autoActivate
+ * {Boolean} Activate the control when it is added to a map. Default is
+ * true.
+ */
+ autoActivate: true,
+
+ /**
+ * APIProperty: preserveCenter
+ * {Boolean} Set this to true if you don't want the map center to change
+ * while pinching. For example you may want to set preserveCenter to
+ * true when the user location is being watched and you want to preserve
+ * the user location at the center of the map even if he zooms in or
+ * out using pinch. This property's value can be changed any time on an
+ * existing instance. Default is false.
+ */
+ preserveCenter: false,
+
+ /**
+ * APIProperty: handlerOptions
+ * {Object} Used to set non-default properties on the pinch handler
+ */
+
+ /**
+ * Constructor: OpenLayers.Control.PinchZoom
+ * Create a control for zooming with pinch gestures. This works on devices
+ * with multi-touch support.
+ *
+ * Parameters:
+ * options - {Object} An optional object whose properties will be set on
+ * the control
+ */
+ initialize: function(options) {
+ OpenLayers.Control.prototype.initialize.apply(this, arguments);
+ this.handler = new OpenLayers.Handler.Pinch(this, {
+ start: this.pinchStart,
+ move: this.pinchMove,
+ done: this.pinchDone
+ }, this.handlerOptions);
+ },
+
+ /**
+ * Method: pinchStart
+ *
+ * Parameters:
+ * evt - {Event}
+ * pinchData - {Object} pinch data object related to the current touchmove
+ * of the pinch gesture. This give us the current scale of the pinch.
+ */
+ pinchStart: function(evt, pinchData) {
+ var xy = (this.preserveCenter) ?
+ this.map.getPixelFromLonLat(this.map.getCenter()) : evt.xy;
+ this.pinchOrigin = xy;
+ this.currentCenter = xy;
+ },
+
+ /**
+ * Method: pinchMove
+ *
+ * Parameters:
+ * evt - {Event}
+ * pinchData - {Object} pinch data object related to the current touchmove
+ * of the pinch gesture. This give us the current scale of the pinch.
+ */
+ pinchMove: function(evt, pinchData) {
+ var scale = pinchData.scale;
+ var containerOrigin = this.map.layerContainerOriginPx;
+ var pinchOrigin = this.pinchOrigin;
+ var current = (this.preserveCenter) ?
+ this.map.getPixelFromLonLat(this.map.getCenter()) : evt.xy;
+
+ var dx = Math.round((containerOrigin.x + current.x - pinchOrigin.x) + (scale - 1) * (containerOrigin.x - pinchOrigin.x));
+ var dy = Math.round((containerOrigin.y + current.y - pinchOrigin.y) + (scale - 1) * (containerOrigin.y - pinchOrigin.y));
+
+ this.map.applyTransform(dx, dy, scale);
+ this.currentCenter = current;
+ },
+
+ /**
+ * Method: pinchDone
+ *
+ * Parameters:
+ * evt - {Event}
+ * start - {Object} pinch data object related to the touchstart event that
+ * started the pinch gesture.
+ * last - {Object} pinch data object related to the last touchmove event
+ * of the pinch gesture. This give us the final scale of the pinch.
+ */
+ pinchDone: function(evt, start, last) {
+ this.map.applyTransform();
+ var zoom = this.map.getZoomForResolution(this.map.getResolution() / last.scale, true);
+ if (zoom !== this.map.getZoom() || !this.currentCenter.equals(this.pinchOrigin)) {
+ var resolution = this.map.getResolutionForZoom(zoom);
+
+ var location = this.map.getLonLatFromPixel(this.pinchOrigin);
+ var zoomPixel = this.currentCenter;
+ var size = this.map.getSize();
+
+ location.lon += resolution * ((size.w / 2) - zoomPixel.x);
+ location.lat -= resolution * ((size.h / 2) - zoomPixel.y);
+
+ // Force a reflow before calling setCenter. This is to work
+ // around an issue occurring in iOS.
+ //
+ // See https://github.com/openlayers/ol2/pull/351.
+ //
+ // Without a reflow setting the layer container div's top left
+ // style properties to "0px" - as done in Map.moveTo when zoom
+ // is changed - won't actually correctly reposition the layer
+ // container div.
+ //
+ // Also, we need to use a statement that the Google Closure
+ // compiler won't optimize away.
+ this.map.div.clientWidth = this.map.div.clientWidth;
+
+ this.map.setCenter(location, zoom);
+ }
+ },
+
+ CLASS_NAME: "OpenLayers.Control.PinchZoom"
+
+});
+/* ======================================================================
+ OpenLayers/Control/TouchNavigation.js
+ ====================================================================== */
+
+/* Copyright (c) 2006-2015 by OpenLayers Contributors (see authors.txt for
+ * full list of contributors). Published under the 2-clause BSD license.
+ * See license.txt in the OpenLayers distribution or repository for the
+ * full text of the license. */
+
+/**
+ * @requires OpenLayers/Control/DragPan.js
+ * @requires OpenLayers/Control/PinchZoom.js
+ * @requires OpenLayers/Handler/Click.js
+ */
+
+/**
+ * Class: OpenLayers.Control.TouchNavigation
+ * The navigation control handles map browsing with touch events (dragging,
+ * double-tapping, tap with two fingers, and pinch zoom). Create a new
+ * control with the <OpenLayers.Control.TouchNavigation> constructor.
+ *
+ * If you’re only targeting touch enabled devices with your mapping application,
+ * you can create a map with only a TouchNavigation control. The
+ * <OpenLayers.Control.Navigation> control is mobile ready by default, but
+ * you can generate a smaller build of the library by only including this
+ * touch navigation control if you aren't concerned about mouse interaction.
+ *
+ * Inherits:
+ * - <OpenLayers.Control>
+ */
+OpenLayers.Control.TouchNavigation = OpenLayers.Class(OpenLayers.Control, {
+
+ /**
+ * Property: dragPan
+ * {<OpenLayers.Control.DragPan>}
+ */
+ dragPan: null,
+
+ /**
+ * APIProperty: dragPanOptions
+ * {Object} Options passed to the DragPan control.
+ */
+ dragPanOptions: null,
+
+ /**
+ * Property: pinchZoom
+ * {<OpenLayers.Control.PinchZoom>}
+ */
+ pinchZoom: null,
+
+ /**
+ * APIProperty: pinchZoomOptions
+ * {Object} Options passed to the PinchZoom control.
+ */
+ pinchZoomOptions: null,
+
+ /**
+ * APIProperty: clickHandlerOptions
+ * {Object} Options passed to the Click handler.
+ */
+ clickHandlerOptions: null,
+
+ /**
+ * APIProperty: documentDrag
+ * {Boolean} Allow panning of the map by dragging outside map viewport.
+ * Default is false.
+ */
+ documentDrag: false,
+
+ /**
+ * APIProperty: autoActivate
+ * {Boolean} Activate the control when it is added to a map. Default is
+ * true.
+ */
+ autoActivate: true,
+
+ /**
+ * Constructor: OpenLayers.Control.TouchNavigation
+ * Create a new navigation control
+ *
+ * Parameters:
+ * options - {Object} An optional object whose properties will be set on
+ * the control
+ */
+ initialize: function(options) {
+ this.handlers = {};
+ OpenLayers.Control.prototype.initialize.apply(this, arguments);
+ },
+
+ /**
+ * Method: destroy
+ * The destroy method is used to perform any clean up before the control
+ * is dereferenced. Typically this is where event listeners are removed
+ * to prevent memory leaks.
+ */
+ destroy: function() {
+ this.deactivate();
+ if(this.dragPan) {
+ this.dragPan.destroy();
+ }
+ this.dragPan = null;
+ if (this.pinchZoom) {
+ this.pinchZoom.destroy();
+ delete this.pinchZoom;
+ }
+ OpenLayers.Control.prototype.destroy.apply(this,arguments);
+ },
+
+ /**
+ * Method: activate
+ */
+ activate: function() {
+ if(OpenLayers.Control.prototype.activate.apply(this,arguments)) {
+ this.dragPan.activate();
+ this.handlers.click.activate();
+ this.pinchZoom.activate();
+ return true;
+ }
+ return false;
+ },
+
+ /**
+ * Method: deactivate
+ */
+ deactivate: function() {
+ if(OpenLayers.Control.prototype.deactivate.apply(this,arguments)) {
+ this.dragPan.deactivate();
+ this.handlers.click.deactivate();
+ this.pinchZoom.deactivate();
+ return true;
+ }
+ return false;
+ },
+
+ /**
+ * Method: draw
+ */
+ draw: function() {
+ var clickCallbacks = {
+ click: this.defaultClick,
+ dblclick: this.defaultDblClick
+ };
+ var clickOptions = OpenLayers.Util.extend({
+ "double": true,
+ stopDouble: true,
+ pixelTolerance: 2
+ }, this.clickHandlerOptions);
+ this.handlers.click = new OpenLayers.Handler.Click(
+ this, clickCallbacks, clickOptions
+ );
+ this.dragPan = new OpenLayers.Control.DragPan(
+ OpenLayers.Util.extend({
+ map: this.map,
+ documentDrag: this.documentDrag
+ }, this.dragPanOptions)
+ );
+ this.dragPan.draw();
+ this.pinchZoom = new OpenLayers.Control.PinchZoom(
+ OpenLayers.Util.extend({map: this.map}, this.pinchZoomOptions)
+ );
+ },
+
+ /**
+ * Method: defaultClick
+ *
+ * Parameters:
+ * evt - {Event}
+ */
+ defaultClick: function (evt) {
+ if(evt.lastTouches && evt.lastTouches.length == 2) {
+ this.map.zoomOut();
+ }
+ },
+
+ /**
+ * Method: defaultDblClick
+ *
+ * Parameters:
+ * evt - {Event}
+ */
+ defaultDblClick: function (evt) {
+ this.map.zoomTo(this.map.zoom + 1, evt.xy);
+ },
+
+ CLASS_NAME: "OpenLayers.Control.TouchNavigation"
+});
+/* ======================================================================
+ OpenLayers/Control/Attribution.js
+ ====================================================================== */
+
+/* Copyright (c) 2006-2015 by OpenLayers Contributors (see authors.txt for
+ * full list of contributors). Published under the 2-clause BSD license.
+ * See license.txt in the OpenLayers distribution or repository for the
+ * full text of the license. */
+
+/**
+ * @requires OpenLayers/Control.js
+ */
+
+/**
+ * Class: OpenLayers.Control.Attribution
+ * The attribution control adds attribution from layers to the map display.
+ * It uses 'attribution' property of each layer.
+ *
+ * Inherits from:
+ * - <OpenLayers.Control>
+ */
+OpenLayers.Control.Attribution =
+ OpenLayers.Class(OpenLayers.Control, {
+
+ /**
+ * APIProperty: separator
+ * {String} String used to separate layers.
+ */
+ separator: ", ",
+
+ /**
+ * APIProperty: template
+ * {String} Template for the global attribution markup. This has to include the
+ * substring "${layers}", which will be replaced by the layer specific
+ * attributions, separated by <separator>. The default is "${layers}".
+ */
+ template: "${layers}",
+
+ /**
+ * APIProperty: layerTemplate
+ * {String} Template for the layer specific attribution. This has to include
+ * the substrings "${href}" and "${title}", which will be replaced by
+ * the layer specific attribution object properties.
+ * The default is '<a href="${href}" target="_blank">${title}</a>'.
+ */
+ layerTemplate: '<a href="${href}" target="_blank">${title}</a>',
+
+ /**
+ * Constructor: OpenLayers.Control.Attribution
+ *
+ * Parameters:
+ * options - {Object} Options for control.
+ */
+
+ /**
+ * Method: destroy
+ * Destroy control.
+ */
+ destroy: function() {
+ this.map.events.un({
+ "removelayer": this.updateAttribution,
+ "addlayer": this.updateAttribution,
+ "changelayer": this.updateAttribution,
+ "changebaselayer": this.updateAttribution,
+ scope: this
+ });
+
+ OpenLayers.Control.prototype.destroy.apply(this, arguments);
+ },
+
+ /**
+ * Method: draw
+ * Initialize control.
+ *
+ * Returns:
+ * {DOMElement} A reference to the DIV DOMElement containing the control
+ */
+ draw: function() {
+ OpenLayers.Control.prototype.draw.apply(this, arguments);
+
+ this.map.events.on({
+ 'changebaselayer': this.updateAttribution,
+ 'changelayer': this.updateAttribution,
+ 'addlayer': this.updateAttribution,
+ 'removelayer': this.updateAttribution,
+ scope: this
+ });
+ this.updateAttribution();
+
+ return this.div;
+ },
+
+ /**
+ * Method: updateAttribution
+ * Update attribution string.
+ */
+ updateAttribution: function() {
+ var attributions = [], attribution;
+ if (this.map && this.map.layers) {
+ for(var i=0, len=this.map.layers.length; i<len; i++) {
+ var layer = this.map.layers[i];
+ if (layer.attribution && layer.getVisibility()) {
+ attribution = (typeof layer.attribution == "object") ?
+ OpenLayers.String.format(
+ this.layerTemplate, layer.attribution) :
+ layer.attribution;
+ // add attribution only if attribution text is unique
+ if (OpenLayers.Util.indexOf(
+ attributions, attribution) === -1) {
+ attributions.push( attribution );