mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-23 16:49:40 +02:00
More cleanup
This commit is contained in:
+3
-2
@@ -17,12 +17,13 @@ iD.Node = function(conn, id, lat, lon, tags, loaded) {
|
||||
iD.Node.prototype = {
|
||||
project: function() {
|
||||
// summary: Update the projected latitude value (this.latp) from the latitude (this.lat).
|
||||
this.latp = 180/Math.PI * Math.log(Math.tan(Math.PI/4+this.lat*(Math.PI/180)/2));
|
||||
this.latp = 180/Math.PI *
|
||||
Math.log(Math.tan(Math.PI/4+this.lat*(Math.PI/180)/2));
|
||||
},
|
||||
latp2lat: function(a) {
|
||||
// summary: Get a latitude from a projected latitude.
|
||||
// returns: Latitude.
|
||||
return 180/Math.PI * (2 * Math.atan(Math.exp(a*Math.PI/180)) - Math.PI/2); // Number
|
||||
return 180/Math.PI * (2 * Math.atan(Math.exp(a*Math.PI/180)) - Math.PI/2);
|
||||
},
|
||||
|
||||
within: function(left, right, top, bottom) {
|
||||
|
||||
+4
-2
@@ -6,6 +6,7 @@ iD.Way = function(conn, id, nodes, tags, loaded) {
|
||||
this.entityType = 'way';
|
||||
this.id = id;
|
||||
this.nodes = nodes || [];
|
||||
this.deleted = false;
|
||||
this.entity = new iD.Entity();
|
||||
this.tags = tags || {};
|
||||
this.loaded = (loaded === undefined) ? true : loaded;
|
||||
@@ -33,11 +34,12 @@ iD.Way.prototype = {
|
||||
// ---------------------
|
||||
// Bounding-box handling
|
||||
within:function(left,right,top,bottom) {
|
||||
// TODO invert and just return
|
||||
if (!this.edgel ||
|
||||
(this.edgel<left && this.edger<left ) ||
|
||||
(this.edgel>right && this.edger>right ) ||
|
||||
(this.edgeb<bottom && this.edget<bottom) ||
|
||||
(this.edgeb>top && this.edgeb>top ) || this.deleted) {
|
||||
(this.edgeb>top && this.edgeb>top )) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
@@ -47,7 +49,7 @@ iD.Way.prototype = {
|
||||
_calculateBbox:function() {
|
||||
this.edgel = 999999; this.edger = -999999;
|
||||
this.edgeb = 999999; this.edget = -999999;
|
||||
for (var i in this.nodes) { this.expandBbox(this.nodes[i]); }
|
||||
_.each(this.nodes, _.bind(function(n) { this.expandBbox(n); }, this));
|
||||
},
|
||||
|
||||
expandBbox:function(node) {
|
||||
|
||||
@@ -50,7 +50,7 @@ declare("iD.renderer.EntityUI", null, {
|
||||
},
|
||||
refreshStyleList:function(tags) {
|
||||
// summary: Calculate the list of styles that apply to this UI at this zoom level.
|
||||
if (!this.styleList || !this.styleList.isValidAt(this.map.scale)) {
|
||||
if (!this.styleList || !this.styleList.isValidAt(this.map.scale)) {
|
||||
this.styleList=this.map.ruleset.getStyles(this.entity,tags,this.map.scale);
|
||||
}
|
||||
this.layer=this.styleList.layerOverride();
|
||||
|
||||
+23
-18
@@ -53,7 +53,7 @@ declare("iD.renderer.Map", null, {
|
||||
edgeb: NaN, // |
|
||||
mapheight: NaN, // size of map object in pixels
|
||||
mapwidth: NaN, // |
|
||||
|
||||
|
||||
layers: null, // array-like object of Groups, one for each OSM layer
|
||||
minlayer: -5, // minimum OSM layer supported
|
||||
maxlayer: 5, // maximum OSM layer supported
|
||||
@@ -61,7 +61,7 @@ declare("iD.renderer.Map", null, {
|
||||
elastic: null, // Group for drawing elastic band
|
||||
|
||||
ruleset: null, // map style
|
||||
|
||||
|
||||
constructor:function(obj) {
|
||||
// summary: The main map display, containing the individual sprites (UIs) for each entity.
|
||||
// obj: Object An object containing .lat, .lon, .scale, .div (the name of the <div> to be used),
|
||||
@@ -111,7 +111,7 @@ declare("iD.renderer.Map", null, {
|
||||
this.surface.connect("onmousedown", lang.hitch(this,"_mouseEvent"));
|
||||
this.surface.connect("onmouseup", lang.hitch(this,"_mouseEvent"));
|
||||
},
|
||||
|
||||
|
||||
setController:function(controller) {
|
||||
// summary: Set the controller that will handle events on the map (e.g. mouse clicks).
|
||||
this.controller=controller;
|
||||
@@ -170,21 +170,26 @@ declare("iD.renderer.Map", null, {
|
||||
sub.sublayer=sublayer;
|
||||
return sub; // dojox.gfx.Group
|
||||
},
|
||||
|
||||
|
||||
createUI:function(entity,stateClasses) {
|
||||
// summary: Create a UI (sprite) for an entity, assigning any specified state classes
|
||||
// (temporary attributes such as ':hover' or ':selected')
|
||||
var id=entity.id;
|
||||
switch (entity.entityType) {
|
||||
case 'node':
|
||||
if (!this.nodeuis[id]) { this.nodeuis[id]=new iD.renderer.NodeUI(entity,this,stateClasses); }
|
||||
else { this.nodeuis[id].setStateClasses(stateClasses).redraw(); }
|
||||
return this.nodeuis[id]; // iD.renderer.EntityUI
|
||||
case 'way':
|
||||
if (!this.wayuis[id]) { this.wayuis[id]=new iD.renderer.WayUI(entity,this,stateClasses); }
|
||||
else { this.wayuis[id].setStateClasses(stateClasses).redraw(); }
|
||||
return this.wayuis[id]; // iD.renderer.EntityUI
|
||||
}
|
||||
var id = entity.id;
|
||||
if (entity.entityType === 'node') {
|
||||
if (!this.nodeuis[id]) {
|
||||
this.nodeuis[id] = new iD.renderer.NodeUI(entity,this,stateClasses);
|
||||
} else {
|
||||
this.nodeuis[id].setStateClasses(stateClasses).redraw();
|
||||
}
|
||||
return this.nodeuis[id]; // iD.renderer.EntityUI
|
||||
} else if (entity.entityType === 'way') {
|
||||
if (!this.wayuis[id]) {
|
||||
this.wayuis[id] = new iD.renderer.WayUI(entity,this,stateClasses);
|
||||
} else {
|
||||
this.wayuis[id].setStateClasses(stateClasses).redraw();
|
||||
}
|
||||
return this.wayuis[id]; // iD.renderer.EntityUI
|
||||
}
|
||||
},
|
||||
|
||||
getUI:function(entity) {
|
||||
@@ -195,7 +200,7 @@ declare("iD.renderer.Map", null, {
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
|
||||
refreshUI:function(entity) {
|
||||
// summary: Redraw the UI for an entity.
|
||||
switch (entity.entityType) {
|
||||
@@ -203,7 +208,7 @@ declare("iD.renderer.Map", null, {
|
||||
case 'way': if (this.wayuis[entity.id] ) { this.wayuis[entity.id].redraw(); } break;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
deleteUI:function(entity) {
|
||||
// summary: Delete the UI for an entity.
|
||||
switch (entity.entityType) {
|
||||
@@ -211,7 +216,7 @@ declare("iD.renderer.Map", null, {
|
||||
case 'way': if (this.wayuis[entity.id] ) { this.wayuis[entity.id].removeSprites(); delete this.wayuis[entity.id]; } break;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
download:function() {
|
||||
// summary: Ask the connection to download data for the current viewport.
|
||||
this.conn.loadFromAPI(this.edgel, this.edger, this.edget, this.edgeb);
|
||||
|
||||
@@ -20,19 +20,19 @@ declare("iD.renderer.NodeUI", [iD.renderer.EntityUI], {
|
||||
},
|
||||
redraw:function() {
|
||||
// summary: Draw the object (mostly icons) and add hitzone sprites.
|
||||
var node=this.entity;
|
||||
var node = this.entity;
|
||||
this.removeSprites();
|
||||
|
||||
// Tags, position and styleList
|
||||
var x=this.map.lon2coord(this.entity.lon);
|
||||
var y=this.map.latp2coord(this.entity.latp);
|
||||
var tags=this.getEnhancedTags();
|
||||
var x= this.map.lon2coord(this.entity.lon);
|
||||
var y= this.map.latp2coord(this.entity.latp);
|
||||
var tags = this.getEnhancedTags();
|
||||
this.refreshStyleList(tags);
|
||||
|
||||
// Iterate through each subpart, drawing any styles on that layer
|
||||
var drawn=false;
|
||||
var s,p,t,w,h;
|
||||
for (i=0; i<this.styleList.subparts.length; i++) {
|
||||
for (i = 0; i < this.styleList.subparts.length; i++) {
|
||||
var subpart=this.styleList.subparts[i];
|
||||
p = this.styleList.pointStyles[subpart];
|
||||
if (!p || !p.drawn()) { continue; }
|
||||
@@ -55,7 +55,6 @@ declare("iD.renderer.NodeUI", [iD.renderer.EntityUI], {
|
||||
this.recordSprite(shape);
|
||||
|
||||
// Add text label
|
||||
|
||||
// Add hit-zone
|
||||
var hit;
|
||||
switch (p.icon_image) {
|
||||
|
||||
@@ -20,7 +20,7 @@ declare("iD.styleparser.StyleChooser", null, {
|
||||
this.ruleChains=[new iD.styleparser.RuleChain()];
|
||||
this.styles=[];
|
||||
},
|
||||
|
||||
|
||||
currentChain:function() {
|
||||
return this.ruleChains[this.ruleChains.length-1];
|
||||
},
|
||||
|
||||
@@ -8,20 +8,19 @@ define(['dojo/_base/declare'], function(declare){
|
||||
|
||||
declare("iD.styleparser.StyleList", null, {
|
||||
|
||||
shapeStyles:{},
|
||||
textStyles:{},
|
||||
pointStyles:{},
|
||||
shieldStyles:{},
|
||||
maxwidth:0,
|
||||
subparts:[], // List of subparts used in this StyleList
|
||||
validAt:-1, // Zoom level this is valid at (or -1 at all levels - saves recomputing)
|
||||
shapeStyles: {},
|
||||
textStyles: {},
|
||||
pointStyles: {},
|
||||
shieldStyles: {},
|
||||
maxwidth: 0,
|
||||
subparts: [], // List of subparts used in this StyleList
|
||||
validAt: -1, // Zoom level this is valid at (or -1 at all levels - saves recomputing)
|
||||
|
||||
constructor:function() {
|
||||
// summary: A StyleList object is the full list of all styles applied to
|
||||
// a drawn entity (i.e. node/way). Each array element applies to that
|
||||
// sublayer (z-index). If there is no element, nothing is drawn on that sublayer.
|
||||
// StyleLists are created by StyleChooser.getStyles.
|
||||
|
||||
this.shapeStyles={};
|
||||
this.textStyles={};
|
||||
this.pointStyles={};
|
||||
|
||||
Reference in New Issue
Block a user