Permalink
Browse files

Moved the layers property from core Mapstraction to OpenLayers as tha…

…t is the only place it's used.

Amending some OpenLayers stuff.

Merging in brunob's event changes.
  • Loading branch information...
1 parent deab174 commit 89689067d4702b6d410d79d2b7b3e781619a8dab @dezfowler dezfowler committed Nov 19, 2010
Showing with 23 additions and 19 deletions.
  1. +1 −2 source/mxn.core.js
  2. +22 −17 source/mxn.openlayers.core.js
View
@@ -55,8 +55,7 @@ var Mapstraction = mxn.Mapstraction = function(element, api, debug) {
* @type {Array}
*/
this.markers = [];
- this.layers = [];
-
+
/**
* The polylines currently loaded.
* @name mxn.Mapstraction#polylines
@@ -4,16 +4,20 @@ mxn.register('openlayers', {
init: function(element, api){
var me = this;
+
var map = new OpenLayers.Map(
element.id,
{
maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
- maxResolution:156543,
- numZoomLevels:18,
- units:'meters',
- projection: "EPSG:41001"
+ maxResolution: 156543,
+ numZoomLevels: 18,
+ units: 'meters',
+ projection: 'EPSG:41001'
}
);
+
+ // initialize layers map (this was previously in mxn.core.js)
+ this.layers = {};
this.layers.osmmapnik = new OpenLayers.Layer.TMS(
'OSM Mapnik',
@@ -89,19 +93,24 @@ mxn.register('openlayers', {
map.events.register('zoomend', map, function(evt){
me.changeZoom.fire();
});
+
// deal with map movement
map.events.register('moveend', map, function(evt){
me.moveendHandler(me);
me.endPan.fire();
});
+
// deal with initial tile loading
var loadfire = function(e) {
me.load.fire();
- this.events.unregister("loadend", this, loadfire);
+ this.events.unregister('loadend', this, loadfire);
};
- for (i in this.layers) {
- if (this.layers[i].visibility == true) {
- this.layers[i].events.register("loadend", this.layers[i], loadfire);
+
+ for (var layerName in this.layers) {
+ if (this.layers.hasOwnProperty(layerName)) {
+ if (this.layers[layerName].visibility === true) {
+ this.layers[layerName].events.register('loadend', this.layers[layerName], loadfire);
+ }
}
}
@@ -198,16 +207,14 @@ mxn.register('openlayers', {
map.addLayer(this.layers.markers);
}
this.layers.markers.addMarker(pin);
-
return pin;
},
removeMarker: function(marker) {
var map = this.maps[this.api];
- var pin = marker.toProprietary(this.api);
+ var pin = marker.proprietary_marker;
this.layers.markers.removeMarker(pin);
pin.destroy();
-
},
declutterMarkers: function(opts) {
@@ -217,25 +224,24 @@ mxn.register('openlayers', {
addPolyline: function(polyline, old) {
var map = this.maps[this.api];
var pl = polyline.toProprietary(this.api);
-
if (!this.layers.polylines) {
this.layers.polylines = new OpenLayers.Layer.Vector('polylines');
map.addLayer(this.layers.polylines);
}
- polyline.setChild(pl);
this.layers.polylines.addFeatures([pl]);
return pl;
},
removePolyline: function(polyline) {
var map = this.maps[this.api];
- var pl = polyline.toProprietary(this.api);
+ var pl = polyline.proprietary_polyline;
this.layers.polylines.removeFeatures([pl]);
},
+
removeAllPolylines: function() {
var olpolylines = [];
- for(var i = 0, length = this.polylines.length; i < length; i++){
- olpolylines.push(this.polylines[i].toProprietary(this.api));
+ for (var i = 0, length = this.polylines.length; i < length; i++) {
+ olpolylines.push(this.polylines[i].proprietary_polyline);
}
if (this.layers.polylines) {
this.layers.polylines.removeFeatures(olpolylines);
@@ -254,7 +260,6 @@ mxn.register('openlayers', {
var map = this.maps[this.api];
var pt = point.toProprietary(this.api);
map.setCenter(pt);
-
},
setZoom: function(zoom) {

0 comments on commit 8968906

Please sign in to comment.